HTMLPurifier does not work - zend-framework3

I use htmlpurifier as a filter for forms. But it does not work after migrating zf2->zf3. "A plugin by the name "htmlpurifier" was not found in the plugin manager Zend\Filter\FilterPluginManager". Though in module config htmlpurifier is present.
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 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,
)
)
)
),
module config in zenddevelopertools:
'filters' =>
array (size=2)
'factories' =>
array (size=1)
'Soflomo\Purifier\PurifierFilter' => string 'Soflomo\Purifier\Factory\PurifierFilterFactory' (length=46)
'aliases' =>
array (size=1)
'htmlpurifier' => string 'Soflomo\Purifier\PurifierFilter' (length=31)
https://bitbucket.org/mad-max/blog-note3

Deleting vendor folder and installing again have helped.

Related

A datatable rendred with extra line on the top - SgDatatablesBundle

I am using SgDatatablesBundle 1.0
The datatable is rendred with a line on the top contain inputfileds!
I dont know how to remove it ,Please any help
I have follwed this link to use the bundle :
https://github.com/stwe/DatatablesBundle/blob/master/Resources/doc/installation.md#your-first-datatable
my class postDatatable:
namespace AppBundle\Datatables;
/**
* Class PostDatatable
*
* #package AppBundle\Datatables
*/
class PostDatatable extends AbstractDatatable
{
/**
* {#inheritdoc}
*/
public function buildDatatable(array $options = array())
{
$this->language->set(array(
'cdn_language_by_locale' => true
//'language' => 'de'
));
$this->ajax->set(array( 'url' => $this->router->generate('app_homepage'),
'type' => 'GET'
));
$this->options->set(array(
'individual_filtering' => true,
'individual_filtering_position' => 'head',
'order_cells_top' => true,
));
$this->features->set(array(
));
$this->columnBuilder
->add('name', Column::class, array(
'title' => 'Name',
))
->add('nbPges', Column::class, array(
'title' => 'NbPges',
))
->add('subject', Column::class, array(
'title' => 'Subject',
))
->add(null, ActionColumn::class, array(
'title' => $this->translator->trans('sg.datatables.actions.title'),
'actions' => array(
array(
'route' => 'app_homepage',
'route_parameters' => array(
'id' => 'id'
),
'label' => $this->translator->trans('sg.datatables.actions.show'),
'icon' => 'glyphicon glyphicon-eye-open',
'attributes' => array(
'rel' => 'tooltip',
'title' => $this->translator->trans('sg.datatables.actions.show'),
'class' => 'btn btn-primary btn-xs',
'role' => 'button'
),
),
array(
'route' => 'app_homepage',
'route_parameters' => array(
'id' => 'id'
),
'label' => $this->translator->trans('sg.datatables.actions.edit'),
'icon' => 'glyphicon glyphicon-edit',
'attributes' => array(
'rel' => 'tooltip',
'title' => $this->translator->trans('sg.datatables.actions.edit'),
'class' => 'btn btn-primary btn-xs',
'role' => 'button'
),
)
)
))
;
}
/**
* {#inheritdoc}
*/
public function getEntity()
{
return 'AppBundle\Entity\Post';
}
/**
* {#inheritdoc}
*/
public function getName()
{
return 'post_datatable';
}
}
Take a look at the available options.
You need to set individual_filtering to false to remove the search input fields.

Symfony 2.8 - FormBuilder : why field becomes required when I define its type?

