Many time we need to show some custom content on Admin Core Controller RenderList.
To display the custom field in the admin controller render list. We need to register the action{ControllerName}ListingFieldsModifier hook.
Check this link https://webkul.com/blog/how-to-modify-fields-list-in-prestashop/ to display the custom field in render list.
To display own HTML content or any customize data, we can use the callback parameter of renderList. But callback searches the method in its own controller. We cannot add the method on admin core controller.
How are we going to use callback inside action{ControllerName}ListingFieldsModifier in our module?
So first we will understand the callback flow and how we can use it in our module.
if (isset($params['callback'])) { $callback_obj= (isset($params['callback_object'])) ? $params['callback_object'] : $this->context->controller; if (!preg_match('/<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)/ism', call_user_func_array(array($callback_obj, $params['callback']), array($field_value, $row)))) { $field_value=call_user_func_array(array($callback_obj, $params['callback']), array($field_value, $row)); } }
Prestashop admin controller first checks the callback parameter is set or not. If set then it checks the callback_object parameter.
If we set the callback_object then the callback method will be searched inside the set object. Otherwise, it will search the callback method in the admin controller.
So how we are going to add our callback method?
So for adding our callback method, we are having a callback_object parameter in the params object.
In callback_object parameter, we will pass the object of the Module
class CallbackExample extends Module { ... public function hookActionAdminOrdersListingFieldsModifier($list) { $optionsOrderStatus = array(1 => 'Select'); if (isset($list['select'])) { $list['select'] .= ', o.`status` AS `type`'; } $list['fields']['type'] = array( 'title' => 'Type', 'align' => 'text-center', 'filter_key' => 'o!status', 'callback' => 'callbackMethod', 'orderby' => false, 'type' => 'select', 'list' => $optionsOrderStatus, 'callback_object' => Module::getInstanceByName($this->name) ); } public function callbackMethod($value) { if ($value) { return '<span class="label label-primary">Test Label</span>'; } } }
So this is how we are going to add our field in the render list of admin controller with our callback method.
I’ll add a custom field and some problems in this search part.
1)After fields add, I’d like to call some formatter in my data and used callback function and redurn some data.
2)After new fields data search not working