How to show Taxonomy term description on hover of them label in add content form drupal 9 - module

$value) {
[`enter image description here`][1]
$form['field_news_type'][$key] = array(
'#type' => 'radio',
'#name' => 'field_news_type',
'#title' => $value,
'#description' => 'Hello_description',
'#attributes' => [
// 'id' => 'edit-' . $key,
'class' => ['news-type-test-class'],
'value' => $key,
],
);
}
}
[1]: https://i.stack.imgur.com/2pXTg.png

Related

Change the url associated with cancel button

I want to change the URL of cancel button presently on canceling the page it is showing me the list but I want to redirect the user on the cancel button.
public function renderForm() {
$this->fields_form = array(
'legend' => array('title' => $this->l('Additional Service'), 'icon' => 'icon-cogs'),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('id_citydelivery'),
'name' => 'id_citydelivery',
'size' => 255),
array(
'type' => 'text',
'label' => $this->l('Service_name'),
'name' => 'service_name',
'size' => 255,
'required' => true,
'desc' => $this->l('Enter name of Arrival port')
),
array(
'type' => 'switch',
'label' => $this->l('Active'),
'name' => 'active',
'required' => false,
'is_bool' => true,
'values' => array(array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Active')), array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Inactive')))),
),
'submit' => array('title' => $this->l('Save')),
);
return parent::renderForm();
}
After Diving into the code I came to know back button URL is set it by $_post['Back']
So I have overridden it; you have to change # with your URL
public function postProcess() {
if (Tools::getIsset('submitAddadditional_service')) {
$this->redirect_after = Context::getContext()->link->getAdminLink('AdminGCardeliverycity', true) . '&updatecitydelivery&id_citydelivery=' . Tools::getValue('id_citydelivery');
} else {
$_POST['back'] = '#'; //For Cancel button url on form which is genrated by renderform()
}
parent::postProcess();
}

Prestashop HelperForm: switch button