I'm building a form like with two non mandatory fileds :
$form = $this->createFormBuilder($contact);
$form->add('name');
$form->add('subject', TextType::class);
$form->getForm();
After rendering the first field is not required (it's normal) but why the second is ?! What's wrong with this code ?
Thanks :)
The problem must be the related entity to this form. Are name and subject nullable?. If no ORM configured then you need to manually set the required attribute to each form field. Look the example of a contact form without ORM.
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('fullName', null, array(
'required' => true,
'attr' => array(
'placeholder' => 'Name',
'class' => 'text gradient'
)))
->add('email','email', array(
'required' => true,
'attr' => array(
'placeholder' => 'Email',
'class' => 'text gradient'
)))
->add('subject', null, array(
'required' => true,
'attr' => array(
'placeholder' => 'Subject',
'class' => 'text gradient'
)))
->add('body', 'textarea', array(
'required' => true,
'attr' => array(
'placeholder' => 'Message',
'class' => 'text gradient'
)));
}
required default value is defined in type class method configureOptions()
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'required' => true,
));
}
and in all parents for this type (parent is defined by getParent() method)
first parent is Symfony\Component\Form\Extension\Core\Type\FormType and there required default value is defined as true, to it is strange that first input is not required.
you can define required while adding new element $form->add('subject', TextType::class, array('required' => false));

How to redirect after view rendering is complete in cakephp 2.3

I am using cakephp 2.3 and required to redirect user after the excel sheet is downloaded successfully. I am using the cake $this->response->type for setting the view as excel sheet generator.
public function admin_export_excel($task_lists = array()) {
$task_ids = $task_lists;
$global_task_array = array();
$this->loadModel('Task');
//-> For each task-id run the loop for fetching the related data to generate the report.
foreach ($task_ids as $index => $task_id) {
//-> Check if the task exists with the specified id.
$this->Task->id = $task_id;
if (!$this->Task->exists())
throw new NotFoundException('Task not found.');
//-> Now check if the logged user is the owner of the specified task.
$task_count = $this->Task->find('count', array('conditions' => array('Task.id' => $task_id,
'Task.user_id' => $this->Auth->user('id'))));
if ($task_count == 0)
throw new NotFoundException('Task not accessable.');
$task_data = $this->Task->find('first', array(
'conditions' => array(
'Task.id' => $task_id
),
'contain' => array(
'TaskForm' => array(
'fields' => array('TaskForm.id', 'TaskForm.reference_table')
),
'Project' => array(
'fields' => array('Project.id', 'Project.project_name')
),
'User' => array(
'fields' => array('User.id', 'User.company_name')
),
'Timezone' => array(
'fields' => array('Timezone.id', 'Timezone.name')
)
)
)
);
// debug($task_data);
$global_task_array[$index] = $task_data;
//-> End of Custom else conditions
unset($task_data);
}
$this->set('global_task_array', $global_task_array);
$this->response->type(array('xls' => 'application/vnd.ms-excel'));
$this->response->type('xls');
$this->render('admin_export_excel');
}
and my view file is
$this->PhpExcel->createWorksheet();
$this->PhpExcel->setDefaultFont('Calibri', 13);
$default = array(
array('label' => __('Task Id'), 'width' => 'auto'),
array('label' => __('Unique Code'), 'width' => 'auto'),
array('label' => __('Site Name'), 'width' => 'auto'),
array('label' => __('Area'), 'width' => 'auto'),
array('label' => __('Location'), 'width' => 'auto'),
array('label' => __('Sub Location'), 'width' => 'auto'),
array('label' => __('About Task'), 'width' => 'auto')
);
$this->PhpExcel->addTableHeader($default, array('name' => 'Cambria', 'bold' => true));
$this->PhpExcel->setDefaultFont('Calibri', 12);
foreach ($global_task_array as $index => $raw) {
$data = array(
$raw['Task']['id'],
$raw['Task']['unique_code'],
$raw['Task']['site_name'],
$raw['Task']['area'],
$raw['Task']['location'],
$raw['Task']['sub_location'],
$raw['Task']['about_task']
);
$this->PhpExcel->addTableRow($data);
}
$this->PhpExcel->addTableFooter();
$this->PhpExcel->output('Task-' . date('d-m-Y') . '.xlsx');
I have tried to use the cake afterFilter method for to redirect the user to other action after the excel sheet is generated but its not working.
public function afterFilter(){
parent::afterFilter();
if($this->request->params['action'] == 'admin_export_excel'){
$this->redirect(array('controller' => 'tasks', 'action' => 'index','admin' => true));
}
}
Any help will be appreciated. Thanks

required don't work for repeated field type in EventSubscriber

