1<?php 2/** 3 * Copyright since 2007 PrestaShop SA and Contributors 4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA 5 * 6 * NOTICE OF LICENSE 7 * 8 * This source file is subject to the Open Software License (OSL 3.0) 9 * that is bundled with this package in the file LICENSE.md. 10 * It is also available through the world-wide-web at this URL: 11 * https://opensource.org/licenses/OSL-3.0 12 * If you did not receive a copy of the license and are unable to 13 * obtain it through the world-wide-web, please send an email 14 * to license@prestashop.com so we can send you a copy immediately. 15 * 16 * DISCLAIMER 17 * 18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 19 * versions in the future. If you wish to customize PrestaShop for your 20 * needs please refer to https://devdocs.prestashop.com/ for more information. 21 * 22 * @author PrestaShop SA and Contributors <contact@prestashop.com> 23 * @copyright Since 2007 PrestaShop SA and Contributors 24 * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) 25 */ 26 27namespace PrestaShopBundle\Form\Admin\Type; 28 29use PrestaShopBundle\Form\Validator\Constraints\TinyMceMaxLength; 30use Symfony\Component\Form\AbstractType; 31use Symfony\Component\Form\Extension\Core\Type\TextareaType; 32use Symfony\Component\Form\FormInterface; 33use Symfony\Component\Form\FormView; 34use Symfony\Component\OptionsResolver\OptionsResolver; 35 36/** 37 * Class enabling TinyMCE on a Textarea field. 38 */ 39class FormattedTextareaType extends AbstractType 40{ 41 /** 42 * Max size of UTF-8 content in MySQL text column 43 */ 44 public const LIMIT_TEXT_UTF8 = 21844; 45 46 /** 47 * {@inheritdoc} 48 */ 49 public function configureOptions(OptionsResolver $resolver) 50 { 51 $resolver->setDefaults([ 52 'autoload' => true, // Start automatically TinyMCE 53 'limit' => self::LIMIT_TEXT_UTF8, 54 ]); 55 $resolver->setAllowedTypes('limit', 'int'); 56 $resolver->setAllowedTypes('autoload', 'bool'); 57 } 58 59 /** 60 * {@inheritdoc} 61 */ 62 public function buildView(FormView $view, FormInterface $form, array $options) 63 { 64 if (!isset($view->vars['attr']['class'])) { 65 $view->vars['attr']['class'] = ''; 66 } 67 68 if (true === $options['autoload']) { 69 $view->vars['attr']['class'] .= ' autoload_rte'; 70 } 71 $view->vars['attr']['counter'] = $options['limit']; 72 $view->vars['constraints'] = [ 73 new TinyMceMaxLength([ 74 'max' => $options['limit'], 75 ]), 76 ]; 77 } 78 79 /** 80 * {@inheritdoc} 81 */ 82 public function getParent() 83 { 84 return TextareaType::class; 85 } 86} 87