When attempting to add JS and CSS files to the back office in my module, I encountered an error message stating: "Attempted to call an undefined method named 'registerStylesheet' of class 'AdminModulesController'."
I have come across other resources discussing similar issues, such as this post on Stack Overflow or this guide on PrestaShop's theme documentation.
In an effort to avoid using the deprecated addJS() function, I attempted to use $this->context->controller->registerStylesheet() and $this->context->controller->registerJavascript(), but that resulted in the aforementioned error.
This is the code snippet for my hook:
public function hookActionAdminControllerSetMedia($params)
{
$this->context->controller->registerStylesheet(
'mb_pages_content',
'modules/'.$this->name.'/styles/admin.min.css'
);
$this->context->controller->registerJavascript(
'mb_pages_content',
'modules/'.$this->name.'/js/admin.js'
);
}
Despite following the instructions found online, I discovered that $this->context->controller does not actually have registerStylesheet() and registerJavascript() methods. What could I be missing? Why am I still encountering this error?