Answer the question
In order to leave comments, you need to log in
Why doesn't htmlpurifier work after migrating to zend framework 3?
After switching to zf3, htmlPurifierFilter stopped working in forms. I am getting this error:
A plugin by the name "htmlpurifier" was not found in the plugin manager Zend\Filter\FilterPluginManager
'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,
)
)
)
),
...
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question