diff --git a/modules/mod_menu/mod_menu.php b/modules/mod_menu/mod_menu.php index a8dbcc9f96427..de1f86309041f 100644 --- a/modules/mod_menu/mod_menu.php +++ b/modules/mod_menu/mod_menu.php @@ -10,19 +10,38 @@ defined('_JEXEC') or die; -use Joomla\CMS\Helper\ModuleHelper; +// TS changes - start use Joomla\Module\Menu\Site\Helper\MenuHelper; +use Joomla\Module\Menu\Site\Module\MenuModule; +// TS changes - end -$list = MenuHelper::getList($params); -$base = MenuHelper::getBase($params); -$active = MenuHelper::getActive($params); -$default = MenuHelper::getDefault(); -$active_id = $active->id; +$list = MenuHelper::getList($params); +$base = MenuHelper::getBase($params); +$active = MenuHelper::getActive($params); +$default = MenuHelper::getDefault(); +$active_id = $active->id; $default_id = $default->id; -$path = $base->tree; -$showAll = $params->get('showAllChildren', 1); -$class_sfx = htmlspecialchars($params->get('class_sfx', ''), ENT_COMPAT, 'UTF-8'); +$path = $base->tree; +$showAll = $params->get('showAllChildren', 1); +$class_sfx = htmlspecialchars($params->get('class_sfx', ''), ENT_COMPAT, 'UTF-8'); -if (count($list)) { - require ModuleHelper::getLayoutPath('mod_menu', $params->get('layout', 'default')); -} +// TS changes - start +$data = [ + 'module' => $module, + 'list' => $list, + 'active' => $active, + 'default' => $default, + 'active_id' => $active_id, + 'default_id' => $default_id, + 'path' => $path, + 'showAll' => $showAll, + 'class_sfx' => $class_sfx, +]; + +$modInstance = new MenuModule($params, $module); +$modInstance->setData($data); + +$layout = '@module/mod_menu/' . explode(':', $params->get('layout', 'default'))[1] . '/' . explode(':', $params->get('layout', 'default'))[1] . '.html.twig'; + +echo $modInstance->render($layout); +// TS changes - end diff --git a/modules/mod_menu/src/Module/MenuModule.php b/modules/mod_menu/src/Module/MenuModule.php new file mode 100644 index 0000000000000..22316ff477ddc --- /dev/null +++ b/modules/mod_menu/src/Module/MenuModule.php @@ -0,0 +1,59 @@ + - http://katalysteducation.org + */ + +namespace Joomla\Module\Menu\Site\Module; + +defined('_JEXEC') || die; + +\JLoader::import('twig.library'); + +use Phproberto\Joomla\Twig\Module\BaseTwigModule; + +/** +* Menu module. +* +* @since 2.0.0 +*/ +class MenuModule extends BaseTwigModule +{ + /** + * Module created by module + * + * @var string + */ + protected $data; + + /** + * Method to set data from module. + * + * @param array $data + */ + public function setData(array $data) : void + { + $this->data = $data; + } + + /** + * Load layout data. + * + * @return array + */ + protected function loadLayoutData() : array + { + return [ + 'cssClass' => $this->getCssClass(), + 'cssId' => $this->getCssId(), + 'moduleInstance' => $this, + 'params' => $this->getParams(), + 'data' => $this->data + ]; + } +} diff --git a/modules/mod_menu/tmpl/collapse-default.php b/modules/mod_menu/tmpl/collapse-default.php deleted file mode 100644 index d41f70689460e..0000000000000 --- a/modules/mod_menu/tmpl/collapse-default.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Text; - -HTMLHelper::_('bootstrap.collapse'); -?> - - diff --git a/modules/mod_menu/tmpl/default.php b/modules/mod_menu/tmpl/default.php index 1c1ca4c63e579..1a47f8d9bcfcc 100644 --- a/modules/mod_menu/tmpl/default.php +++ b/modules/mod_menu/tmpl/default.php @@ -1,92 +1 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Helper\ModuleHelper; - -/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ -$wa = $app->getDocument()->getWebAssetManager(); -$wa->registerAndUseScript('mod_menu', 'mod_menu/menu.min.js', [], ['type' => 'module']); -$wa->registerAndUseScript('mod_menu', 'mod_menu/menu-es5.min.js', [], ['nomodule' => true, 'defer' => true]); - -$id = ''; - -if ($tagId = $params->get('tag_id', '')) { - $id = ' id="' . $tagId . '"'; -} - -// The menu class is deprecated. Use mod-menu instead -?> - class="mod-menu mod-list nav "> - &$item) { - $itemParams = $item->getParams(); - $class = 'nav-item item-' . $item->id; - - if ($item->id == $default_id) { - $class .= ' default'; - } - - if ($item->id == $active_id || ($item->type === 'alias' && $itemParams->get('aliasoptions') == $active_id)) { - $class .= ' current'; - } - - if (in_array($item->id, $path)) { - $class .= ' active'; - } elseif ($item->type === 'alias') { - $aliasToId = $itemParams->get('aliasoptions'); - - if (count($path) > 0 && $aliasToId == $path[count($path) - 1]) { - $class .= ' active'; - } elseif (in_array($aliasToId, $path)) { - $class .= ' alias-parent-active'; - } - } - - if ($item->type === 'separator') { - $class .= ' divider'; - } - - if ($item->deeper) { - $class .= ' deeper'; - } - - if ($item->parent) { - $class .= ' parent'; - } - - echo '
  • '; - - switch ($item->type) : - case 'separator': - case 'component': - case 'heading': - case 'url': - require ModuleHelper::getLayoutPath('mod_menu', 'default_' . $item->type); - break; - - default: - require ModuleHelper::getLayoutPath('mod_menu', 'default_url'); - break; - endswitch; - - // The next item is deeper. - if ($item->deeper) { - echo '
  • ', $item->level_diff); - } else { - // The next item is on the same level. - echo ''; - } -} -?> + diff --git a/modules/mod_menu/tmpl/default/default.html.twig b/modules/mod_menu/tmpl/default/default.html.twig new file mode 100644 index 0000000000000..aa0c59d6de2f1 --- /dev/null +++ b/modules/mod_menu/tmpl/default/default.html.twig @@ -0,0 +1,16 @@ + diff --git a/modules/mod_menu/tmpl/default/default.md b/modules/mod_menu/tmpl/default/default.md new file mode 100644 index 0000000000000..7b3a7adb55815 --- /dev/null +++ b/modules/mod_menu/tmpl/default/default.md @@ -0,0 +1,97 @@ +## Info + +**Module:** mod_menu + +**Template:** default + +**Description:** This is the view which we use to display a default menu items. + +## Data + +### {{ data.list }} + +This is a list of all menu items. It should be displayed in such way: +``` +{% if data.list|length > 0 %} + +{% endif %} +``` + +**Tips:** + + - Item link should be taken from: + ``` +{{ item.flink }} + ``` + + - Info about active element should be taken from the `data.path` for specific ID: + ``` +if item.id in data.path + ``` + or for the `aliasoptions` for the an 'alias' **NOT TESTED**: + ``` +data.path|length > 0 and item.params.get('aliasoptions') == data.path|last + ``` + + - If the next item is deeper: + ``` +{% if item.deeper %} + ``` + + - If the next item is shallower: + ``` +{% elseif item.shallower %} + ``` + + - How many levels should be ended: + ``` + {% for i in range(1, item.level_diff) %} + + {% endfor %} + ``` + +### {{ data.base }} + +This is a base menu item (usualy is the same as active). + +### {{ data.active }} + +This is an active menu item. + +### {{ data.default }} + +This is a default menu item for the webpage (home page). + +### {{ data.active_id }} + +This is a ID for active item. + +### {{ data.default_id }} + +This is a ID for default item. + +### {{ data.path }} + +This is a path for current subpage. + +### {{ data.showAll }} + +This is a showAll marker. + +### {{ pageclass_sfx }} + +CSS class suffix. diff --git a/modules/mod_menu/tmpl/default_component.php b/modules/mod_menu/tmpl/default_component.php deleted file mode 100644 index 35f4521441d76..0000000000000 --- a/modules/mod_menu/tmpl/default_component.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Filter\OutputFilter; -use Joomla\CMS\HTML\HTMLHelper; - -$attributes = array(); - -if ($item->anchor_title) { - $attributes['title'] = $item->anchor_title; -} - -if ($item->anchor_css) { - $attributes['class'] = $item->anchor_css; -} - -if ($item->anchor_rel) { - $attributes['rel'] = $item->anchor_rel; -} - -if ($item->id == $active_id) { - $attributes['aria-current'] = 'location'; - - if ($item->current) { - $attributes['aria-current'] = 'page'; - } -} - -$linktype = $item->title; - -if ($item->menu_icon) { - // The link is an icon - if ($itemParams->get('menu_text', 1)) { - // If the link text is to be displayed, the icon is added with aria-hidden - $linktype = '' . $item->title; - } else { - // If the icon itself is the link, it needs a visually hidden text - $linktype = '' . $item->title . ''; - } -} elseif ($item->menu_image) { - // The link is an image, maybe with its own class - $image_attributes = []; - - if ($item->menu_image_css) { - $image_attributes['class'] = $item->menu_image_css; - } - - $linktype = HTMLHelper::_('image', $item->menu_image, $item->title, $image_attributes); - - if ($itemParams->get('menu_text', 1)) { - $linktype .= '' . $item->title . ''; - } -} - -if ($item->browserNav == 1) { - $attributes['target'] = '_blank'; -} elseif ($item->browserNav == 2) { - $options = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes'; - - $attributes['onclick'] = "window.open(this.href, 'targetWindow', '" . $options . "'); return false;"; -} - -echo HTMLHelper::_('link', OutputFilter::ampReplace(htmlspecialchars($item->flink, ENT_COMPAT, 'UTF-8', false)), $linktype, $attributes); diff --git a/modules/mod_menu/tmpl/default_heading.php b/modules/mod_menu/tmpl/default_heading.php deleted file mode 100644 index ccd5a22b63efe..0000000000000 --- a/modules/mod_menu/tmpl/default_heading.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\HTML\HTMLHelper; - -$title = $item->anchor_title ? ' title="' . $item->anchor_title . '"' : ''; -$anchor_css = $item->anchor_css ?: ''; -$linktype = $item->title; - -if ($item->menu_icon) { - // The link is an icon - if ($itemParams->get('menu_text', 1)) { - // If the link text is to be displayed, the icon is added with aria-hidden - $linktype = '' . $item->title; - } else { - // If the icon itself is the link, it needs a visually hidden text - $linktype = '' . $item->title . ''; - } -} elseif ($item->menu_image) { - // The link is an image, maybe with its own class - $image_attributes = []; - - if ($item->menu_image_css) { - $image_attributes['class'] = $item->menu_image_css; - } - - $linktype = HTMLHelper::_('image', $item->menu_image, $item->title, $image_attributes); - - if ($itemParams->get('menu_text', 1)) { - $linktype .= '' . $item->title . ''; - } -} - -?> -> diff --git a/modules/mod_menu/tmpl/default_separator.php b/modules/mod_menu/tmpl/default_separator.php deleted file mode 100644 index 5eab1ff28307e..0000000000000 --- a/modules/mod_menu/tmpl/default_separator.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\HTML\HTMLHelper; - -$title = $item->anchor_title ? ' title="' . $item->anchor_title . '"' : ''; -$anchor_css = $item->anchor_css ?: ''; -$linktype = $item->title; - -if ($item->menu_icon) { - // The link is an icon - if ($itemParams->get('menu_text', 1)) { - // If the link text is to be displayed, the icon is added with aria-hidden - $linktype = '' . $item->title; - } else { - // If the icon itself is the link, it needs a visually hidden text - $linktype = '' . $item->title . ''; - } -} elseif ($item->menu_image) { - // The link is an image, maybe with its own class - $image_attributes = []; - - if ($item->menu_image_css) { - $image_attributes['class'] = $item->menu_image_css; - } - - $linktype = HTMLHelper::_('image', $item->menu_image, $item->title, $image_attributes); - - if ($itemParams->get('menu_text', 1)) { - $linktype .= '' . $item->title . ''; - } -} - -?> -> diff --git a/modules/mod_menu/tmpl/default_url.php b/modules/mod_menu/tmpl/default_url.php deleted file mode 100644 index c9e46ccd8a782..0000000000000 --- a/modules/mod_menu/tmpl/default_url.php +++ /dev/null @@ -1,69 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -defined('_JEXEC') or die; - -use Joomla\CMS\Filter\OutputFilter; -use Joomla\CMS\HTML\HTMLHelper; - -$attributes = array(); - -if ($item->anchor_title) { - $attributes['title'] = $item->anchor_title; -} - -if ($item->anchor_css) { - $attributes['class'] = $item->anchor_css; -} - -if ($item->anchor_rel) { - $attributes['rel'] = $item->anchor_rel; -} - -$linktype = $item->title; - -if ($item->menu_icon) { - // The link is an icon - if ($itemParams->get('menu_text', 1)) { - // If the link text is to be displayed, the icon is added with aria-hidden - $linktype = '' . $item->title; - } else { - // If the icon itself is the link, it needs a visually hidden text - $linktype = '' . $item->title . ''; - } -} elseif ($item->menu_image) { - // The link is an image, maybe with an own class - $image_attributes = []; - - if ($item->menu_image_css) { - $image_attributes['class'] = $item->menu_image_css; - } - - $linktype = HTMLHelper::_('image', $item->menu_image, $item->title, $image_attributes); - - if ($itemParams->get('menu_text', 1)) { - $linktype .= '' . $item->title . ''; - } -} - -if ($item->browserNav == 1) { - $attributes['target'] = '_blank'; - $attributes['rel'] = 'noopener noreferrer'; - - if ($item->anchor_rel == 'nofollow') { - $attributes['rel'] .= ' nofollow'; - } -} elseif ($item->browserNav == 2) { - $options = 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,' . $params->get('window_open'); - - $attributes['onclick'] = "window.open(this.href, 'targetWindow', '" . $options . "'); return false;"; -} - -echo HTMLHelper::_('link', OutputFilter::ampReplace(htmlspecialchars($item->flink, ENT_COMPAT, 'UTF-8', false)), $linktype, $attributes);