diff --git a/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/html.php b/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/html.php index be1ba8a5..62ef4f0c 100644 --- a/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/html.php +++ b/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/html.php @@ -126,7 +126,7 @@ protected function configureParams($item) // Merge {{controller.item.name.lower}} params. If this is single-{{controller.item.name.lower}} view, menu params override article params // Otherwise, {{controller.item.name.lower}} params override menu item params $active = $app->getMenu()->getActive(); - $temp = clone ($data->params); + $temp = clone $data->params; $item->params = new Registry($item->params); // Check to see which parameters should take priority @@ -136,7 +136,7 @@ protected function configureParams($item) // If the current view is the active item and an {{controller.item.name.lower}} view for this {{controller.item.name.lower}}, // then the menu item params take priority - if (strpos($currentLink, 'view={{controller.item.name.lower}}') && (strpos($currentLink, '&id=' . (string) $item->id))) + if (strpos($currentLink, 'view={{controller.item.name.lower}}') && strpos($currentLink, '&id=' . $item->id)) { // $item->params are the {{controller.item.name.lower}} params, $temp are the menu item params // Merge so that the menu item params take priority @@ -147,21 +147,27 @@ protected function configureParams($item) { $this->setLayout($active->query['layout']); } + // Check for alternative layout of article + elseif ($layout = $item->params->get('layout_type')) + { + $this->setLayout($layout); + } } else { - // Current view is not a single {{controller.item.name.lower}}, so the {{controller.item.name.lower}} params take priority here - // Merge the menu item params with the {{controller.item.name.lower}} params so that the {{controller.item.name.lower}} params take priority - $temp->merge($item->params); - $this->params = $temp; - // Check for alternative layouts (since we are not in a single-{{controller.item.name.lower}} menu item) // Single-{{controller.item.name.lower}} menu item layout takes priority over alt layout for an {{controller.item.name.lower}} - if ($layout = $data->params->get('layout_type')) + // Make sure set layout first since there may no layout params in item + if ($layout = $item->params->get('layout_type')) { $this->setLayout($layout); } + // Current view is not a single {{controller.item.name.lower}}, so the {{controller.item.name.lower}} params take priority here + // Merge the menu item params with the {{controller.item.name.lower}} params so that the {{controller.item.name.lower}} params take priority + $temp->merge($item->params); + $item->params = $temp; + // If not Active, set Title $this->setTitle($item->get('title')); } @@ -170,11 +176,11 @@ protected function configureParams($item) { // Merge so that article params take priority $temp->merge($data->params); - $this->params = $temp; + $data->params = $temp; // Check for alternative layouts (since we are not in a single-article menu item) // Single-article menu item layout takes priority over alt layout for an article - if ($layout = $data->params->get('layout_type')) + if ($layout = $item->params->get('layout_type')) { $this->setLayout($layout); } diff --git a/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/tmpl/default.xml b/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/tmpl/default.xml index 5ba0aad0..18fb1fd8 100644 --- a/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/tmpl/default.xml +++ b/bundles/GeneratorBundle/Template/component/default/site/view/{{controller.item.name.lower}}/tmpl/default.xml @@ -29,10 +29,11 @@
+ label="{{extension.element.upper}}_ITEM_SETTINGS" + addfieldpath="/libraries/windwalker/src/Form/Fields">
+ label="JGLOBAL_CATEGORY_OPTIONS" + addfieldpath="/libraries/windwalker/src/Form/Fields"> element['client_id']; + + if ($clientId === null && $this->form instanceof JForm) + { + $clientId = $this->form->getValue('client_id'); + } + + $clientId = (int) $clientId; + + $client = JApplicationHelper::getClientInfo($clientId); + + // Get the extension. + $extension = (string) $this->element['extension']; + + if (empty($extension) && ($this->form instanceof JForm)) + { + $extension = $this->form->getValue('extension'); + } + + $extension = preg_replace('#\W#', '', $extension); + + $template = (string) $this->element['template']; + $template = preg_replace('#\W#', '', $template); + + $template_style_id = ''; + if ($this->form instanceof JForm) + { + $template_style_id = $this->form->getValue('template_style_id'); + $template_style_id = preg_replace('#\W#', '', $template_style_id); + } + + $view = (string) $this->element['view']; + $view = preg_replace('#\W#', '', $view); + + // If a template, extension and view are present build the options. + if ($extension && $view && $client) + { + // Load language file + $lang = JFactory::getLanguage(); + $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, true) + || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extension, null, false, true); + + // Get the database object and a new query object. + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + + // Build the query. + $query->select('e.element, e.name') + ->from('#__extensions as e') + ->where('e.client_id = ' . (int) $clientId) + ->where('e.type = ' . $db->quote('template')) + ->where('e.enabled = 1'); + + if ($template) + { + $query->where('e.element = ' . $db->quote($template)); + } + + if ($template_style_id) + { + $query->join('LEFT', '#__template_styles as s on s.template=e.element') + ->where('s.id=' . (int) $template_style_id); + } + + // Set the query and load the templates. + $db->setQuery($query); + $templates = $db->loadObjectList('element'); + + // Build the search paths for component layouts. + $component_path = JPath::clean($client->path . '/components/' . $extension . '/view/' . $view . '/tmpl'); + + // Prepare array of component layouts + $component_layouts = array(); + + // Prepare the grouped list + $groups = array(); + + // Add a Use Global option if useglobal="true" in XML file + if ((string) $this->element['useglobal'] === 'true') + { + $groups[JText::_('JOPTION_FROM_STANDARD')]['items'][] = JHtml::_('select.option', '', JText::_('JGLOBAL_USE_GLOBAL')); + } + + // Add the layout options from the component path. + if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\.xml$', false, true))) + { + // Create the group for the component + $groups['_'] = array(); + $groups['_']['id'] = $this->id . '__'; + $groups['_']['text'] = JText::sprintf('JOPTION_FROM_COMPONENT'); + $groups['_']['items'] = array(); + + foreach ($component_layouts as $i => $file) + { + // Attempt to load the XML file. + if (!$xml = simplexml_load_file($file)) + { + unset($component_layouts[$i]); + + continue; + } + + // Get the help data from the XML file if present. + if (!$menu = $xml->xpath('layout[1]')) + { + unset($component_layouts[$i]); + + continue; + } + + $menu = $menu[0]; + + // Add an option to the component group + $value = basename($file, '.xml'); + $component_layouts[$i] = $value; + $text = isset($menu['option']) ? JText::_($menu['option']) : (isset($menu['title']) ? JText::_($menu['title']) : $value); + $groups['_']['items'][] = JHtml::_('select.option', '_:' . $value, $text); + } + } + + // Loop on all templates + if ($templates) + { + foreach ($templates as $template) + { + // Load language file + $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, true) + || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, true); + + $template_path = JPath::clean( + $client->path + . '/templates/' + . $template->element + . '/html/' + . $extension + . '/' + . $view + ); + + // Add the layout options from the template path. + if (is_dir($template_path) && ($files = JFolder::files($template_path, '^[^_]*\.php$', false, true))) + { + foreach ($files as $i => $file) + { + // Remove layout files that exist in the component folder + if (in_array(basename($file, '.php'), $component_layouts)) + { + unset($files[$i]); + } + } + + if (count($files)) + { + // Create the group for the template + $groups[$template->name] = array(); + $groups[$template->name]['id'] = $this->id . '_' . $template->element; + $groups[$template->name]['text'] = JText::sprintf('JOPTION_FROM_TEMPLATE', $template->name); + $groups[$template->name]['items'] = array(); + + foreach ($files as $file) + { + // Add an option to the template group + $value = basename($file, '.php'); + $text = $lang + ->hasKey( + $key = strtoupper( + 'TPL_' + . $template->name + . '_' + . $extension + . '_' + . $view + . '_LAYOUT_' + . $value + ) + ) + ? JText::_($key) : $value; + $groups[$template->name]['items'][] = JHtml::_('select.option', $template->element . ':' . $value, $text); + } + } + } + } + } + + // Compute attributes for the grouped list + $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; + $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; + + // Prepare HTML code + $html = array(); + + // Compute the current selected values + $selected = array($this->value); + + // Add a grouped list + $html[] = JHtml::_( + 'select.groupedlist', $groups, $this->name, + array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected) + ); + + return implode($html); + } + else + { + return ''; + } + } +} diff --git a/src/View/Engine/AbstractEngine.php b/src/View/Engine/AbstractEngine.php index 420a5d39..1fbb5018 100644 --- a/src/View/Engine/AbstractEngine.php +++ b/src/View/Engine/AbstractEngine.php @@ -1,6 +1,6 @@ layout = $layout; + $this->setLayout($layout); return $this->loadTemplate(null, $data); } @@ -149,7 +150,7 @@ public function loadTemplate($tpl = null, $data = null) if (!$templateFile) { - throw new \Exception(\Joomla\CMS\Language\Text::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file . '.' . $this->layoutExt), 500); + throw new \Exception(\Joomla\CMS\Language\Text::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file . '.' . $this->layoutExt), 500); } $output = $this->execute($templateFile, $data); @@ -227,9 +228,7 @@ public function getPath($layout) $file = \JPath::clean($layout . '.' . $this->layoutExt); // Find the layout file path. - $path = \JPath::find(clone($this->paths), $file); - - return $path; + return \JPath::find(clone $this->paths, $file); } /** diff --git a/src/View/Html/AbstractHtmlView.php b/src/View/Html/AbstractHtmlView.php index 1b635aaf..6b224c86 100644 --- a/src/View/Html/AbstractHtmlView.php +++ b/src/View/Html/AbstractHtmlView.php @@ -71,6 +71,8 @@ abstract class AbstractHtmlView extends AbstractView * @param Container $container DI Container. * @param array $config View config. * @param \SplPriorityQueue $paths Paths queue. + * + * @throws \Exception */ public function __construct(Model $model = null, Container $container = null, $config = array(), \SplPriorityQueue $paths = null) {