- Posts: 21
COMMUNITY FORUM
The use of formatted code blocks has been restored in our (Kunena powered) forum for old and new threads.
Any code should (again) be placed within [code]...[/code] tags in the message editor.
K2 as YOOtheme Pro content source
- Philippe Marty
-
Topic Author
- Offline
- Junior Member
I want to use K2 as a content source in the Yootheme Pro builder. YOOtheme
I am in contact with the Zoolanders team to think about the feasibility of this development. They are interested in the subject, but need a relay in your teams for some information.
Who would be the person available for this?
I think this project would be a great asset for the attractiveness of K2 because Yootheme has become a major player in terms of visual builder for Joomla.
I am at your disposal for any question on the subject.
Thanks in advance,
Phil
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 4
I went ahead and put together a draft for this possible integration to find out a first major issue. YOOtheme Pro Builder relies on the onLoadTemplate joomla standard event to determine the context of the current view, turns out K2 doesn't fire such event.
If this is confirmed, I would like to know about the reasons and possible fixes. If is not, would appreciate some support on the matter.
Thanks!
Please Log in or Create an account to join the conversation.
- Fotis
-
- Offline
- Admin
- Posts: 6088
What's the case exactly?
As for plugins events, we include the most common ones as a com_content replacement (and more) but I've never heard of this "onLoadTemplate" event (and I can't find anything in Joomla's docs). Any hints are welcome...
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 4
Unfortunately K2, in the display method of its views, calls addPath a number of times after the YTP stream wrapper is registered (which happens in the Joomla onBeforeDisplay event), and therefore the stream wrapper (and the new event) is not called, since Joomla takes the first path in the list.
Possible solutions:
1. Move the addPath calls before Joomla calls the onBeforeDisplay event, which means not in the View display method
2. Trigger this custom onLoadTemplate event yourselves after the various addPath calls in your views.
Please Log in or Create an account to join the conversation.
- Fotis
-
- Offline
- Admin
- Posts: 6088
Is there any documentation for the proper use of the "onLoadTemplate" event?
Please Log in or Create an account to join the conversation.
- Daniele
-
- Offline
- New Member
- Posts: 2
Basically what YTP does is custom triggering that even with 2 parameters, the view object and the template file.
here's the specifis:
$app = Factory::getApplication();
$app->triggerEvent('onLoadTemplate', [$view, $tpl]);
where
$view is the View object (children of the JView class)
$tpl is the name of the layout used, without path or extension (example "links" or "content"). They take it form the $view-->getLayout() method.
The full code of their beforeDisplay listener that does this is
public static function beforeDisplay(Config $config, $event)
{
if ($config('app.isAdmin')) {
return;
}
$view = $event->getArgument('subject');
// loader callback for template event
$loader = function ($path) use ($view) {
// Clone view to avoid mutations on the original view
$copy = clone $view;
$copy->set('_output', null);
$copy->set('context', basename($copy->get('_basePath')) . ".{$copy->getName()}");
$tpl = substr(basename($path, '.php'), strlen($copy->getLayout()) + 1) ?: null;
var_dump('TPL: ' . $tpl);
var_dump('Class: ' . get_class($copy));
$app = Factory::getApplication();
$app->triggerEvent('onLoadTemplate', [$copy, $tpl]);
return $copy->get('_output');
};
// register the stream wrapper
if (!in_array('views', stream_get_wrappers())) {
stream_wrapper_register('views', StreamWrapper::class);
}
// add loader using a stream reference
// check if path is available (StackIdeas com_payplan)
if ($path = $view->get('_path')) {
array_unshift($path, 'views://' . StreamWrapper::setObject($loader));
$view->set('_path', $path);
}
}
Hope this helps!
Please Log in or Create an account to join the conversation.
- Fotis
-
- Offline
- Admin
- Posts: 6088
From what Miljan said, you should inject your code around here: github.com/getk2/k2/blob/master/components/com_k2/views/item/view.html.php#L773
However I have no idea how YTP works and *how* it fetches content from third-party components like K2. I asked before but Miljan did not provide this info.
Test if your added code works and if it does, simply send me the code and I'll add it in. Remember to add some sort of context under which this event will be triggered, e.g. a way to detect that YTP is calling this piece of code. There is no reason to fire an event on every request if the associated component is not present or used in a Joomla site.
Please Log in or Create an account to join the conversation.
- Daniele
-
- Offline
- New Member
- Posts: 2
Please Log in or Create an account to join the conversation.
- Fotis
-
- Offline
- Admin
- Posts: 6088
Please Log in or Create an account to join the conversation.
- Fotis
-
- Offline
- Admin
- Posts: 6088
The relevant code is now merged thanks to Daniele in the dev release of K2: getk2.org/downloads/?f=K2_Development_Release.zip
Please Log in or Create an account to join the conversation.