@Anykin

Почему не работает htmlpurifier после перехода на zend framework 3?

После перехода на zf3 перестал работать htmlPurifierFilter в формах. Получаю такую ошибку:
A plugin by the name "htmlpurifier" was not found in the plugin manager Zend\Filter\FilterPluginManager

Хотя с помощью zendDeveloperTools видно, что в конфигах htmlPurifier есть.
'filters' => 
    array (size=3)
      'aliases' => 
        array (size=1)
          'htmlpurifier' => string 'Soflomo\Purifier\PurifierFilter' (length=31)
      'factories' => 
        array (size=1)
          'Soflomo\Purifier\PurifierFilter' => string 'Soflomo\Purifier\Factory\PurifierFilterFactory' (length=46)


class PostFormFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        $aggregatehydrator = $container->get(AggregateHydrator::class);

        return new PostForm(
            $aggregatehydrator,
            new InputFilter()
        );
    }
}


class PostForm extends Form
{
    public function __construct(
        HydratorInterface $hydrator,
        InputFilter $inputFilter,
        $name = "post_form",
        $options = array()
    ) {
        parent::__construct($name, $options);

        $this->setAttribute('method', 'post')
            ->setHydrator($hydrator)
            ->setInputFilter($inputFilter);
    }
    
    public function init() {
        //parent::init();
        $this->add(array(
            'name' => 'post',
            'type' => 'MxmBlog\Form\PostFieldset',
            'options' => array(
                'use_as_base_fieldset' => true
            )
        ));
        
        $this->add(array(
            'type' => 'submit',
            'name' => 'submit',
            'attributes' => array(
                'value' => 'Send'
            )
        ));
    }
}


class PostFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct(PostInterface $post, HydratorInterface $hydrator, $name = "post", $options = array())
    {
        parent::__construct($name, $options);
        
        $this->setHydrator($hydrator);
        $this->setObject($post);

       ...
        
        $this->add(array(
            'type' => 'textarea',
            'name' => 'text',
            'attributes'=>array(
                'class' => 'form-control',
                'required' => 'required',
                'rows' => '3',
            ),
            'options' => array(
                'label' => 'The text'
            )
        ));

        ...
    }
    
    public function init() {
        //parent::init();
        $this->add(array(
            'name' => 'category',
            'type' => 'MxmBlog\Form\CategoriesFieldset',
            'options' => array(
                'use_as_base_fieldset' => true
            )
        ));
        
        $this->add(array(
            'type' => 'Zend\Form\Element\Collection',
            'name' => 'tags',
            'options' => array(
                'label' => 'Please choose tags',
                'count' => 1,
                'should_create_template' => true,
                'allow_add' => true,
                'target_element' => array(
                    'type' => 'MxmBlog\Form\TagFieldset',
                ),
            ),
        ));
        
    }
    
    /**
     * Should return an array specification compatible with
     * {@link ZendInputFilterFactory::createInputFilter()}.
     *
     * @return array
     */
    public function getInputFilterSpecification()
    {
        return array(
            ...
            'text' => array(
                'required' => true,
                'filters'=>array(
                    array(
                        'name' => 'htmlpurifier'
                    ),
                ),
                'validators' => array(
                    array(
                        'name'=>'StringLength',
                        'options'=>array(
                            'encoding'=>'UTF-8',
                            'min'=>1,
                            'max'=>250000,
                        )
                    )
                )
            ),
            ...
        );
    }
}


  • Вопрос задан
  • 306 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы