Jump to content

Validation of modules supporting WidgetInterface


Recommended Posts

I developed a module supporting the WidgetInterface. The interface requires me to implement also:

public function getWidgetVariables($hookName, array $configuration);

However, the module does not need to get Widget Variables. So I have the method return an empty array, but then the validator complains in the Optimizations section that $hookName and $configuration are not used. To overcome this I have now implemented as below. Does anybody know of a better solution?

public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        if (is_null($hookName) && is_array($configuration)) {
            return [];
        } else {
            return [];
        }
    }

 

Edited by elburgl69 (see edit history)
Link to comment
Share on other sites

No Validation error, but upon installing the module I get the following:

Compile Error: Declaration of LveProductCmsTabs::getWidgetVariables() must be compatible with PrestaShop\PrestaShop\Core\Module\WidgetInterface::getWidgetVariables($hookName, array $configuration)

 

Link to comment
Share on other sites

You have to use same declaration as from the interface, so use

public function getWidgetVariables($hookName = null, array $configuration = []) {}

On 8/21/2020 at 9:55 AM, elburgl69 said:

in the Optimizations section that $hookName and $configuration are not used

These are only optimizations warnings, can be ignored

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...