Creating a Widget to promote our module anywhere on the FO
First, let’s define what a widget is. From version 1.7 of PrestaShop, the new concept of widgets appeared. Any module can implement a widget interface by adding use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
to its main module class and using class ModuleClassName extends Module implements WidgetInterface
for the main module class definition.
Following this interface, we have to implement the two following functions:
public function renderWidget($hookName, array $configuration); public function getWidgetVariables($hookName, array $configuration);
If we don’t declare any hookNameOfTheHook($params)
functions in our module, the renderWidget()
function will be triggered by the hook’s name provided via the $hookName
argument. The $configuration
argument will contain the params of the hook trigger.
The getWidgetVariables()
function will be used to compute the data to assign to the template...