From c8f53e64724ed33766842667edf76bdf2bfc9149 Mon Sep 17 00:00:00 2001 From: nobohan Date: Thu, 5 Apr 2018 17:09:01 +0200 Subject: [PATCH] fix deprecations: use fqcn and other deprecated properties --- Controller/CustomFieldsGroupController.php | 4 +- CustomFields/CustomFieldNumber.php | 61 ++++++++++++---------- Form/Extension/PostTextNumberExtension.php | 1 + Form/Type/CustomFieldType.php | 2 +- Form/Type/LinkedCustomFieldsType.php | 2 +- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/Controller/CustomFieldsGroupController.php b/Controller/CustomFieldsGroupController.php index 23c797d92..47bd43c7b 100644 --- a/Controller/CustomFieldsGroupController.php +++ b/Controller/CustomFieldsGroupController.php @@ -373,8 +373,8 @@ class CustomFieldsGroupController extends Controller } $form = $this->createForm(FormTypeCustomField::class, null, array('group' => $entity)); - $form->add('submit_dump', 'submit', array('label' => 'POST AND DUMP')); - $form->add('submit_render','submit', array('label' => 'POST AND RENDER')); + $form->add('submit_dump', SubmitType::class, array('label' => 'POST AND DUMP')); + $form->add('submit_render', SubmitType::class, array('label' => 'POST AND RENDER')); $form->handleRequest($request); $this->get('twig.loader') diff --git a/CustomFields/CustomFieldNumber.php b/CustomFields/CustomFieldNumber.php index 91ccac8d0..559f917e7 100644 --- a/CustomFields/CustomFieldNumber.php +++ b/CustomFields/CustomFieldNumber.php @@ -3,7 +3,7 @@ /* * Chill is a software for social workers * - * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, + * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, * , * * This program is free software: you can redistribute it and/or modify @@ -22,20 +22,24 @@ namespace Chill\CustomFieldsBundle\CustomFields; -use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface; -use Chill\CustomFieldsBundle\Entity\CustomField; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\LessThanOrEqual; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Bundle\TwigBundle\TwigEngine; +use Symfony\Component\Form\Extension\Core\Type\NumberType; +use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\Extension\Core\Type\TextType; + +use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface; +use Chill\CustomFieldsBundle\Entity\CustomField; use Chill\MainBundle\Templating\TranslatableStringHelper; /** * Create a custom field number. - * + * * This number may have a min and max value, and a precision. - * + * * @author Julien Fastré * @author Marc Ducobu */ @@ -48,41 +52,42 @@ class CustomFieldNumber extends AbstractCustomField const MAX = 'max'; const SCALE = 'scale'; const POST_TEXT = 'post_text'; - + /** * * @var TwigEngine */ private $templating = NULL; - + /** * * @var TranslatableStringHelper */ private $translatableStringHelper = NULL; - + public function __construct(TwigEngine $templating, TranslatableStringHelper $translatableStringHelper) { $this->templating = $templating; $this->translatableStringHelper = $translatableStringHelper; } - + public function buildForm(FormBuilderInterface $builder, CustomField $customField) { $options = $customField->getOptions(); - + //select the type depending to the SCALE $type = ($options[self::SCALE] === 0 or $options[self::SCALE] === NULL)? + //IntegerType::class : NumberType::class; 'integer' : 'number'; - + $fieldOptions = $this->prepareFieldOptions($customField, $type); - + $builder->add($customField->getSlug(), $type, $fieldOptions); } - + /** * prepare the options'form field - * + * * @param CustomField $customField * @param string $type * @return mixed[] @@ -90,18 +95,18 @@ class CustomFieldNumber extends AbstractCustomField private function prepareFieldOptions(CustomField $customField, $type) { $options = $customField->getOptions(); - + /** * @var mixed[] the formField options */ $fieldOptions = array(); - - // add required + + // add required $fieldOptions['required'] = False; - + //add label $fieldOptions['label'] = $this->translatableStringHelper->localize($customField->getName()); - + // add constraints if required if ($options[self::MIN] !== NULL) { $fieldOptions['constraints'][] = new GreaterThanOrEqual(array('value' => $options[self::MIN])); @@ -109,44 +114,44 @@ class CustomFieldNumber extends AbstractCustomField if ($options[self::MAX] !== NULL) { $fieldOptions['constraints'][] = new LessThanOrEqual(array('value' => $options[self::MAX])); } - + // add precision to options if required if ($type === 'number') { $fieldOptions['scale'] = $options[self::SCALE]; } - + if (!empty($options[self::POST_TEXT])) { $fieldOptions['post_text'] = $options[self::POST_TEXT]; } - + return $fieldOptions; } public function buildOptionsForm(FormBuilderInterface $builder) { return $builder - ->add(self::MIN, 'number', array( + ->add(self::MIN, NumberType::class, array( 'scale' => 2, 'label' => 'Greater or equal than', 'required' => false )) - ->add(self::MAX, 'number', array( + ->add(self::MAX, NumberType::class, array( 'scale' => 2, 'label' => 'Lesser or equal than', 'required' => false )) - ->add(self::SCALE, 'integer', array( + ->add(self::SCALE, IntegerType::class, array( 'scale' => 0, 'label' => 'Precision', 'constraints' => array( new GreaterThanOrEqual(array('value' => 0)) ) )) - ->add(self::POST_TEXT, 'text', array( + ->add(self::POST_TEXT, TextType::class, array( 'label' => 'Text after the field' )) ; - + } public function deserialize($serialized, CustomField $customField) @@ -167,7 +172,7 @@ class CustomFieldNumber extends AbstractCustomField return $this->templating ->render($template, array( - 'number' => $value, + 'number' => $value, 'scale' => $options[self::SCALE], 'post' => $options[self::POST_TEXT] )); diff --git a/Form/Extension/PostTextNumberExtension.php b/Form/Extension/PostTextNumberExtension.php index 5cbaeca34..f934f6c05 100644 --- a/Form/Extension/PostTextNumberExtension.php +++ b/Form/Extension/PostTextNumberExtension.php @@ -28,6 +28,7 @@ class PostTextNumberExtension extends PostTextExtension { public function getExtendedType() { + //return PostTextNumberExtension::class; return 'number'; } diff --git a/Form/Type/CustomFieldType.php b/Form/Type/CustomFieldType.php index ecbb07d5a..6f3727e44 100644 --- a/Form/Type/CustomFieldType.php +++ b/Form/Type/CustomFieldType.php @@ -63,7 +63,7 @@ class CustomFieldType extends AbstractType ; } - public function getBlockPrefix() + public function getName() { return 'custom_field'; } diff --git a/Form/Type/LinkedCustomFieldsType.php b/Form/Type/LinkedCustomFieldsType.php index d14bb67ce..635ddcc1f 100644 --- a/Form/Type/LinkedCustomFieldsType.php +++ b/Form/Type/LinkedCustomFieldsType.php @@ -80,7 +80,7 @@ class LinkedCustomFieldsType extends AbstractType public function getParent() { - return 'choice'; + return ChoiceType::class; } /**