Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Overriding a core view from a plugin?
JasonJudge
New
I would like to add some checkboxes below the search field in the search form, as a part of a plugin. I cannot find any events to hook into, allowing me to alter the search form, as the search form is built entirely within the view:
applications/dashboard/views/search/index.php
Now, that view can be overridden in the theme, and that works fine. However, I then have a theme view and a plugin, both of which need to be installed together to work. Is there any way the view can be put into the plugin and be made to override the core view from there?
-- Jason
Tagged:
0
Comments
did you try including the over-riding php using the same structure as you would in the theme?
Vanilla Wiki, Tastes Great! 31,000 viewers can't be wrong. || Plugin Development Explained
One way through routing
Another way
grep is your friend.
just put search.php in you plugin's views folder.
grep is your friend.
TBH I didn't. I'll give that a go.
It doesn't, arguably it could.
I think the issue is there is one theme, and many plugins.
grep is your friend.
there is a typo in the above code an extra
;
grep is your friend.
That is perfect @x00 - thanks :-)
Essentially in my plugin I have this event hook:
The "dashboard/search/" path is relative to the plugin's own "views" folder. This overrides the standard view for the core SearchController. The index.php view is a copy of the core applications/dashboard/views/search/index.php but with a few extra lines in it.
The additional code you have supplied will check whether the theme has overridden this view first, and run the theme version if it is. I'll incorporate that into my plugin too and put a note in the installation instructions to warn installers about this (you could imagine several plugins and a theme wanting to take over that view as well as possibly an updated version of the core view, and the installer would need to merge them together).
-- Jason
This is the final code:
So I can override the plugin-override in the theme here:
It is a long path, but I am aiming to keep it consistent with the path of the original view in the core and with the path that you would normally use in the theme if you wanted to override the core view.
Hopefully this is useful to someone.
-- Jason