Prestashop custom module add table header - prestashop

I am developing a custom module in Prestashop. In that module I want to show my custom saved values like the table order. So basically the table should have header part and in that header part there would input fields to search the record for the corresponding data header. So the module custom page header should show like this reference image
So can some one tell me how to do this in a custom module? Any help and suggestions will be really appreciable. Thanks

You need some effort to make it all work but for displaying table header, and I do hope you are using HelperList class,
$helper->simple_header = false;
Check official documentation.

Assuming you know how to make a module, all you need is this (bear in mind it is an example and you'll have to replace bits and pieces here and there).
file /modules/mymodule/controllers/admin/AdminRulesController.php
class AdminRulesController extends ModuleAdminController
{
public function __construct()
{
$this->module = 'mymodule';
$this->table = 'rules'; //table queried for the list
$this->className = 'Rules';//class of the list items
$this->lang = false;
$this->bootstrap = true;
$this->context = Context::getContext();
$this->fields_list = array(
'id_rule' => array(
'title' => $this->l('ID'),
'align' => 'center',
'class' => 'fixed-width-xs',
'search' => false, //in case you want certain fields to not be searchable/sortable
'orderby' => false,
),
'name' => array(
'title' => $this->l('Rule name'),
'align' => 'center',
),
'is_active' => array(
'title' => $this->l('Active'),
'align' => 'center',
'type' => 'bool',
'active' => 'status',
),
'comment' => array(
'title' => $this->l('Comment'),
'align' => 'center',
'callback' => 'displayOrderLink' //will allow you to display the value in a custom way using a controller callback (see lower)
)
);
parent::__construct();
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
return parent::renderList();
}
public function displayOrderLink($comment)
{
switch($comment)
{
case 'value1':
return '<span style="color:red">mytext</span>';
case 'value2':
return '<strong>mytext</strong>';
default:
return 'defaultValue';
}
}
}

Related

ExpressionEngine Custom Control Panel tab not working

I'm trying to add a tab to my Publish entry form, I have the following code (pruned for simplicity), but it's not working:
in tab.my_module.php:
public function display($channel_id, $entry_id = '')
{
$settings = array();
$settings = array(
'custom_field' => array(
'field_id' => 'custom_field',
'field_label' => 'custom_field',
'field_type' => 'text'
)
);
return $settings;
}
in upd.my_module.php:
public function install() {
ee()->layout->add_layout_tabs($this->tabs(), 'my_module');
}
public function tabs()
{
$tabs['my_module'] = array(
'custom_field'=> array(
'visible' => 'true',
'collapse' => 'false',
'htmlbuttons' => 'true',
'width' => '100%'
),
);
return $tabs;
}
But hte tab doesnt appear after i reinstall the module, what am I missing?
The problem was caused by having style information in the lang file!
The new tab was actually being included on the Publish and Edit pages but the style in the Tab title was somehow causing the new tab to be hidden.
$lang = array(
'module_name' => 'My Module',
'module_description' => 'Brief description ',
'save_btn' => 'Save',
'save_btn_clicked' => 'Clicked',
'module_name' => '<style color="green">My Module</style>',
);

Difference between THEME_preprocess_image and THEME_image ?

What is the difference between these 2 functions that can but put in template.php for Drupal?
function THEME_preprocess_image(&$variables) {
// something
}
function THEME_image($variables) {
// something
}
function theme_image renders the HTML output for a renderable array.
THEME_preprocess_image
I do believe, that the right name for that is template_preprocess_HOOK, it is called inside of theme() before theme function eg. THEME_image
Please consider the use case here:
// In custom.module
$variables = array(
'path' => 'path/to/img.jpg',
'alt' => 'Test alt',
'title' => 'Test title',
'width' => '50%',
'height' => '50%',
'attributes' => array('class' => 'some-img', 'id' => 'my-img'),
);
$img = theme('image', $variables);
If you want to change some attributes of an image, you do the following:
function mytheme_preprocess_image($vars) {
// Do the changes, before it's rendered.
}

Yii file CFormInputElement won't display unless explicitly marked "safe"

I'm trying to use Form Builder to build a simple file upload prompt. I want to specify the rule for the file to be similar to
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html'),
but something is wrong. The file upload element only appears if I explicitly mark the element as 'safe' (and remove the 'file' rule). What am I missing?
models/UploadForm.php
class UploadForm extends CFormModel
{
public $year;
public $formFile;
public function rules ()
{
return array(
array('year', 'required'),
array('year', 'date', 'format'=>'yyyy'),
// array('formFile', 'safe'),
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html'),
);
}
static public function getYearOptions () {...}
}
views/extranet/uploadForm.php
return array(
'title' => 'Select year',
'method' => 'post',
'enctype' => 'multipart/form-data',
'elements' => array(
'year' => array(
'type' => 'dropdownlist',
'items' => UploadForm::getYearOptions(),
),
'formFile' => array(
'type' => 'file',
'label' => 'form source file',
),
),
'buttons' => array(
'upload' => array(
'type' => 'submit',
'label' => 'upload',
),
),
);
controllers/ExtranetController.php
class ExtranetController extends CController
{
public function actionIndex ()
{
$form = new CForm('application.views.extranet.uploadForm', new UploadForm());
if ($form->submitted('upload') && $form->validate()) {...}
$this->render('index', array('form' => $form));
}
}
The reason for this is very simple.
The form builder only renders input elements which are considered safe (I.E. have a validation rule). What you have done is perfectly fine, except CFileValidator isn't "safe" by default, whereas other validators are safe.
The quickest way to solve this is the following:
// In your model::rules() function
return array(
array('formFile', 'file', 'allowEmpty' => false, 'types' => 'html', 'safe' => true),
);
Refer to these two links for more information: the CFileValidator#safe documentation, and the Github issue for a problem very similar to yours.

Attach inputFilter to dynamcially created field elements

Until now I have been binding input filters to the form in the module, in other words I have been creating elements in the form, adding input filters to the elements on the module side.
For example check this example
Right now im creating text field elements dynamically depending upon the requirements, like this in my form
//Form
public function addNamesTextFieldElement($names)
{
foreach($names as $name)
{
$nameTextField = new Element\Text($name->getName());
$nameTextField->setAttribute('type', "text");
$nameTextField->setLabel($name->getName());
$this->add($nameTextField );
}
}
What would be best approach where to add/attach input filters to such dynamically generated elements.
I probably wouldn't use this approach, but something like this would work, providing you have already assigned an InputFilter to the form:
public function addNamesTextFieldElement($names)
{
$factory = new InputFactory();
foreach($names as $name)
{
$nameTextField = new Element\Text($name->getName());
$nameTextField->setAttribute('type', "text");
$nameTextField->setLabel($name->getName());
$this->add($nameTextField );
$this->getInputFilter()->add(
$factory->createInput(array(
'name' => $name->getName(),
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
))
);
}
}

dynamically adding text boxes in drupal form api

I want to have a add more button on clicking which i can add dynamically, textboxes in a drupal form api.. can someone help on this?
Thanks in advance
Take a look at Adding dynamic form elements using AHAH. It is a good guide to learn AHAH with Drupal's form API.
EDIT: For an example, install the Examples for Developers module, it has an AHAH example you can use to help you learn.
Here is an example how to solve this with Ajax in Drupal 7(If anyone want I can convert it also to Drupal 6 using AHAH(name before it became Ajax)).
<?php
function text_boxes_form($form, &$form_state)
{
$number = 0;
$addTextbox = false;
$form['text_lists'] = array
(
'#tree' => true,
'#theme' => 'my_list_theme',
'#prefix' => '<div id="wrapper">',
'#suffix' => '</div>',
);
if (array_key_exists('triggering_element', $form_state) &&
array_key_exists('#name', $form_state['triggering_element']) &&
$form_state['triggering_element']['#name'] == 'Add'
) {
$addTextbox = true;
}
if (array_key_exists('values', $form_state) && array_key_exists('text_lists', $form_state['values']))
{
foreach ($form_state['values']['text_lists'] as $element) {
$form['text_lists'][$number]['text'] = array(
'#type' => 'textfield',
);
$number++;
}
}
if ($addTextbox) {
$form['text_lists'][$number]['text'] = array(
'#type' => 'textfield',
);
}
$form['add_button'] = array(
'#type' => 'button',
'#name' => 'Add',
'#ajax' => array(
'callback' => 'ajax_add_textbox_callback',
'wrapper' => 'wrapper',
'method' => 'replace',
'effect' => 'fade',
),
'#value' => t('Add'),
);
return $form;
}
function ajax_add_textbox_callback($form, $form_state)
{
return $form['text_lists'];
}
function text_boxes_menu()
{
$items = array();
$items['text_boxes'] = array(
'title' => 'Text Boxes',
'description' => 'Text Boxes',
'page callback' => 'drupal_get_form',
'page arguments' => array('text_boxes_form'),
'access callback' => array(TRUE),
'type' => MENU_CALLBACK,
);
return $items;
}