Elementor Widget - repeater responsive margin control doesn't work - controls

I've got some trouble with creating repeater responsive margin control in my Elementor widget. I dynamically create items in the widget and I need this field to be able to change the position of my items in the widget.
My code below doesn't work.
// Content section
$this->start_controls_section(
'content_section',
[
'label' => __( 'Content', 'watt-elements' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
...
$repeater = new \Elementor\Repeater();
$repeater->add_responsive_control(
'feature_margin',
[
'label' => __( 'Feature margin', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', 'em', '%' ],
'selectors' => [
'{{WRAPPER}} {{CURRENT_ITEM}} .feature-tip' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]);
...
$this->end_controls_section();

I know it is a late reply but should be helpful for someone.
You need to add the below dynamic class for {{CURRENT_ITEM}}.
class="elementor-repeater-item-<?php echo $item['_id']; ?>"

Related

Color and underline in wysiwyg field

I'm developing with backpack for laraver and I'm using wysiwyg field. I would like to use underline and change font color. I'm searched in ckeditor webpage and it seems it supports these functions.
How can I enable them?
Best regards
Edit - I don't understand why I'm receiving negatives for this question. What I'm doing wrong?
Edit 2-
Thank you Delighted,
Here is the code I'm using, but forecolor option seems not to be working. The button does not appear.
$this->crud->addField([
'name' => 'desc1',
'label' => 'DescipciĆ³n 1',
'type' => 'tinymce',
// optional overwrite of the configuration array
'options' => [
'selector' => 'textarea.tinymce',
'skin' => 'dick-light',
'plugins' => 'image,link,media,anchor',
'toolbar' => 'undo redo formatselect fontsizeselect bullist numlist link image bold italic underline forecolor',
],
]);
What you are looking for is the options index in the field configuration which is documented here
Essentially, you'll want to include the options index in your field configuration and add to it any of the options that you would normally pass to the javascript init method of TinyMce if you were using it manually.
The specific option you want is the toolbar option. Here's a list of controls you can add to the toolbar
Here's a quick example:
$this->crud->addField([
'name' => 'description',
'label' => 'Description',
'type' => 'tinymce',
// optional overwrite of the configuration array
'options' => [
'selector' => 'textarea.tinymce',
'skin' => 'dick-light',
'plugins' => 'image,link,media,anchor',
'toolbar' => 'forecolor underline',
],
]);
For a closer look at exactly how these options are passed to tinymce, see the tinymce field blade template lines 33 - 50
I have finally got that. I had to add textcolor and colorpicker as plugins.
The resultant code is as follows.
$this->crud->addField([
'name' => 'desc1',
'label' => 'DescipciĆ³n 1',
'type' => 'tinymce',
// optional overwrite of the configuration array
'options' => [
'selector' => 'textarea.tinymce',
//'statusbar' => false,
'skin' => 'dick-light',
'plugins' => 'image,link,media,anchor,textcolor,colorpicker',
'toolbar' => [
'undo redo | styleselect | bold italic | link image | forecolor',
'alignleft aligncenter alignright'
]
],
]);
Thank you very much Delighted00

How to add the alt and title fields in an image field of a custom entity in drupal 8

I created a custom entity with an image field. But I can not display the alt and title fields.
Here is my code:
$fields['main_img'] = BaseFieldDefinition::create('image')
->setLabel(t('Main image of the hardware'))
->setSettings([
'file_directory' => 'hardware',
'file_extensions' => 'png jpg jpeg',
])
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'image',
'weight' => -30,
))
->setDisplayOptions('form', array(
'label' => 'above',
'type' => 'image_image',
'weight' => -30,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Could you tell me how to display the alt and title fields of my image and maybe someone knows where the documentation is for doing that because I can not find it?
Thank you all
I loaded one of my node field definitions with $node->getFieldDefinitions():
I believe you can try something like this:
->setDisplayOptions('form', array(
'label' => 'above',
'type' => 'image_image',
'weight' => -30,
'settings' => [
'alt_field' => TRUE,
'alt_field_required' => TRUE, //optional
'title_field' => TRUE,
'title_field_required' => TRUE, //optional
],
))
Thank Dmytro.
I feel a little stupid but it's life.
It was enough to add 'alt_field_required' => FALSE and 'title_field' => TRUE in setSettings.
But as title and alt is displayed that when we download an image I thought it did not work.
A day of lost!

How do I limit number of characters in the admin form in magento

I have following code in my Form.php
$fieldset->addField('desc', 'textarea', array(
'label' => Mage::helper('module')->__('Description'),
'required' => true,
'name' => 'desc',
));
How to restrict the number of characters in this text area?
In theory you should be able to do that by adding to the textarea a maxlength attribute.
So you should end up with something like this:
<textarea maxlength="50"></textarea>
But Magento does not allow the maxlength attribute.
If you take a look at the Varien_Data_Form_Element_Textarea class (the one responsable for rendering textareas) you will see this method.
public function getHtmlAttributes()
{
return array('title', 'class', 'style', 'onclick', 'onchange', 'rows', 'cols', 'readonly', 'disabled', 'onkeyup', 'tabindex');
}
Those are the only ones that you can specify when you create the element.
First option would be to extend this class and add the maxlength among the allowed attributes, then your column could look like this:
$fieldset->addField('desc', 'textarea', array(
'label' => Mage::helper('module')->__('Description'),
'required' => true,
'name' => 'desc',
'maxlength' => 50
));
The second option is to add it via some javascript.
$fieldset->addField('desc', 'textarea', array(
'label' => Mage::helper('module')->__('Description'),
'required' => true,
'name' => 'desc',
'after_element_html' => '<script type="text/javascript">Event.observe(window, "load", function() {$("id_of_textarea_here").setAttribute("maxlength", 50)})</script>'
));
A third option would be to insert instead of the javascript above some code that limits the length of the text.
You can find an example here.
Final Note:
the content from after_element_html will be displayed in the form right after the element. So you can basically put anything there.

Magento Admin Grid - How to assign an action/function to a button?

I created a new module and I managed to list all the orders from the shop.
I also added a button (with this code).
$link= Mage::helper('adminhtml')->getUrl('adminhtml/order/sync/') .'id/$entity_id';
$this->addColumn('action_edit', array(
'header' => $this->helper('catalog')->__('Action'),
'width' => 15,
'sortable' => false,
'filter' => false,
'type' => 'action',
'actions' => array(
array(
'url' => $link,
'caption' => $this->helper('catalog')->__('Sync'),
),
)
));
I really don't know how to assign an action to this button. What I should create in my custom module ? A new controller?
I need to display something or get some data when I click this button...
thank you very much
I think you should write
public function YourActionNameAction()
{
}
in your Module controller file

How to translate form labels in Zend Framework 2?

I'm not getting it!.. Can please someone explain, how to translate form labels? A simple example would be great.
Thank you in advance!
class Search\Form\CourseSearchForm
...
class CourseSearchForm extends Form {
...
public function __construct(array $cities) {
parent::__construct('courseSearch');
...
$this->add(array(
'name' => 'city',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Stadt',
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
));
...
}
}
view script /module/Search/view/search/search/search-form.phtml
<?php echo $this->form()->openTag($form); ?>
<dl>
...
<dt><label><?php echo $form->get('city')->getLabel(); ?></label></dt>
<dd><?php echo $this->formRow($form->get('city'), null, false, false); ?></dd>
...
</dl>
<?php echo $this->form()->closeTag(); ?>
<!-- The formRow(...) is my MyNamespace\Form\View\Helper (extends Zend\Form\View\Helper\FormRow); the fourth argument of it disables the label. -->
The module/Application/config/module.config.php is configured:
return array(
'router' => ...
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'de_DE',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => ...
'view_manager' => ...
);
I also edited my view and use the FormLabel view helper:
<dt><label><?php echo $this->formLabel($form->get('city')); ?></label></dt>
Furthermore I debugged the FormLabel at the place, where the tranlator is used (lines 116-120) -- seems to be OK.
But it's still not working.
EDIT
The (test) items for labels, I added to the de_DE.po file manually, are tranlated. The ZF2 side problem was actually, that I was using $form->get('city')->getLabel() instead of $this->formlabel($form->get('city')) in th view script.
The problem is now, that the labels are not added to the de_DE.po file. But it's not a ZF2 issue anymore, so I've accept Ruben's answer and open a new Poedit question.
Instead of using:
<?php echo $form->get('city')->getLabel(); ?>
You should use the formlabel view helper. This helper automatically uses your translator during rendering if you have inserted it in your ServiceManager. Most likely you will have it in your Application's module module.config.php:
'service_manager' => array(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
Once you do use the formlabel view helper:
echo $this->formLabel($form->get('city'));
And of course make sure your translations are in your .po file.
i think your problem is that you label are not detected by poedit (or similar tool), so you have to add them manually to your poedit catalogs (.po)
to make your label strings detected by tools like poedit, your strings need to be used inside a translate() function or _() (other function can be added in Catalog/properties/sources keyword)
as the _() function is not user in ZF2 (today) so a tiny hack is to add a function like this in your index.php (no need to modify anything, this way, in poedit params):
// in index.php
function _($str)
{
return $str;
}
and in your code, just use it when your strings are outside of a translate function
//...
$this->add(array(
'name' => 'city',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => _('myLabel') , // <------ will be detected by poedit
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
));
//...
or like this if you prefer
$myLabel = _('any label string'); // <--- added to poedit catalog
//...
'options' => array(
'label' => $myLabel ,
'value_options' => $this->cities,
'id' => 'searchFormCity',
),
#Ruben says right!
Me I use PoEdit to generate my *.mo files and to be sure to get all translations in the file, I create somewhere (in view for example) a file named _lan.phtml with all text to be translated :
<?php echo $this->translate("My label");
... ?>
Of course, Poedit has to be configured to find my keywords. check this to how to configure it
All solutions don't use the power of ZF2. You must configure your poedit correctly :
All things are here :
http://circlical.com/blog/2013/11/5/localizing-your-twig-using-zend-framework-2-applications

Resources