requestStack = $requestStack; $this->templating = $templating; $this->translatableStringHelper = $translatableStringHelper; } /** * Create a form according to the maxLength option. * * if maxLength < 256 THEN the form type is 'text' * if not, THEN the form type is textarea */ public function buildForm(FormBuilderInterface $builder, CustomField $customField) { $options = $customField->getOptions(); $type = (256 > $options[self::MAX_LENGTH]) ? TextType::class : TextareaType::class; $attrArray = []; if (array_key_exists(self::MULTIPLE_CF_INLINE, $options) and $options[self::MULTIPLE_CF_INLINE]) { $attrArray['class'] = 'multiple-cf-inline'; } $builder->add($customField->getSlug(), $type, [ 'label' => $this->translatableStringHelper->localize($customField->getName()), 'required' => false, 'attr' => $attrArray, ]); } public function buildOptionsForm(FormBuilderInterface $builder) { return $builder ->add(self::MAX_LENGTH, IntegerType::class, ['empty_data' => 256]) ->add(self::MULTIPLE_CF_INLINE, ChoiceType::class, [ 'choices' => [ 'Multiple boxes on the line' => '1', 'One box on the line' => '0', ], 'label' => 'Box appearance', 'expanded' => true, ]); } public function deserialize($serialized, CustomField $customField) { return $serialized; } public function getName() { return 'Text field'; } public function render($value, CustomField $customField, $documentType = 'html') { $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.html.twig'; if ('csv' == $documentType) { $template = 'ChillCustomFieldsBundle:CustomFieldsRendering:text.csv.twig'; } return $this->templating ->render($template, ['text' => $value]); } public function serialize($value, CustomField $customField) { return $value; } }