I created form EditFormType with code:
// ...
public function buildForm(FormBuilderInterface $builder, array $options)
{
// ...
$builder->addEventSubscriber(new UnsetReadOnlyForEmailField());
}
// ...
and UnsetReadOnlyForEmailField:
// ...
public static function getSubscribedEvents()
{
return array(
FormEvents::PRE_SET_DATA => 'preSetData'
);
}
public function preSetData(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
if ($data === null) {
return;
}
if ($data->getId() === null) {
$form->add(
'plainPassword',
'repeated',
array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle', 'required' => true),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
)
);
}
}
// ...
Unfortunately required for repeated field doesn't work, field is't required. Any suggestions? If I do it wrong, then please write to set the fields in the form are required or not, depending on the form to edit or add. On add form required, on edit form not required.
I think you can do it in such way:
$form->add(
'plainPassword',
'repeated',
array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array(
'label' => 'form.password',
'required' => true
),
'second_options' => array(
'label' => 'form.password_confirmation',
'required' => true
),
'invalid_message' => 'fos_user.password.mismatch',
)
);

My Node Type wont Show It's Fields

I am trying to create my first drupal module that creates a simple node type wcNames. This node type has two fields, firstname & lastname.
I could get my module create the DB table for node type and add it in node_type table, but when I open node/add/wc-name fields firstname and lastname don't appear.
Below is my code. Please suggest.
<?php
// wc_name.install file
/*
* hook_schema Implementation: Creates the DB and it's fields
*/
function wc_name_schema(){
$schema['wc_name_names'] = array(
'fields' => array(
'nmid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
'firstname' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
'lastname' => array('type' => 'varchar', 'length' => 50, 'not null' => FALSE),
),
'primary key' => array('nmid'),
'unique keys' => array(),
'indexes' => array(
'nmid' => array('nmid'),
),
);
return $schema;
}
//function wc_name_install(){ } // Use this function to set variables for the module.
function wc_name_uninstall(){
//unset variables if any set
// Delete all wc_name nodes
db_delete('node')->condition('type', 'wc_name')->execute();
// Delete all wc_name tables
db_drop_table('wc_name_names');
}
?>
<?php
// wc_name.module
/*
* Implementation of _node_info(): define node
*/
function wc_name_node_info(){
return array(
'wc_name' => array(
'name' => t('wcName'),
'base' => 'wc_name',
'base' => 'page',
'description' => t("A smaple module to save names."),
'has_title' => TRUE,
'title_label' => t('Title'),
'has_body' => FALSE,
)
);
}
function wc_name_menu() {
$items = array();
$items['wc_name'] = array(
'title' => 'wcNames',
'page callback' => 'wc_name',
// 'access arguments' => array('access wcNames'),
);
}
?>
<?php
// wc_name_form.inc
function wc_name_form($node, &$form_state){
// Add fields
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#required' => FALSE,
'#default_value' => $node->wc_name['firstname'],
);
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#required' => FALSE,
'#default_value' => $node->wc_name['lastname'],
);
return $form;
}
?>
What am I missing?
Try this:
function createTextFieldByName($type, $fieldname, $fieldlabel)
{
$field = field_info_field($fieldname);
if (empty($field)) {
$field = array(
'field_name' => $fieldname,
'type' => 'text',
'entity_types' => array('node'),
'translatable' => TRUE,
);
$field = field_create_field($field);
}
$instance = field_info_instance('node', $fieldname, $type);
if (empty($instance)) {
$instance = array(
'field_name' => $fieldname,
'entity_type' => 'node',
'bundle' => $type,
'label' => $fieldlabel,
);
$instance = field_create_instance($instance);
return $instance;
}
return null;
}
$type =
array(
'type' => 'MY_TYPE',
'name' => t('NAME'),
'base' => 'node_content',
'description' => t("DESCRIPTION"),
'custom' => 1,
'modified' => 1,
'locked' => 0,
);
$type = node_type_set_defaults($type);
node_type_save($type);
createTextFieldByName($type,'firstname','First name');
createTextFieldByName($type,'lastname','Last name');

Resources