You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.1 KiB
106 lines
3.1 KiB
<?php
|
|
/**
|
|
* @package Joomla.Site
|
|
* @subpackage com_foos
|
|
*
|
|
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
*/
|
|
|
|
namespace FooNamespace\Component\Foos\Site\View\Foo;
|
|
|
|
\defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\Registry\Registry;
|
|
|
|
/**
|
|
* HTML Foos View class for the Foo component
|
|
*
|
|
* @since __BUMP_VERSION__
|
|
*/
|
|
class HtmlView extends BaseHtmlView
|
|
{
|
|
/**
|
|
* The page parameters
|
|
*
|
|
* @var \Joomla\Registry\Registry|null
|
|
* @since __BUMP_VERSION__
|
|
*/
|
|
protected $params = null;
|
|
|
|
/**
|
|
* The item model state
|
|
*
|
|
* @var \Joomla\Registry\Registry
|
|
* @since __BUMP_VERSION__
|
|
*/
|
|
protected $state;
|
|
|
|
/**
|
|
* The item object details
|
|
*
|
|
* @var \JObject
|
|
* @since __BUMP_VERSION__
|
|
*/
|
|
protected $item;
|
|
|
|
/**
|
|
* Execute and display a template script.
|
|
*
|
|
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
|
|
*
|
|
* @return mixed A string if successful, otherwise an Error object.
|
|
*/
|
|
public function display($tpl = null)
|
|
{
|
|
$item = $this->item = $this->get('Item');
|
|
|
|
$state = $this->state = $this->get('State');
|
|
$params = $this->params = $state->get('params');
|
|
$itemparams = new Registry(json_decode($item->params));
|
|
|
|
$temp = clone $params;
|
|
|
|
/**
|
|
* $item->params are the foo params, $temp are the menu item params
|
|
* Merge so that the menu item params take priority
|
|
*
|
|
* $itemparams->merge($temp);
|
|
*/
|
|
|
|
// Merge so that foo params take priority
|
|
$temp->merge($itemparams);
|
|
$item->params = $temp;
|
|
|
|
$active = Factory::getApplication()->getMenu()->getActive();
|
|
|
|
// Override the layout only if this is not the active menu item
|
|
// If it is the active menu item, then the view and item id will match
|
|
if ((!$active) || ((strpos($active->link, 'view=foo') === false) || (strpos($active->link, '&id=' . (string) $this->item->id) === false))) {
|
|
if (($layout = $item->params->get('foos_layout'))) {
|
|
$this->setLayout($layout);
|
|
}
|
|
} else if (isset($active->query['layout'])) {
|
|
// We need to set the layout in case this is an alternative menu item (with an alternative layout)
|
|
$this->setLayout($active->query['layout']);
|
|
}
|
|
|
|
Factory::getApplication()->triggerEvent('onContentPrepare', ['com_foos.foo', &$item, &$item->params]);
|
|
|
|
// Store the events for later
|
|
$item->event = new \stdClass;
|
|
$results = Factory::getApplication()->triggerEvent('onContentAfterTitle', ['com_foos.foo', &$item, &$item->params]);
|
|
$item->event->afterDisplayTitle = trim(implode("\n", $results));
|
|
|
|
$results = Factory::getApplication()->triggerEvent('onContentBeforeDisplay', ['com_foos.foo', &$item, &$item->params]);
|
|
$item->event->beforeDisplayContent = trim(implode("\n", $results));
|
|
|
|
$results = Factory::getApplication()->triggerEvent('onContentAfterDisplay', ['com_foos.foo', &$item, &$item->params]);
|
|
$item->event->afterDisplayContent = trim(implode("\n", $results));
|
|
|
|
return parent::display($tpl);
|
|
}
|
|
}
|