diff --git a/Classes/Domain/Model/MenuGroup.php b/Classes/Domain/Model/MenuGroup.php index e2cdd9f9d5166909fc0014d6a6441cd7c9884530..e37a5ab50d112b152a27a94150041708af2056aa 100644 --- a/Classes/Domain/Model/MenuGroup.php +++ b/Classes/Domain/Model/MenuGroup.php @@ -9,7 +9,7 @@ namespace NL\NlMenubuilder\Domain\Model; * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * - * (c) 2021 + * (c) 2021 * ***/ /** @@ -20,12 +20,20 @@ class MenuGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity /** * Name of the menu group - * + * * @var string * @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty") */ protected $title = ''; + /** + * Name of the template + * + * @var string + * @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty") + */ + protected $template = ''; + /** * __construct */ @@ -41,7 +49,7 @@ class MenuGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity * Do not modify this method! * It will be rewritten on each save in the extension builder * You may modify the constructor of this class instead - * + * * @return void */ protected function initStorageObjects() @@ -50,7 +58,7 @@ class MenuGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity /** * Returns the title - * + * * @return string title */ public function getTitle() @@ -60,7 +68,7 @@ class MenuGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity /** * Sets the title - * + * * @param string $title * @return void */ @@ -68,4 +76,25 @@ class MenuGroup extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { $this->title = $title; } + + /** + * Returns the template + * + * @return string title + */ + public function getTemplate() + { + return $this->template; + } + + /** + * Sets the template + * + * @param string $template + * @return void + */ + public function setTemplate($template) + { + $this->template = $template; + } } diff --git a/Classes/Domain/Model/MenuItem.php b/Classes/Domain/Model/MenuItem.php index eda0c622be6e9a1ee1b47e567a7335bd67b7f39f..14db26326322c07af72d22cd8025e8ff593164f9 100644 --- a/Classes/Domain/Model/MenuItem.php +++ b/Classes/Domain/Model/MenuItem.php @@ -17,10 +17,10 @@ namespace NL\NlMenubuilder\Domain\Model; */ class MenuItem extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity { - const TYPE_PAGE = '0'; - const TYPE_LINK = '1'; - const TYPE_CONTENT = '2'; - const TYPE_SUBMENU = '3'; + const TYPE_PAGE = 0; + const TYPE_LINK = 1; + const TYPE_CONTENT = 2; + const TYPE_SUBMENU = 3; /** * Type of the menu item @@ -82,6 +82,27 @@ class MenuItem extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity */ protected $submenu = null; + /** + * Get type name of the menu item. + * + * @return string + */ + public function getTypeName(): string + { + switch ($this->type) { + case self::TYPE_PAGE: + return 'Page'; + case self::TYPE_LINK: + return 'Link'; + case self::TYPE_CONTENT: + return 'Content'; + case self::TYPE_SUBMENU: + return 'Submenu'; + } + + return 'Undefined'; + } + /** * Returns the title * @@ -281,7 +302,7 @@ class MenuItem extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity */ public function getSubmenu() { - return $this->submenu; + return $this->submenu->current(); } /** diff --git a/Classes/Hooks/ItemsProcFunc.php b/Classes/Hooks/ItemsProcFunc.php new file mode 100644 index 0000000000000000000000000000000000000000..1ca8bf54e38c52c68b44c08ad0e897e8a867a368 --- /dev/null +++ b/Classes/Hooks/ItemsProcFunc.php @@ -0,0 +1,73 @@ +<?php + +namespace NL\NlMenubuilder\Hooks; + +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Fluid\View\TemplatePaths; +use TYPO3\CMS\Lang\LanguageService; + +class ItemsProcFunc +{ + protected $extensionKey = 'nl_menubuilder'; + + protected $langPrefix = 'LLL:EXT:nl_menubuilder/Resources/Private/Language/locallang_db.xlf:tx_nlmenubuilder_domain_model_menugroup.template.I.'; + + /** + * @var ObjectManager + */ + protected $objectManager; + + /** + * @var TemplatePaths + */ + protected $templatePaths; + + /** + * ItemsProcFunc constructor. + */ + public function __construct() + { + $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class); + $this->templatePaths = $this->objectManager->get(TemplatePaths::class); + } + + /** + * @param array $config + */ + public function loadMenuGroupTemplates(&$config) + { + $this->templatePaths->fillDefaultsByPackageName($this->extensionKey); + + $paths = $this->templatePaths->toArray(); + + $templates = []; + + foreach ($paths[TemplatePaths::CONFIG_TEMPLATEROOTPATHS] as $templatePath) { + $templatePath .= 'ViewHelpers' . DIRECTORY_SEPARATOR . 'Widget'. DIRECTORY_SEPARATOR . 'Show'; + $foundTemplates = GeneralUtility::getFilesInDir($templatePath, 'html'); + + $templates = array_merge($templates, $foundTemplates); + } + + $templates = array_unique($templates); + + foreach ($templates as $template) { + $template = str_replace('.html', '', $template); + $config['items'][] = [ + htmlspecialchars($this->getLanguageService()->sL($this->langPrefix . $template)), + $template + ]; + } + } + + /** + * Returns LanguageService + * + * @return LanguageService + */ + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/Classes/ViewHelpers/Widget/Controller/ShowController.php b/Classes/ViewHelpers/Widget/Controller/ShowController.php new file mode 100644 index 0000000000000000000000000000000000000000..b34c6e7ac6c0e0184f073cdcffd3d58a62419a78 --- /dev/null +++ b/Classes/ViewHelpers/Widget/Controller/ShowController.php @@ -0,0 +1,63 @@ +<?php + +namespace NL\NlMenubuilder\ViewHelpers\Widget\Controller; + +use NL\NlMenubuilder\Domain\Model\Menu; +use NL\NlMenubuilder\Domain\Repository\MenuRepository; +use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController; + +class ShowController extends AbstractWidgetController +{ + /** + * Model object instance of root menu. + * + * @var Menu + */ + protected $menu; + + /** + * Menu group template. + * + * @var string + */ + protected $template; + + /** + * @var MenuRepository + */ + protected $menuRepository; + + /** + * Inject menu repository + * + * @param MenuRepository $controller + */ + public function injectMenuRepository(MenuRepository $menuRepository) + { + $this->menuRepository = $menuRepository; + } + + /** + * Main action + */ + public function indexAction() + { + $this->view->assign('menu', $this->menu); + + return $this->view->render($this->template); + } + + /** + * @return array + */ + public function initializeAction() + { + $uuid = $this->widgetConfiguration['uuid'] ?? 0; + $menu = $this->menuRepository->findByUid($uuid); + + if (!is_null($menu)) { + $this->menu = $menu; + $this->template = $this->menu->getMenuGroup()->getTemplate(); + } + } +} diff --git a/Classes/ViewHelpers/Widget/ShowViewHelper.php b/Classes/ViewHelpers/Widget/ShowViewHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..28e979f6599a88fff9e0c37caffc5d0eb967e3db --- /dev/null +++ b/Classes/ViewHelpers/Widget/ShowViewHelper.php @@ -0,0 +1,47 @@ +<?php + +namespace NL\NlMenubuilder\ViewHelpers\Widget; + +use NL\NlMenubuilder\ViewHelpers\Widget\Controller\ShowController; +use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper; + +class ShowViewHelper extends AbstractWidgetViewHelper +{ + /** + * @var ShowController + */ + protected $controller; + + /** + * Inject controller + * + * @param ShowController $controller + */ + public function injectController(ShowController $controller) + { + $this->controller = $controller; + } + + /** + * Initialize arguments + * + * @return void + */ + public function initializeArguments() + { + $this->registerArgument('uuid', 'int', 'UUID of the menu', true, 0); + } + + /** + * Render everything + * + * @param \TYPO3\CMS\Extbase\Persistence\QueryResultInterface $objects + * @param int $uuid + * @param string $as + * @return string + */ + public function render() + { + return $this->initiateSubRequest(); + } +} diff --git a/Configuration/TCA/tx_nlmenubuilder_domain_model_menugroup.php b/Configuration/TCA/tx_nlmenubuilder_domain_model_menugroup.php index bf2421221113287b7bbe10e3279a3008c910e1fa..b9406678814d6b21a76a30a045d5c83793db3b8a 100644 --- a/Configuration/TCA/tx_nlmenubuilder_domain_model_menugroup.php +++ b/Configuration/TCA/tx_nlmenubuilder_domain_model_menugroup.php @@ -23,10 +23,10 @@ return [ 'iconfile' => 'EXT:nl_menubuilder/Resources/Public/Icons/tx_nlmenubuilder_domain_model_menugroup.gif' ], 'interface' => [ - 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title', + 'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, title, template', ], 'types' => [ - '1' => ['showitem' => "title, --div--;$ll:tabs.access, starttime, endtime, sys_language_uid, l10n_parent, l10n_diffsource, hidden"], + '1' => ['showitem' => "title, template, --div--;$ll:tabs.access, starttime, endtime, sys_language_uid, l10n_parent, l10n_diffsource, hidden"], ], 'columns' => [ 'sys_language_uid' => [ @@ -129,5 +129,15 @@ return [ ], ], + 'template' => [ + 'exclude' => false, + 'label' => "$ll:tx_nlmenubuilder_domain_model_menugroup.template", + 'config' => [ + 'type' => 'select', + 'items' => [], + 'itemsProcFunc' => 'NL\NlMenubuilder\Hooks\ItemsProcFunc->loadMenuGroupTemplates' + ], + ], + ], ]; diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt new file mode 100644 index 0000000000000000000000000000000000000000..c2b542758013ca171625da7498c36cc367ff5ea9 --- /dev/null +++ b/Configuration/TypoScript/setup.txt @@ -0,0 +1,6 @@ +lib.tx_nlmenubuilder.contentElementRendering = RECORDS +lib.tx_nlmenubuilder.contentElementRendering { + tables = tt_content + source.current = 1 + dontCheckPid = 1 +} diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index de906b15af4619346541af9ad72d9b22b5da705c..ce843a2e8318306f7e767ceae8c1f9ead8eaed4d 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -21,6 +21,9 @@ <trans-unit id="tx_nlmenubuilder_domain_model_menugroup.title" resname="tx_nlmenubuilder_domain_model_menugroup.title"> <source>Title</source> </trans-unit> + <trans-unit id="tx_nlmenubuilder_domain_model_menugroup.template" resname="tx_nlmenubuilder_domain_model_menugroup.template"> + <source>Template</source> + </trans-unit> <trans-unit id="tx_nlmenubuilder_domain_model_menuitem" resname="tx_nlmenubuilder_domain_model_menuitem"> <source>Menu Item</source> </trans-unit> diff --git a/Resources/Private/Language/locallang_db.xlf b/Resources/Private/Language/locallang_db.xlf index 331da3ce6e1058444386c623a9b12663eb9b1084..31a1067110881690b3578b471954f330609d8a7d 100644 --- a/Resources/Private/Language/locallang_db.xlf +++ b/Resources/Private/Language/locallang_db.xlf @@ -21,6 +21,9 @@ <trans-unit id="tx_nlmenubuilder_domain_model_menugroup.title" resname="tx_nlmenubuilder_domain_model_menugroup.title"> <source>Title</source> </trans-unit> + <trans-unit id="tx_nlmenubuilder_domain_model_menugroup.template" resname="tx_nlmenubuilder_domain_model_menugroup.template"> + <source>Template</source> + </trans-unit> <trans-unit id="tx_nlmenubuilder_domain_model_menuitem" resname="tx_nlmenubuilder_domain_model_menuitem"> <source>Menu Item</source> </trans-unit> @@ -54,6 +57,13 @@ <trans-unit id="menu.tabs.menu_item" resname="menu.tabs.menu_item"> <source>Menu Items</source> </trans-unit> + <trans-unit id="tx_nlmenubuilder_domain_model_menugroup.template.I.Index" resname="tx_nlmenubuilder_domain_model_menugroup.template.I.Index"> + <source>Index</source> + </trans-unit> + <trans-unit id="tx_nlmenubuilder_domain_model_menugroup.template.I.Show" resname="tx_nlmenubuilder_domain_model_menugroup.template.I.Show"> + <source>Show</source> + </trans-unit> + </body> </file> </xliff> diff --git a/Resources/Private/Partials/Menu.html b/Resources/Private/Partials/Menu.html new file mode 100644 index 0000000000000000000000000000000000000000..ebd4fd7140783ee22bd33f5be543e318b589d024 --- /dev/null +++ b/Resources/Private/Partials/Menu.html @@ -0,0 +1,10 @@ +<div class="menu-builder menu"> + <div class="menu-builder menu-title" hidden>{menu.title}</div> + <div class="menu-builder menu-item-group"> + <f:for each="{menu.menuItem}" as="menuItem"> + <div class="menu-builder menu-item"> + <f:render partial="MenuItem/{menuItem.typeName}" arguments="{menuItem:menuItem}" /> + </div> + </f:for> + </div> +</div> diff --git a/Resources/Private/Partials/MenuItem/Content.html b/Resources/Private/Partials/MenuItem/Content.html new file mode 100644 index 0000000000000000000000000000000000000000..7da59a8347985ca9bba4f8f3ed2a9eb9d4e624a2 --- /dev/null +++ b/Resources/Private/Partials/MenuItem/Content.html @@ -0,0 +1,6 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> + +<div class="menu-builder menu-item-content"> + <div class="menu-builder menu-item-title">{menuItem.title}</div> + <f:cObject typoscriptObjectPath="lib.tx_nlmenubuilder.contentElementRendering">{menuItem.content}</f:cObject> +</div> diff --git a/Resources/Private/Partials/MenuItem/Link.html b/Resources/Private/Partials/MenuItem/Link.html new file mode 100644 index 0000000000000000000000000000000000000000..09fec575ebbcc7cc9b3bba349d9f79810ea12ed6 --- /dev/null +++ b/Resources/Private/Partials/MenuItem/Link.html @@ -0,0 +1,5 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> + +<div class="menu-builder menu-item-link"> + <f:link.typolink parameter="{menuItem.link}">{menuItem.title}</f:link.typolink> +</div> diff --git a/Resources/Private/Partials/MenuItem/Page.html b/Resources/Private/Partials/MenuItem/Page.html new file mode 100644 index 0000000000000000000000000000000000000000..b78e6bf2c6ac5b962a27a0f06d7cd9edeadf6eda --- /dev/null +++ b/Resources/Private/Partials/MenuItem/Page.html @@ -0,0 +1,5 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> + +<div class="menu-builder menu-item-page"> + <f:link.page>{menuItem.page}</f:link.page> +</div> diff --git a/Resources/Private/Partials/MenuItem/Submenu.html b/Resources/Private/Partials/MenuItem/Submenu.html new file mode 100644 index 0000000000000000000000000000000000000000..462732b729df453b44477a2b412cc85c79f5c589 --- /dev/null +++ b/Resources/Private/Partials/MenuItem/Submenu.html @@ -0,0 +1,7 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> + +<div class="menu-builder menu-item-submenu"> + <div class="menu-builder menu-item-title">{menuItem.title}</div> + + <f:render partial="Menu" arguments="{menu:menuItem.submenu}" /> +</div> diff --git a/Resources/Private/Templates/ViewHelpers/Widget/Show/Index.html b/Resources/Private/Templates/ViewHelpers/Widget/Show/Index.html new file mode 100644 index 0000000000000000000000000000000000000000..82456c67b305edf0ccc292a35ee1c6f73fc3ec23 --- /dev/null +++ b/Resources/Private/Templates/ViewHelpers/Widget/Show/Index.html @@ -0,0 +1,9 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> + +<div class="menu-builder menu-group"> + <div>[DEV]Index Template[DEV]</div> + <div class="menu-builder menu-group-title" hidden>{menu.menuGroup.title}</div> + + <f:render partial="Menu" arguments="{menu:menu}" /> + +</div> diff --git a/Resources/Private/Templates/ViewHelpers/Widget/Show/Show.html b/Resources/Private/Templates/ViewHelpers/Widget/Show/Show.html new file mode 100644 index 0000000000000000000000000000000000000000..fc5006d8324f1446a837bb55349c84b8a25fe963 --- /dev/null +++ b/Resources/Private/Templates/ViewHelpers/Widget/Show/Show.html @@ -0,0 +1,9 @@ +<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true"> + +<div class="menu-builder menu-group"> + <div>[DEV]Show Template[DEV]</div> + <div class="menu-builder menu-group-title" hidden>{menu.menuGroup.title}</div> + + <f:render partial="Menu" arguments="{menu:menu}" /> + +</div> diff --git a/ext_tables.sql b/ext_tables.sql index 58dd4a3325872bfcf9754ea6e7206ccbe0370c5d..93728679a6108613cd571c0784359ec437ce8192 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -16,7 +16,8 @@ CREATE TABLE tx_nlmenubuilder_domain_model_menu ( # CREATE TABLE tx_nlmenubuilder_domain_model_menugroup ( - title varchar(255) DEFAULT '' NOT NULL + title varchar(255) DEFAULT '' NOT NULL, + template varchar(255) DEFAULT '' NOT NULL ); @@ -34,7 +35,7 @@ CREATE TABLE tx_nlmenubuilder_domain_model_menuitem ( image int(11) unsigned NOT NULL default '0', page varchar(255) DEFAULT '' NOT NULL, link varchar(255) DEFAULT '' NOT NULL, - content text, + content varchar(255) DEFAULT '' NOT NULL, submenu int(11) unsigned DEFAULT '0' NOT NULL );