A datatable rendred with extra line on the top - SgDatatablesBundle - symfony

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.

Related

HTMLPurifier does not work

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.

Drupal Custom Entity Page not found

I am actualy trying to implement my first own entity using this tutorial:
http://www.istos.it/en/blog/drupal-entities/drupal-entities-part-3-programming-hello-drupal-entity
So far anything worked fine, but now i ran in some problem I couldnt get fixed.
After creating my new entity, I get redirected to the page "slider/(id)". But it says that the page could not be found. When I try to open the URL manualy I get the same error.
Here is my code:
he_slider.module
/**
* Implements hook_entitiy_info()
*/
function he_slider_entity_info(){
$slider_info['slider'] = array(
'label' => t('Slider Item'),
'controller class' => 'SliderController',
'views controller class' => 'EntityDefaultViewsController',
'base table' => 'slider',
'uri callback' => 'he_slider_uri',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'sid',
),
'static cache' => TRUE,
'bundles' => array(
'slider'=> array(
'label' => 'Slider',
'admin' => array(
'path' => 'admin/structure/slider/manage',
'access arguments' => array('administer slider'),
),
),
),
'view modes' => array(
'full' => array(
'label' => t('Full Slider Item'),
'custom settings' => FALSE,
),
)
);
return $slider_info;
}
/**
* URI Callback function
*/
function he_slider_uri($slider){
return array(
'path' => 'slider/' . $slider->id,
);
}
/**
* Load the a single or multiple entities
*/
function he_slider_load($sid = NULL, $reset = FALSE){
$sids = (isset ($sid) ? array($sid) : array());
$slider = slider_load_multiple($sids, $reset);
return $slider? reset ($slider) : FALSE;
}
function he_slider_load_multiple($sids = array(), $conditions = array(), $reset = FALSE){
return entity_load('slider', $sids, $conditions, $reset);
}
/**
* Provides the Pages to administer and view the entities
*/
function he_slider_menu(){
$items['admin/content/slider/add'] = array(
'title' => 'Add Slider Item',
'page callback' => 'he_slider_add',
'access arguments' => array('create slideritem'),
);
$items['admin/structure/slider/manage'] = array(
'title' => 'Slider Administration',
'description' => 'Manage Slider Structure',
'page callback' => 'he_slider_info',
'access arguments' => array('administer slideritem'),
);
$items['slider/%slider'] = array(
'title callback' => 'he_slider_page_title',
'title arguments' => array(1),
'page callback' => 'he_slider_page_view',
'page arguments' => array(1),
'access arguments' => array('view slideritem'),
'type' => MENU_CALLBACK,
);
$items['slider/%slider/edit'] = array(
'title' => 'Slider Edit',
'title arguments' => array(1),
'page callback' => 'he_slider_page_edit',
'page arguments' => array(1),
'access arguments' => array('edit slideritem'),
'type' => MENU_CALLBACK,
);
$items['admin/content/slider/add'] = array(
'title' => 'Add Slider Item!',
'page callback' => 'he_slider_add',
'access arguments' => array('create slideritem'),
);
return $items;
}
function he_slider_permission(){
return array(
'administer slideritem' => array(
'title' => t('Administer Slider'),
'restrict access' => TRUE,
),
'view slideritem' => array(
'title' => t('View Slideritems'),
),
'edit slideritem' => array(
'title' => t('Edit Slideritems'),
)
);
}
function he_slider_info() {
return ('Welcome to the administration page for your Slideritems!');
}
function he_slider_page_title($slider){
return $slider->sid;
}
function he_slider_page_view($slider, $view_mode = 'full'){
$slider->content = array();
// Build fields content.
field_attach_prepare_view('slider', array($slider->sid => $slider), $view_mode);
entity_prepare_view('slider', array($slider->sid => $slider));
$slider->content += field_attach_view('slider', $slider, $view_mode);
return $slider->content;
}
function he_slider_field_extra_fields() {
$return = array();
$return['slider']['slider'] = array(
'form' => array(
'title' => array(
'label' => t('Title'),
'description' => t('Slider Title'),
),
),
);
return $return;
}
/**
* Implements the slider add form, where we are able to create our new entities
*/
function he_slider_add() {
$slider = (object) array (
'sid' => '',
'type' => 'slider',
'title' => '',
);
return drupal_get_form('he_slider_add_form', $slider);
}
function he_slider_add_form($form, &$form_state, $slider) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('Note'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
field_attach_form('slider', $slider, $form, $form_state);
return $form;
}
/**
* Implements the Entitiy Edit form
*/
function he_slider_page_edit($slider) {
return drupal_get_form('he_slider_add_form', $slider);
}
/**
* Validates the Entity Add form
*/
function he_slider_add_form_validate($form, &$form_state) {
$slider_submission = (object) $form_state['values'];
field_attach_form_validate('slider', $slider_submission, $form, $form_state);
}
function he_slider_add_form_submit($form, &$form_state) {
$slider_submission = (object) $form_state['values'];
field_attach_submit('slider', $slider_submission, $form, $form_state);
$slider = he_slider_save($slider_submission);
$form_state['redirect'] = "slider/$slider->sid";
}
function he_slider_save(&$slider) {
return entity_get_controller('slider')->save($slider);
}
/**
* Implements hook_views_api().
*/
function he_slider_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'slider') . '/views',
);
}
/**
* Implements hook_form_alter().
*/
function he_slider_form_alter(&$form, &$form_state, $form_id) {
if($form_id=='_slider_add_form'){
$form['submit']['#weight'] = 99;
}
}
he_slider.controller.inc:
class SliderController extends DrupalDefaultEntityController {
public function save($slider) {
drupal_write_record('slider', $slider);
field_attach_insert('slider', $slider);
module_invoke_all('entity_insert', $slider, 'slider');
return $slider;
}
}
The problem is here:
$items['slider/%slider'] = array(
Drupal's menu system will look for a function named slider_load(), whereas your entity load function is named he_slider_load(). This causes the router to bail out and throw a 404.
To fix it, simply change that line to
$items['slider/%he_slider'] = array(
And clear your caches.

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');

How To Create New Content Type Programmatically in Drupal 7?

I'm building a module (my_module) in Drupal 7.
It has some functionality and also will create new content type.
In my_module.install I implemented the hook_install (my_module_install).
Can I use more one implementation of hook_install to create new content type (my_cck_install) in this module?
If (yes), how should I do this?
Else: have I do this in another module? :-)
You can't use more than one implementation of hook_install in the same module; in PHP you can't have 2 function with the same name which rules this out.
You would just need to add your new content type in the same hook_install anyway (have a look at how the standard installation profile does it at /profiles/standard/standard.install). This is how I always add new content types from the install file (using the example of a testimonials module):
function testimonial_install() {
// Make sure a testimonial content type doesn't already exist
if (!in_array('testimonial', node_type_get_names())) {
$type = array(
'type' => 'testimonial',
'name' => st('Testimonial'),
'base' => 'node_content',
'custom' => 1,
'modified' => 1,
'locked' => 0,
'title_label' => 'Customer / Client Name'
);
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
}
}
The following code will create a content type called "Event" with a machine name of 'event' and a title field -
//CREATE NEW CONTENT TYPE
function orderform_node_info() {
return array(
'event' => array(
'name' => t('Event'),
'base' => 'event',
'description' => t('A event content type'),
'has_title' => TRUE
),
);
}
function event_form($node,$form_state) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => t('event Title'),
'#default_value' => !empty($node->title) ? $node->title : '',
'#required' => TRUE,
'#weight' => -5
);
return $form;
}
//END CONTENT TYPE
you should place it in your .module file... if you want do add additional fields to it, let me know and I'll patch you up with the code... good luck!
/**
* Implements hook_node_info()
*/
function mymodule_node_info() {
return array(
'news' => array(
'name' => t('News'),
'base' => 'news',
'description' => t('You can add News here'),
'has_title' => TRUE,
'title_label' => t('News title')
)
);
}
/**
* Implement hook_form()
*/
function mymodule_form($node, $form_state) {
return node_content_form($node, $form_state);
}
Add the implementation to mymodule.install is as follows:
/**
* Implements hook_install().
*/
function mymodule_install() {
node_types_rebuild();
$types = node_type_get_types();|
node_add_body_field($types['news']);
}
You can get a detailed description with code from here
/*
* Implementation in hook node info in .Module file
*/
function test_node_info() {
return array(
'product' => array(
'name' => t('Product'),
'base' => 'product',
'description' => t('Product Title'),
)
);
}
/**
* Implement hook_form()
*/
function product_form($node, $form_state) {
return node_content_form($node, $form_state);
}
/**
* Implements hook_install() in .install file.
*/
function test_install() {
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['product']);
//New way to implement to add fields in your content type
foreach (_test_installed_fields() as $field) {
field_create_field($field);
}
foreach (_test_installed_instances() as $fieldinstance) {
$fieldinstance['entity_type'] = 'node';
$fieldinstance['bundle'] = 'product';
field_create_instance($fieldinstance);
}
}
/*
* Define your fields
*/
function _test_installed_fields() {
$t = get_t();
return array(
'product_title123' => array(
'field_name' => 'product_title123',
'label' => $t('Product Title'),
'type' => 'text'
),
'description123' => array(
'field_name' => 'description123',
'label' => $t('Description'),
'type' => 'text'
),
);
}
/*
* Define your instance of fields
*/
function _test_installed_instances() {
$t = get_t();
return array(
'product_title123' => array(
'field_name' => 'product_title123',
'type' => 'text',
'label' => $t('Product Title'),
'widget' => array(
'type' => 'text_textfield'
),
'display' => array(
'example_node_list' => array(
'label' => $t('Product Title'),
'type' => 'text'
)
)
),
'description123' => array(
'field_name' => 'description123',
'type' => 'text',
'label' => $t('Description'),
'widget' => array(
'type' => 'text_textarea_with_summary'
),
'display' => array(
'example_node_list' => array(
'label' => $t('Description'),
'type' => 'text'
)
)
),
);
}
/**
* Implements hook_uninstall().
*/
function test_uninstall() {
$ournewtype = 'product';
$sql = 'SELECT nid FROM {node} n WHERE n.type = :type';
$result = db_query($sql, array(':type' => $ournewtype));
$nodeids = array();
foreach ($result as $row) {
$nodeids[] = $row->nid;
}
node_delete_multiple($nodeids);
node_type_delete($ournewtype);
}
That's it.

Resources