Keyword

K2 as YOOtheme Pro content source

  • Philippe Marty
  • Philippe Marty's Avatar Topic Author
  • Offline
  • Junior Member
More
2 years 8 months ago #179910 by Philippe Marty
K2 as YOOtheme Pro content source was created by Philippe Marty
Hello @fotis and K2 devs,

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)
  • Miljan (ZOOlanders)'s Avatar
  • Offline
  • New Member
More
2 years 7 months ago #179919 by Miljan (ZOOlanders)
Replied by Miljan (ZOOlanders) on topic K2 as YOOtheme Pro content source
Hi everyone,

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.

More
2 years 7 months ago #179930 by JoomlaWorks
Replied by JoomlaWorks on topic K2 as YOOtheme Pro content source
Since I'm not aware (nor use) YooTheme Pro (let's call it YTP for now), I'd like some guidance on how you'd like to integrate K2 as a source for it. My guess is that YTP either retrieves K2 content in the backend and displays it within its own context (=component view) or it injects code with K2 component views.

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)
  • Miljan (ZOOlanders)'s Avatar
  • Offline
  • New Member
More
2 years 7 months ago #179939 by Miljan (ZOOlanders)
Replied by Miljan (ZOOlanders) on topic K2 as YOOtheme Pro content source
What YTP does to allow for the builder templating is register a new _path in the Joomla View Classes dynamically. This path is actually a stream wrapper, that simply introduces this new onLoadTemplate event in Joomla. This is because Joomla itself does not trigger an even when a view is loading a template in its loadTemplateLayout call in View classes.

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.

More
2 years 7 months ago #179940 by JoomlaWorks
Replied by JoomlaWorks on topic K2 as YOOtheme Pro content source
Since the onBeforeDisplay is triggered essentially by the view template, we can't load it before the actual template override inclusion. So it's down to point 2.

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.

More
2 years 7 months ago #179947 by Daniele
Replied by Daniele on topic K2 as YOOtheme Pro content source
Hi, colleague of Miljan (ZOOlanders) here.

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.

More
2 years 7 months ago #179948 by JoomlaWorks
Replied by JoomlaWorks on topic K2 as YOOtheme Pro content source
OK, since I'm not using YTP, please grab a copy of K2 directly from GitHub (this is the URL getk2.org/downloads/?f=K2_Development_Release.zip), install it in a dev site with YTP and make the relevant change e.g. on the item view (the article equivalent for K2).

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.

More
2 years 7 months ago #179949 by Daniele
Replied by Daniele on topic K2 as YOOtheme Pro content source
Did a PR so you have less work ahead of you :)

github.com/getk2/k2/pull/551

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179952 by JoomlaWorks
Replied by JoomlaWorks on topic K2 as YOOtheme Pro content source
Thank you - let's continue this over at GitHub and I'll update this post later.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #179953 by JoomlaWorks
Replied by JoomlaWorks on topic K2 as YOOtheme Pro content source
@Philippe Marty

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.


Powered by Kunena Forum