Hey All
Is there any way that I can override layout of view from plugin?
Thanks
-- Ofer Cohen TP2 - The new way to manage your modules
Hannes
Am 21.03.2012 12:28, schrieb Ofer Cohen:
>
> Hey All
>
> Is there any way that I can override layout of view from plugin?
>
> Thanks
>
> --
> Ofer Cohen
> TP2 <http://extensions.joomla.org/extensions/style-a-design/modules-management/19884> - The new way to manage your modules
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To post to this group, send an email to
> joomla-de...@googlegroups.com.
> To unsubscribe from this group, send email to
> joomla-dev-gene...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
I tried to get that in with this pull request, but it was denied: https://github.com/joomla/joomla-platform/pull/421 Hannes
As Hannes mentioned, it's not possible using the API. In my own plugin, I've added a method to check for overrides following the same logic as component views based on some code in a JoomlaWorks plugin I use. You can see it at https://github.com/mbabker/Yet-Another-Social-Plugin/blob/master/yetanothersocial.php#L308.
Regardless of that, the code that I proposed allows for A LOT more than
just "overriding" a view. And even though I agree with the notion that
the MVC most likely needs to be revamped, I first have to see the code
before I stop bugging everyone with these small improvements. The
changes to JView were ready in time for Joomla 1.7 and thus could
already be used by lots of people for at least 2 major releases. There
isn't a lot more than good intentions regarding a new MVC as far as I
know. And even if there were, that still leaves a few thousand legacy
extensions out there using the old code. So as long as we are talking
about varporware, please don't dismiss my code as "obsolete soon anyway".
Hannes
> TP2 <http://extensions.joomla.org/extensions/style-a-design/modules-management/19884> - The new way to manage your modules
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/joomla-dev-general/-/_lf6hgcXaKoJ.
Hey Amy
Thanks for your reply. It took half a day to find how to override
view (layout can't be override) and here is how I did it:
public function onAfterRoute() {
$app = JFactory::getApplication();
if (!$app->isAdmin() || JRequest::getString('option')
!= 'com_banners'
|| JRequest::getString('view') != 'banner') {//check
if we're on the right view
return;
}
jimport('joomla.application.component.controller');
$params = array(
'base_path' => JPATH_BASE . '/components/' .
JRequest::getString('option'),
'view_path' => dirname(__FILE__),
);
$b = JController::getInstance('Banners', $params);
$b->addViewPath(dirname(__FILE__) . '/views');
}
This will load the plugin view before the component view. Because
it's loading first, it will use the first that load. The loading
done via getInstance.
I copy the view banner from admin com_banners to the plugin views folder and then override it.
Hope it will help someone one day. I'll put it in the docs soon. What is the best place in the wiki to put it?
Thanks
Ofer Cohen
--
Hey Amy
Thanks for the example. I added it to the wiki page
http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core#Further_tips
(as a link).
The difference between my approach to yours is that mine override
the view and not extends it like you did (but perhaps I can get
over that too. I didn't try yet). In addition I didn't need to
"touch" the model.
Amy, you make my day :-)
Ofer Cohen