I am using Prestashop HelperForm to generate a switch button. The status of the button depends on data generated from database. The problem is that the button is always set to false.
Here is the code :
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Champs pour feuille de soin'),
'icon' => 'icon-pencil'
),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_product',
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu1'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field1',
),
array(
'type' => 'radio',
'label' => $this->l('required'),
'name' => 'relab1',
'is_bool' => false,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'label1_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label1_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu2'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field2',
),
array(
'type' => 'radio',
'label' => $this->l('required'),
'name' => 'relab2',
'is_bool' => false,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'active_on',
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu3'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field3',
),
array(
'type' => 'switch',
'label' => $this->l('required'),
'name' => 'relab3',
'is_bool' => true,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'label3_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label3_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'textarea',
'label' => $this->l('Label'),
'name' => 'contenu4'
),
array(
'type' => 'hidden',
'name' => 'id_customization_field4',
),
array(
'type' => 'checkbox',
'label' => $this->l('Required'),
'name' => 'label4',
'class' => 't',
'multiple' => true,
'values' => array(
'query' => array($label3),
'id' => 'label4',
'name' => 'label4',
'expand' => array(
'default' => 'show',
'show' => array('text' => $this->l('show'), 'icon' => 'plus-sign-alt'),
'hide' => array('text' => $this->l('hide'), 'icon' => 'minus-sign-alt')
),
)
),
),
'submit' => array(
'title' => $this->l('Save'),
'name' => $this->l('submitAddproduct'),
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitUpdate';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
$helper->fields_value['id_product'] = Tools::getValue('id_product'),
'relab4' => 1,
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
$helper->fields_value['contenu1'] = $contenu1;
$helper->fields_value['contenu2'] = $contenu2;
$helper->fields_value['contenu3'] = $contenu3;
$helper->fields_value['contenu4'] = $contenu4;
$helper->fields_value['relab1'] = (int)$relab1;
$helper->fields_value['relab2'] = (int)$relab2;
$helper->fields_value['relab3'] = (int)$relab3;
$helper->fields_value['relab4'] = (int)$relab4;
$helper->fields_value['id_customization_field1'] = $id_customization_field1;
$helper->fields_value['id_customization_field2'] = $id_customization_field2;
$helper->fields_value['id_customization_field3'] = $id_customization_field3;
$helper->fields_value['id_customization_field4'] = $id_customization_field4;
return $helper->generateForm(array($fields_form));
I guess you have this part of the code too ($helper is your HelperForm() object):
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
So with this function you need to return a relab2 value:
public function getConfigFieldsValues()
{
return array(
'relab2' => 1 // your value, 1 or 0
// other form values
);
}
You need to provide your form values to the HelperForm object.
Here is an example:
$fields_form = array(
'legend' => array(
'title' => $this->('My Form'),
),
'input' => array(
'type' => 'switch',
'label' => $this->l('required'),
'name' => 'relab2',
'is_bool' => true,
'desc' => $this->l('required'),
'values' => array(
array(
'id' => 'label2_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label2_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
);
$val = getValFromDB(); //example
$helper = new HelperForm();
$helper->module = $this;
$helper->name_controller = 'example';
$helper->title = $this->displayName;
$helper->submit_action = 'example_action';
// [...]
// [...]
// Here you provide your values
$helper->fields_value = array('relab2' => $val);
return $helper->generateForm(array(array('form' => $fields_form)));
Hi I have had the same issue on prestashop 1.6 and 1.7 and I finally figured out the problem so I will share my findings with you guys.
So here is my switch :
array(
'type' => 'switch',
'label' => $this->trans('Captcha Test Mode', array(), 'Admin.Shipping.Feature'),
'name' => 'CORE_CAPTCHA_TEST_MODE',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->trans('Enabled', array(), 'Admin.Global'),
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->trans('Disabled', array(), 'Admin.Global'),
),
),
As you can see it has to have an explicit name CORE_CAPTCHA_TEST_MODE.
Where things become interesting is in the getConfigFormValues() method :
protected function getConfigFormValues()
{
return array(
'CORE_CAPTCHA_TEST_MODE' => Tools::getValue('CORE_CAPTCHA_TEST_MODE', Configuration::get('CORE_CAPTCHA_TEST_MODE', true)),
);
}
Unlike any other type of field where a simple Configuration::get would be enough to set the value in the field when the form is loaded for a switch we need to add Tools::getValue(...
Also got the same question, bot issue was elsewhere, just a switch button itself does nothing, you have to provide value data to it and then changes will be shown.
as other noted switch input itself:
array(
'type' => 'switch',
'label' => $this->l('Display map'),
'name' => 'my_data',
'is_bool' => true,
'values' => array(
array(
'id' => 'label2_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'label2_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
and provide saved data to it right bellow
$helper->fields_value['my_data'] = Configuration::get('my_data');

Prestashop upload field image display

I created new AdminReferenceController in prestashop back office with list and form for every item in list, and everything is working fine except one thing. When i try show image below upload button image is not displayed, (i check, image exist on server and url is valid). I use prestashop 1.5.6.0 Please check what i am doing wrong? Name and description values is properly displayed...
public function renderForm()
{
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Reference'),
'image' => '../modules/reference/logo.gif'
),
'input' => array(
array(
'type' => 'text',
'lang' => false,
'label' => $this->l('Reference name:'),
'name' => 'name',
'size' => 60,
'desc' => $this->l('Reference name')
),
array(
'type' => 'file',
'lang' => false,
'label' => $this->l('Reference image:'),
'name' => 'image',
'display_image' => true,
'desc' => $this->l('Upload Reference image from your computer')
),
array(
'type' => 'textarea',
'label' => $this->l('Reference description:'),
'name' => 'description',
'autoload_rte' => true,
'desc' => $this->l('Reference description')
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
if (!($obj = $this->loadObject(true)))
return;
$this->fields_value = array(
'image' => "<img src='/prestashop/img/reference/1.jpg'>",
'size' => '500',
'name' => 'test',
'description' => 'test'
);
return parent::renderForm();
}
Thanks
You can also use this code if it helps you
public function renderForm()
{
if (!($obj = $this->loadObject(true)))
return;
$image = _PS_MANU_IMG_DIR_.$obj->id.'.jpg';
$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350,
$this->imageType, true, true);
$image_size = file_exists($image) ? filesize($image) / 1000 : false;
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Add Maker'),
'icon' => 'icon-maker'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'required' => true
),
array(
'type' => 'file',
'label' => $this->l('Maker Image'),
'name' => 'image_url_maker',
'image' => $image_url ? $image_url : false,
'size' => $image_size,
'display_image' => true,
'col' => 6,
'hint' => $this->l('Upload a maker image from your computer.')
),
),
'submit' => array(
'title' => $this->l('Save'),
)
);
return parent::renderForm();
}

Populating Form Data in ZF2 when using Fieldsets

I am currently playing around with ZF2 beta 4 and I seem to be stuck when i try to use fieldsets within a form and getting the data back into the form when the form is submitted. I am not sure if I am not setting the input filters right for fieldsets or I am missing something. For example, I have the following (simplified to make it clear):
Controller
public function indexAction(){
$form = new MyForm();
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->post());
if ($form->isValid()) {
//Do something
print_r($form->getData()); //for debug
}
}
return array('form' => $form);
}
MyForm.php
class MyForm extends Form
{
public function __construct()
{
parent::__construct();
$this->setName('myForm');
$this->setAttribute('method', 'post');
$this->add(array(
'name' => 'title',
'attributes' => array(
'type' => 'text',
'label' => 'Title',
),
));
$this->add(new MyFieldset('myfieldset'));
//setting InputFilters here
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'title',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
)));
//Now add fieldset Input filter
foreach($this->getFieldsets() as $fieldset){
$fieldsetInputFilter = $factory->createInputFilter($fieldset->getInputFilterSpecification());
$inputFilter->add($fieldsetInputFilter,$fieldset->getName());
}
//Set InputFilter
$this->setInputFilter($inputFilter);
}
}
MyFieldset.php
class MyFieldset extends Fieldset implements InputFilterProviderInterface{
public function __construct($name)
{
parent::__construct($name);
$factory = new Factory();
$this->add($factory->createElement(array(
'name' => $name . 'foo',
'attributes' => array(
'type' => 'text',
'label' => 'Foo',
),
)));
}
public function getInputFilterSpecification(){
return array(
'foo' => array(
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
),
);
}
}
I am able to output the form as expected and I end up with two input elements named 'title' and 'myfieldsetfoo' (the name given when outputing with the ViewHelper). So of course when I submit the raw post will show values for 'title' and 'myfieldsetfoo'. However, when I use SetData() the values for the field set are not being populated (although I can see the values in the raw post object). Instead, examining the output of '$form->getData()' I receive:
Array(
[title] => Test,
[myfieldset] => Array(
[foo] =>
)
)
What am I missing? What do I need to do so that ZF2 understands how to populate the fieldset?
Thanks for any help, this is driving me crazy.
Why I do is concatenate InputFilter so I could handle the whole HTML form array posted.
<form method="POST">
<input type="text" name="main[name]" />
<input type="text" name="main[location]" />
<input type="text" name="contact[telephone]" />
<input type="submit" value="Send" />
</form>
This will create an array posted like
post["main"]["name"]
post["main"]["location"]
post["contact"]["telephone"]
Filtered and validated with:
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
$post = $this->request->getPost();
$inputFilter = new InputFilter();
$factory = new InputFactory();
// $post["main"]
$mainFilter = new InputFilter();
$mainFilter->add($factory->createInput(array(
'name' => 'name',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));
$mainFilter->add($factory->createInput(array(
'name' => 'location',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));
$inputFilter->add($mainFilter, "main");
// $post["contact"]
$contactFilter = new InputFilter();
$contactFilter->add($factory->createInput(array(
'name' => 'name',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));
$contactFilter->add($mainFilter, "contact");
//Set posted data to InputFilter
$inputFilter->setData($post->toArray());
http://www.unexpectedit.com/zf2/inputfilter-validate-and-filter-a-form-data-with-fieldsets
I think you forgot to prepare your form in the controller:
return array('form' => $form->prepare());
This will rename the "name" field of your fieldset to "myfieldset[foo]", so you don't have to prepend the fieldsets name on your own.
Just use
'name' => 'foo'
instead of
'name' => $name . 'foo'
in your fieldset class.
I think the problem is that you declare a new form in your controller. And that clear the previous form.
$form = new MyForm();
I use the Service Manager to declare the form and filters.
And then in the controller I do:
$form = $this->getServiceLocator()->get('my_form');
That way I always get the object I want
Update
I no longer use service manager to call forms. I just call a new form and issue $form->setData($data);
The source for the data can also be entity though then I would issue: $form->bind($entity)

Yii CGridView custom footer

I am using CGridView to show data in grid format, but i am not able to create a custom footer,
the code that i am using,
<?php
$this->widget('zii.widgets.grid.CGridView',
array('dataProvider' => $dataProvider,
'columns' => array(
array(
'name' => 'created_date',
'header' => 'Created',
),
array(
'name' => 'access_date',
'header' => 'Accessed',
),
array(
'name' => 'referenceCode',
'header' => 'Ref Code',
),
array(
'name' => 'designation',
'header' => 'Designation',
),
array(
'name' => 'company',
'header' => 'Company',
),
array(
'name' => 'recommended_actions',
'header' => 'Recommended Action',
'type' => 'html',
'value' => function($jobBoard) {
return CHtml::link($recAction[0]['display_text'], Yii::app()->createUrl($actionUrl, $params));
}
),
array(
'class' => 'CDataColumn',
'header' => 'List of Actions',
'type' => 'html',
'value' => function($jobBoard){
echo '<div class="action-joborder">
<ul class="moveto-joborder">
<li>Action <img height="6" width="7" alt="" src="images/bg_action.gif">
<ul>';
echo '<li>'.CHtml::link($actionArray['display_text'], Yii::app()->createUrl($actionUrl, $params)).'</li>';
echo '</ul>
</li>
</ul>
</div>';
},
'name' => 'actions',
),
)));
?>
the above code gives me footer with pagination only, i want to place a some Button element to give the grid some control.
the grid should look like,
is there any way i can make custom element at the footer.
You can extend framework/zii/widgets/grid/CGridView.php and use it in your code. extend the following method to change footer
public function renderTableFooter()
{
$hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER;
$hasFooter=$this->getHasFooter();
if($hasFilter || $hasFooter)
{
echo "<tfoot>\n";
if($hasFooter)
{
echo "<tr>\n";
foreach($this->columns as $column)
$column->renderFooterCell();
echo "</tr>\n";
}
if($hasFilter)
$this->renderFilter();
echo "</tfoot>\n";
}
}
protected/components/GridView.php
Yii::import('zii.widgets.grid.CGridView');
class GridView extends CGridView
{
/**
* Renders the table footer.
*/
public function renderTableFooter()
{
$hasFilter=$this->filter!==null && $this->filterPosition===self::FILTER_POS_FOOTER;
$hasFooter=$this->getHasFooter();
if($hasFilter || $hasFooter)
{
echo "<tfoot>\n";
if($hasFooter)
{
echo "<tr>\n";
foreach($this->columns as $column){
if($column->footer!='')
$column->footer=eval("return " . $column->footer.";");
$column->renderFooterCell();
}
echo "</tr>\n";
}
if($hasFilter)
$this->renderFilter();
echo "</tfoot>\n";
}
}
public function sumTotal($attribute){
$data=$this->dataProvider->getData();
$sum=0;
foreach($data as $index => $value ){
if(isset($data[$index]->{$attribute}))
$sum+=$data[$index]->{$attribute};
}
return $sum;
}
}
views/{controllers}/{action}.php
$this->widget('GridView',
array('dataProvider' => $dataProvider,
'columns' => array(
array(
'name' => 'created_date',
'header' => 'Created',
),
array(
'name' => 'access_date',
'header' => 'Accessed',
),
array(
'name' => 'referenceCode',
'header' => 'Ref Code',
),
array(
'name' => 'designation',
'header' => 'Designation',
),
array(
'name' => 'company',
'header' => 'Company',
),
array(
'name' => 'recommended_actions',
'header' => 'Recommended Action',
'type' => 'html',
'value' => function($jobBoard) {
return CHtml::link($recAction[0]['display_text'], Yii::app()->createUrl($actionUrl, $params));
}
'footer'=> 'number_format($this->sumTotal("recommended_actions"))',
),
array(
'class' => 'CDataColumn',
'header' => 'List of Actions',
'type' => 'html',
'value' => function($jobBoard){
echo '<div class="action-joborder">
<ul class="moveto-joborder">
<li>Action <img height="6" width="7" alt="" src="images/bg_action.gif">
<ul>';
echo '<li>'.CHtml::link($actionArray['display_text'], Yii::app()->createUrl($actionUrl, $params)).'</li>';
echo '</ul>
</li>
</ul>
</div>';
},
'name' => 'actions',
),
)));