I am trying to find a hook that will let me add my own code into an existing elementor widget. For example they have the "post widget" which lets you display a list of posts based on the conditions/categories you set.
I would like to add my own code into this "block" but am unable to find any specific hooks for hooking into an existing widget (specifically the posts widget)
Any help would be much appreciated. Is there a hook for this? If not what is my next best option?
Thanks!
This depends on what you want to achieve but in general there are hooks.
I am not sure about the posts-widget but I can show you some examples in general.
If you want to add controls to a widget use this (you can find additional information to the names and stuff in their documentation https://developers.elementor.com/add-controls-to-widgets/)
add_action( 'elementor/element/heading/section_title/before_section_end', function( $element, $args ) {
$element->add_control( 'title_color',
[
'label' => 'Color' ,
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'red',
'options' => [
'red' => 'Red',
'blue' => 'Blue',
],
'section' => 'section_title',
'tab' => 'content',
]
);
}, 10, 2);
the widget in the example is the heading. You can find out the registered names by inspecting the editor or the blocks inside the plugin directory
If you want to change the rendered content of a widget you can use this
add_action( 'elementor/widget/render_content', function( $content, $widget ){ // $content (string) = the rendered content of the widget; widget = the data object
if ($widget->get_name() === 'heading') { // your targeted widget
$settings = $widget->get_settings(); // every that is stored in this method. Titles, captions, margins and so on. Usually this is all you need
// eg if you simply want to wrap your widgets content you can do something like this
$content .= '<div class="i-am-a-wrapper">'.$content.'</div>';
}
return $content;
}, 10, 2 );
I hope this helps :)
Related
Im trying to build a custom Elementor widget in my own category, but when I created a custom category, it was not displayed in the edit panel, which means I have to search my widget name to find it.
Does any know how to fix it?
The code:
function add_elementor_widget_categories() {
\Elementor\Plugin::instance()->$elements_manager->add_category(
'category-name',
[
'title' => __( 'Test Category', 'plugin-name' ),
'icon' => 'fa fa-plug',
]
);
}
add_action( 'elementor/elements/categories_registered', 'add_elementor_widget_categories' );
This code is from Elementor sample code, but I don't know why it doesn't work.
in my yii2 project i've got a gridview with a simple checkbox column.
<?=
GridView::widget([
'id' => 'gridwithcheckboxes',
'dataProvider' => $dataProvider,
'columns' => [
['attribute' => 'a', 'value' => 'tabfora.a'],
['attribute' => 'b', 'value' => 'tabforb.b'],
'user',
'mobile',
'description',
['class' => 'yii\grid\CheckboxColumn'],
],
]);
?>
I know i can get the checkboxes values by this js helper:
var keys = $('#gridwithcheckboxes').yiiGridView('getSelectedRows');
Is there a method to pass them with a form submit to a controller action instead using javascript?
Thanks for all the help.
I resolve this problem like this.
Create link in which href you will add ids of the rows you checked.
<a href="" class="btn btn-info" target="_blank" id="exampleButton" data-pjax=false>Button</a>
Then register a javascript action in the bottom of the page, where on click of the checkbox you will update href of link.
<?php
$this->registerJs('
$(document).on("ready pjax:success", function() {
$(".kv-row-checkbox").change(function(){
var keys = $("#gridwithcheckboxes").yiiGridView("getSelectedRows");
var keysJson = JSON.stringify(keys);
$("a[id=\"exampleButton\"]").attr("href", "name-of-action?keys="+keysJson);
});
$(".select-on-check-all").change(function(){
var keys = $("#gridwithcheckboxes").yiiGridView("getSelectedRows");
var keysJson = JSON.stringify(keys);
$("a[id=\"exampleButton\"]").attr("href", "name-of-action?keys="+keysJson);
});
});
',View::POS_READY);
?>
.kv-row-checkbox and .select-on-check-all are classes of checkboxes, you must check if yours are different.
In the controller
public function actionNameOfAction($keys)
{
// decoding
$keys = json_decode($keys);
// Operation with ids
......
}
I use the gridview widget including the checkbox column within regular html form tags to pass the selected id's via $_POST. You need to have a hidden input with value =Yii::$app->request->getCsrfToken(), or it won't work. In the controller, $_POST['selection] is an array of the selected id's.
The only way to do it via form is actually to wrap a gridview with a form. The form should start before the gridview and end after the gridview. You can have one or two submit buttons.
It doesn't mean you can't use ajax for this if you want.
I have FriendsofCake Bootstrap-ui plugin. I see in the source that it accepts text for the pagination prev and next labels.
I am not sure how to exactly set the config option though.
PaginatorHelper.php
if (isset($options['next'])) {
if ($options['next'] === true) {
$options['next'] = $this->config('labels.next');
}
$options['after'] = $this->next($options['next'], ['escape' => false]) . $options['after'];
}
I was trying this below in the bootstrap.php but no effect
Configure::write('friendsofcake.PaginatorHelper.labels.prev', 'previous');
But I see they are also set in the __construct
Answer
With the help from drmonkeyninja here is the exact code needed to configure the labels in the AppView.php
$this->loadHelper(
'Paginator',
[
'className' => 'BootstrapUI.Paginator',
'labels' => [
'prev' => 'previous',
'next' => 'next',
]
]
);
This appears to be badly documented, but to configure any of the settings for a helper you need to pass them as an array when you load it. So for example, if you are loading the Paginator helper inside your AppView you would pass prevlike this:-
$this->loadHelper(
'Paginator',
[
'className' => 'BootstrapUI.Paginator',
'prev' => 'previous'
]
);
How can i give different title for different radio button using CakePHP Form Helper
$radio_options = array('unknown'=>'Unknown','negative'=>'Negative','positive'=>'Positive');
$titles = array('0'=>'Unknown','1'=>'Negative','2'=>'Positive');
I am trying to create radio buttons like this
echo $this->Form->input('radio_buttons', array(
'options' => $radio_options,
'legend' =>false,
'label' => true,
'div'=>false,
'class'=>'radio inline',
'type' => 'radio',
'separator'=>'<br>',
'title'=>$titles,));
But its not working..Form Helper creating same title for all of the radio buttons.
Look at what the FormHelper generates, then generate it manually or with a php foreach loop or something.
There are cases like this, when it's just easier (or the only way) to not use a helper.
I have a Slider model having some associated Images (models). When editing a Slider, there's a tab for its images. Now this can be modified, to select and deselect containing images. This, it seems, is done through an admin grid, having a checkbox column (the "values" key is for testing):
$this->addColumn('in_slider', array(
'header_css_class' => 'a-center',
'type' => 'checkbox',
'name' => 'in_slider',
'values' => array(1,2),
'align' => 'center',
'index' => 'slider_image_id'
));
Let's say the Slider in the above image has one image attached, and that works fine. But, when user selects "Any" and clicks "Search", all images must show, but those that are not associated should be deselected. I think this is standard behavior for such a feature.
What I don't get is the mechanism behind those two buttons: Reset Filter and Search. From what I've managed to dig up, a grid class has a getGridUrl() method which is used to refresh the grid data (via AJAX). That URL mapping to a controller.
// in grid class
public function getGridUrl()
{
return $this->getUrl('*/*/editGrid', array('_current' => true));
}
// Image controller
public function editGridAction()
{
$blockMarkup = $this->getLayout()->createBlock('module/someblock')->toHtml();
$this->getResponse()->setBody($blockMarkup);
}
But what about the "Search" button? How does that work?
How do other modules know when to show ALL entities, or searching for "Yes" or "No"?
When saving the slider, how can one grab the selected values? Working in Slider controller's saveAction I presume, but how do you get the checkbox values?
What you're looking for is a mass action. Add this function to your grid file (whatever extends Mage_Adminhtml_Block_Weidget_Grid):
protected function _prepareMassaction()
{
$this->setMassactionIdField('some_ID');
$this->getMassactionBlock()->setFormFieldName('element_name'); //html name of checkbox
$this->getMassactionBlock()->addItem('some_ID', array(
'label'=> __('Some Label'),
'url' => $this->getUrl('*/*/doSomething'), //an action defined in the controller
'selected' => 'selected',
'confirm' => __('Are you sure?')
));
return $this;
}
Here's a good blog post that helps to explain the concept:
http://inchoo.net/ecommerce/magento/how-to-add-massactions-to-magentos-grid/