fix deprecatrions: use fqcn for chill classes

This commit is contained in:
nobohan 2018-04-04 12:19:46 +02:00
parent ac9325a7f2
commit 65e7354437

View File

@ -26,9 +26,10 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option; use Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option;
use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer; use Chill\CustomFieldsBundle\Form\DataTransformer\CustomFieldDataTransformer;
use Symfony\Bridge\Twig\TwigEngine; use Symfony\Bridge\Twig\TwigEngine;
use Chill\MainBundle\Form\Type\Select2ChoiceType;
/** /**
* *
* *
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
@ -39,29 +40,29 @@ class CustomFieldLongChoice extends AbstractCustomField
* @var OptionRepository * @var OptionRepository
*/ */
private $optionRepository; private $optionRepository;
/** /**
* *
* @var TranslatableStringHelper * @var TranslatableStringHelper
*/ */
private $translatableStringHelper; private $translatableStringHelper;
/** /**
* @var TwigEngine * @var TwigEngine
*/ */
private $templating; private $templating;
const KEY = 'key'; const KEY = 'key';
public function __construct(OptionRepository $optionRepository, public function __construct(OptionRepository $optionRepository,
TranslatableStringHelper $translatableStringHelper, TranslatableStringHelper $translatableStringHelper,
TwigEngine $twigEngine) TwigEngine $twigEngine)
{ {
$this->optionRepository = $optionRepository; $this->optionRepository = $optionRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->templating = $twigEngine; $this->templating = $twigEngine;
} }
public function buildForm(FormBuilderInterface $builder, CustomField $customField) public function buildForm(FormBuilderInterface $builder, CustomField $customField)
{ {
$options = $customField->getOptions(); $options = $customField->getOptions();
@ -69,7 +70,7 @@ class CustomFieldLongChoice extends AbstractCustomField
false, true); false, true);
//create a local copy of translatable string helper //create a local copy of translatable string helper
$translatableStringHelper = $this->translatableStringHelper; $translatableStringHelper = $this->translatableStringHelper;
$builder->add($customField->getSlug(), 'select2_choice', array( $builder->add($customField->getSlug(), Select2ChoiceType::class, array(
'choices' => $entries, 'choices' => $entries,
'choice_label' => function(Option $option) use ($translatableStringHelper) { 'choice_label' => function(Option $option) use ($translatableStringHelper) {
return $translatableStringHelper->localize($option->getText()); return $translatableStringHelper->localize($option->getText());
@ -96,7 +97,7 @@ class CustomFieldLongChoice extends AbstractCustomField
)); ));
$builder->get($customField->getSlug()) $builder->get($customField->getSlug())
->addModelTransformer(new CustomFieldDataTransformer($this, $customField)); ->addModelTransformer(new CustomFieldDataTransformer($this, $customField));
} }
public function buildOptionsForm(FormBuilderInterface $builder) public function buildOptionsForm(FormBuilderInterface $builder)
@ -107,12 +108,12 @@ class CustomFieldLongChoice extends AbstractCustomField
foreach ($keys as $key) { foreach ($keys as $key) {
$choices[$key] = $key; $choices[$key] = $key;
} }
return $builder->add(self::KEY, 'choice', array( return $builder->add(self::KEY, 'choice', array(
'choices' => $choices, 'choices' => $choices,
'label' => 'Options key' 'label' => 'Options key'
)); ));
} }
public function deserialize($serialized, \Chill\CustomFieldsBundle\Entity\CustomField $customField) public function deserialize($serialized, \Chill\CustomFieldsBundle\Entity\CustomField $customField)
@ -120,8 +121,8 @@ class CustomFieldLongChoice extends AbstractCustomField
if ($serialized === NULL) { if ($serialized === NULL) {
return NULL; return NULL;
} }
return $this->optionRepository->find($serialized); return $this->optionRepository->find($serialized);
} }
@ -135,7 +136,7 @@ class CustomFieldLongChoice extends AbstractCustomField
$option = $this->deserialize($value, $customField); $option = $this->deserialize($value, $customField);
$template = 'ChillCustomFieldsBundle:CustomFieldsRendering:choice_long.' $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:choice_long.'
.$documentType.'.twig'; .$documentType.'.twig';
return $this->templating return $this->templating
->render($template, array( ->render($template, array(
'values' => $option === NULL ? array() : array($option) 'values' => $option === NULL ? array() : array($option)
@ -147,13 +148,13 @@ class CustomFieldLongChoice extends AbstractCustomField
if ($value === NULL) { if ($value === NULL) {
return NULL; return NULL;
} }
if (!$value instanceof Option) { if (!$value instanceof Option) {
throw new \LogicException('the value should be an instance of ' throw new \LogicException('the value should be an instance of '
. 'Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, ' . 'Chill\CustomFieldsBundle\Entity\CustomFieldLongChoice\Option, '
. is_object($value) ? get_class($value) : gettype($value).' given'); . is_object($value) ? get_class($value) : gettype($value).' given');
} }
// we place the id in array, to allow in the future multiple select // we place the id in array, to allow in the future multiple select
return $value->getId(); return $value->getId();
} }