This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I am trying to override a backend widget partial using a plugin. I want the 'Manage widgets' button of the dashboard to only be visible from administrators belonging to a certain group. I didn't find any events to hook onto in order to change the twig template or a way to monkey-patch the widget's render
method. Is it possible?
I finally found a solution.
Short version:
Add the following in the boot()
method of your plugin
ReportContainer::extend(function ($widget) {
$widget->addViewPath(plugins_path().'/myVendor/myPlugin/widgets/reportcontainer/partials/');
});
Explanation
The widget responsible for hosting the dashboard report widgets is Backend\Widgets\ReportContainer
. It extends WidgetBase
which in turn extends Extendable
.
Using the extend()
method of Extendable
you can extend the classes' constructor, calling class methods when an object of that class is instantiated.
WidgetBase
also has the trait ViewMaker
which adds methods for handling views. We can make use of that by calling the addViewPath
method of ViewMaker
to include our path in the view path locations. That way, we can override a template by creating a file of the same name in our new path.
Last updated
support21438 said:
I am trying to override a backend widget partial using a plugin. I want the 'Manage widgets' button of the dashboard to only be visible from administrators belonging to a certain group. I didn't find any events to hook onto in order to change the twig template or a way to monkey-patch the widget's
render
method. Is it possible?
The original issue has been solved with the recent addition of the backend.manage_default_dashboard
permission
1-4 of 4