ExpressionEngine Custom Control Panel tab not working - module

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

Related

Drupal 7 - get variables from hook_theme

I tried to pass a variable from a custom module to a tpl file.
In my custom module (named example)
1. I created a route with an argument via hook_menu :
function example_menu() {
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
2. I created my page callback function :
function example_display_fancybox_photos($nid) {
$nodePhoto = node_load($nid);
$field_photo = field_get_items('node', $nodePhoto, 'field_photo');
$photo = [
"field_photo" => $field_photo[0]['uri'],
....
];
return theme('example_fancybox_photos', array('infosPhoto' => $photos));
}
3 . I created a hook_theme
function example_theme() {
$themes = array();
$themes['example_fancybox_photos'] = array(
'template' => 'templates/example-fancybox-photos',
'variables' => array('infosPhoto' => NULL),
);
return $themes;
}
4 . I finally created a tpl named "example-fancybox-photos.tpl.php" in templates folder (in theme folder)
<pre><?php print var_dump($infosPhoto); ?></pre>
The result is NULL
I did some researchs but i dont understand why the variable is still NULL.
thanks for your help !
I finally managed to get the variable from the module to the tpl !
1. I created a route with an argument via hook_menu :
function example_menu() {
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
2. I created my page callback function :
function example_display_fancybox_photos($nid) {
$nodePhoto = node_load($nid);
$field_photo = field_get_items('node', $nodePhoto, 'field_photo');
$photos = [
"field_photo" => $field_photo[0]['uri'],
....
];
return theme('example_fancybox_photos', array('infosPhoto' => $photos));
}
3 . I created a hook_theme
function example_theme() {
$themes = array();
$themes['example_fancybox_photos'] = array(
'template' => 'templates/example_fancybox_photos',
'variables' => array('infosPhoto' => NULL),
);
return $themes;
}
4 . I finally created a tpl named "example_fancybox_photos.tpl.php" in templates folder (in MODULE (example) folder)
The problems were that:
- the tpl was not named in the same way and with dashes instead of underscore
- the tpl was in the template folder of the theme and not of the module
You have passed $photos but you have array as $photo. try to change that
Hope the below code helps you.
function example_menu(){
$items['example/fancybox-photos/%'] = array(
'page callback' => 'example_display_fancybox_photos',
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
function example_display_fancybox_photos($nid){
$photos = 'value from example module!';
return theme('example_fancybox_photos',array('photos' => $photos));
}
function example_theme() {
$path = drupal_get_path('module', 'example');
return array(
'example_fancybox_photos' => array(
'variables' => array('photos' => null),
'template' => 'example_fancybox_photos',
'path' => $path,
),
);
}
Place your tpl file example_fancybox_photos.tpl.php in your module directory and inside it use the below code.
<?php print $photos; ?>
or
function example_theme() {
return array(
'example_fancybox_photos' => array(
'variables' => array('photos' => null),
'template' => 'example_fancybox_photos',
),
);
}
Place your tpl file example_fancybox_photos.tpl.php in your theme directory and inside it place the below code
<?php print $photos; ?>

Prestashop custom module add table header

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

Module configuration toolbar buttons don't show in Prestashop 1.6

I am working on adapting my custom prestashop modules to prestashop 1.6. The toolbar buttons at the configuration page are not showing on 1.6 (they do appear on 1.5) and no error message is given.
Toolbar in 1.5:
No Toolbar in 1.6
Do anyone know how to show them in prestashop 1.6? This is the fragment of my code where I declare the toolbar:
$helper = new HelperForm();
// Module, token and currentIndex
$helper->module = $this;
$helper->name_controller = $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->title = $this->displayName;
$helper->show_toolbar = true;
$helper->toolbar_scroll = true; // yes - > Toolbar is always visible on the top of the screen.
$helper->submit_action = 'delete'.$this->name;
$this->uri = ToolsCore::getCurrentUrlProtocolPrefix() .$this->context->shop->domain_ssl.$this->context->shop->physical_uri;
$helper->toolbar_btn = array(
'import' => array(
'desc' => $this->l('Descargar CSV'),
'href' =>$this->uri. 'modules/' . $this->getName() . '/excel.csv',
),
'delete' => array(
'desc' => $this->l('Borrar CSV'),
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&delete'.$this->name.
'&token='.Tools::getAdminTokenLite('AdminModules'),
),
'back' => array(
'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
'desc' => $this->l('Back to list')
)
);
Thanks in advance.
After doing some research I tried using HelperList instead of HelperForm and the toolbar buttons do appear but at the list header, instead of the green area.
On the other hand, HelperForm provides a "buttons" array (I'm not sure if that is a Prestashop 1.6 change or it was there on the 1.5.x versions) which appear left to the submit button in a sort of toolbar below the form.
$this->fields_form[0]['form'] = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('New test block'),
),
'input' => array(
array(
'type' => 'textarea',
'label' => $this->l('Text'),
'lang' => true,
'name' => 'text',
'cols' => 40,
'rows' => 10,
'class' => 'rte',
'autoload_rte' => true,
)
),
'submit' => array(
'title' => $this->l('Save'),
),
'buttons' => array(
array(
'href' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'),
'title' => $this->l('Back to list'),
'icon' => 'process-icon-back'
)
)
);
I suppose the toolbar behaviour and purpose has changed along with the new backend theme.
I've been helping fixing a module we did develope for prestashop, and this was one of the bug we found out. If you want to show any information in the green bar, you will have to use the property $page_header_toolbar_btn from extending AdminCrontrollerCore class which is located at "/classes/controller" until the prestashop team fix the bug I'll report. If you want to make your plugin compatible with older version you will have to use _PS_VERSION global variable.
Edit: https://github.com/PrestaShop/PrestaShop/pull/2065 pull request to solve the bug.
Here is my example code:
class AdminOrdersController extends AdminOrdersControllerCore
{
.....
public function initToolbar()
{
if ($this->display == 'view' && $this->_order->module == 'mymodule') {
if ($this->_mymodule->isOrderComplete($this->_order)) {
$mymodule_return = array(
'short' => $this->l('mymodule account'),
'href' => self::$currentIndex . '&id_order=' . $this->_order->id . '&vieworder&return_mymodule=1&token=' . $this->token,
'desc' => $this->l('return to mymodule'),
'class' => 'process-icon-standardreturn mymodule-return',
);
$mymodule_partial_return = array(
'short' => 'return customer mymodule account',
'href' => '#',
'desc' => $this->l('return to mymodule'),
'class' => 'process-icon-partialreturn',
);
//Depend of the prestashop version, we use $toolbar_btn[]
// or we use $page_header_toolbar_btn[]
if (_PS_VERSION_ > '1.5') {
$mymodule_return['class'] = "process-icon-delete mymodule-return";
$this->page_header_toolbar_btn['return_mymodule'] = $mymodule_return;
} else {
$this->toolbar_btn['return_mymodule'] = $mymodule_return;
$this->toolbar_btn['return_mymodule_partial'] = $mymodule_partial_return;
}
}
}
}
}
I also search for way to display buttons in HelperList, but I want them appear in panel-footer.
The only button, that works this way, is back button.
$helperList->toolbar_btn = array(
'back' => array(
'href' => $this->context->link->getAdminLink('AdminModules').'&configure='.$this->name.'&add_new_feed=1',
'desc' => $this->l('New Feed')
));
Obviously, the drawback is in icon, which don't corespond with the purpose.

Yiibooster TBSelect2 not displayed

In my view I have this code:
echo $form->select2Row($model, 'Zustelladresse', array(
'asDropDownList' => false,
'options' => array(
'placeholder' => "Zustelladresse",
'width' => '100%',
'closeOnSelect' => true,
'minimumInputLength'=>1,
'initSelection' => "js:function (element, callback) {
var selected_data = new Object;
selected_data.id = '123';
selected_data.text = 'Test';
callback(selected_data);
}",
'ajax' => array(
'url' => Yii::app()->createUrl('address/zustelladresse'),
'dataType' => 'json',
'data' => 'js:function(term,page) { if(term && term.length){ return { zustelladresse: term };} }',
'results' => 'js:function(data,page) { return {results: data}; }',
),
)));
Created html:
Why is created only label and hidden input?
YiiBooster widgets are quite tricky to debug, if anything is wrong they just don't show. If you still need the answer, I successfully displayed a select2 widget with this code:
$form->select2Row($model, 'attribute_name', array(
'data' => array('1'=>'value1,'2'=>'value2'),
'htmlOptions'=>array(
'style' => 'width:600px',
'multiple' => true,
),
'options'=>array('placeholder'=>'Please make a selection'),
));
I'd suggest you to start from this code and add up your options one by one, and see if anything breaks.

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;
}