From e021cea2dabbe45f3f85fb87e53dcfef867cf194 Mon Sep 17 00:00:00 2001 From: nobohan Date: Fri, 20 Apr 2018 14:19:17 +0200 Subject: [PATCH] fix deprecation error: use gqcn and pass option in array --- CustomFields/CustomFieldChoice.php | 9 ++++++--- Form/Type/ChoiceWithOtherType.php | 10 +--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index 46df61a0a..e89f70c5b 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -88,7 +88,8 @@ class CustomFieldChoice extends AbstractCustomField 'multiple' => $customFieldOptions[self::MULTIPLE], 'choices' => array_combine(array_values($choices),array_keys($choices)), 'required' => $customField->isRequired(), - 'label' => $this->translatableStringHelper->localize($customField->getName())); + 'label' => $this->translatableStringHelper->localize($customField->getName()) + ); //if allow_other = true if ($customFieldOptions[self::ALLOW_OTHER] == true) { @@ -103,8 +104,10 @@ class CustomFieldChoice extends AbstractCustomField $builder ->create( $customField->getSlug(), - new ChoiceWithOtherType($otherValueLabel), - $options) + ChoiceWithOtherType::class, + $options, + array('other_value_label'=> $otherValueLabel) + ) ->addModelTransformer(new CustomFieldDataTransformer($this, $customField))); } else { //if allow_other = false diff --git a/Form/Type/ChoiceWithOtherType.php b/Form/Type/ChoiceWithOtherType.php index ca57063d5..05b011f22 100644 --- a/Form/Type/ChoiceWithOtherType.php +++ b/Form/Type/ChoiceWithOtherType.php @@ -17,19 +17,12 @@ class ChoiceWithOtherType extends AbstractType { private $otherValueLabel = 'Other value'; - public function __construct($otherValueLabel = Null) { - if($otherValueLabel) { - $this->otherValueLabel = $otherValueLabel; - } - } - /* (non-PHPdoc) * @see \Symfony\Component\Form\AbstractType::buildForm() */ public function buildForm(FormBuilderInterface $builder, array $options) { - //$otherValueLabel = $options['other_value_label']; //add an 'other' entry in choices array $options['choices'][$this->otherValueLabel] = '_other'; //ChoiceWithOther must always be expanded @@ -52,9 +45,8 @@ class ChoiceWithOtherType extends AbstractType $resolver ->setRequired(array('choices')) ->setAllowedTypes('choices', array('array')) - //->setDefault('other_value_label', null) ->setDefaults(array( - 'multiple' => false, + 'multiple' => false )) ; }