- Posts: 22
COMMUNITY FORUM
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: 8
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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...
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Is there any documentation for the proper use of the "onLoadTemplate" event?
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
The relevant code is now merged thanks to Daniele in the dev release of K2: getk2.org/downloads/?f=K2_Development_Release.zip
Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Philippe Marty
-
Topic Author
- Offline
- Junior Member
- Posts: 22
So I can upgrade K2 with that release.
@daniele, put on the other hand, what do I need to do to get YTP to use K2 as a content source?
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
There are some last issues we are solving out, but anyhow a custom plugin or child theme configuration would be necessary to make the workflow possible. Will let you know when we have something solid, hopefully soon.
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
Now that the initial limitations have been solved, I have further tested the possibilities of this integration, and I am positive about it possibility. In fact I went ahead and put together a draft that already allows to set a Template for the main K2 Views and map the values of it Items and Categories. I was even able to add support to basic Extra Fields types.
If there is enough interest we could give this project a real chance, so please DM me on Discord (miljan#0690) anyone who is willing to participate in anyway and lets take it from there.
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
github.com/joolanders/ytp-source-k2
@Fotis, there is a PR pending that would make this integration even better, is there anything we can do to get it merged?
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
The right place to report issues or do feature request is here - github.com/joolanders/ytp-source-k2/issues
Please Log in or Create an account to join the conversation.
- Philippe Marty
-
Topic Author
- Offline
- Junior Member
- Posts: 22
We should now manage to make it more known. @Miljan, maybe it's possible to share this extension, with the other Zoolanders extensions, on the Yootheme directory? yootheme.com/support/extensions
Please Log in or Create an account to join the conversation.
- Miljan (ZOOlanders)
-
- Offline
- New Member
- Posts: 8
Please Log in or Create an account to join the conversation.