[FEATURE] Added ActionMenuItemGroupViewHelper 87/38487/10
authorMichael Oehlhof <typo3@oehlhof.de>
Sat, 4 Apr 2015 22:35:38 +0000 (00:35 +0200)
committerFrank Nägler <typo3@naegler.net>
Sat, 2 May 2015 18:24:37 +0000 (20:24 +0200)
Using this ViewHelper we can use OptGroups in the backend selectfield
which controls which function selected.

Resolves: #62242
Releases: master
Change-Id: I7208691c305068764496c09b3f3d5ccc8f1b7665
Reviewed-on: http://review.typo3.org/38487
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
typo3/sysext/beuser/Resources/Private/Layouts/Default.html
typo3/sysext/core/Documentation/Changelog/master/Feature-62242-ActionMenuItemGroupViewHelper.rst [new file with mode: 0644]
typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php [new file with mode: 0644]

index f01c92b..c691e8b 100644 (file)
@@ -32,4 +32,4 @@
                        </div>
                </div>
        </div>
-</f:be.container>
\ No newline at end of file
+</f:be.container>
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-62242-ActionMenuItemGroupViewHelper.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-62242-ActionMenuItemGroupViewHelper.rst
new file mode 100644 (file)
index 0000000..9de9d24
--- /dev/null
@@ -0,0 +1,35 @@
+===============================================
+Feature: #62242 - ActionMenuItemGroupViewHelper
+===============================================
+
+Description
+===========
+
+Using this ViewHelper, OptGroups can be used in the backend select field, which controls which action is selected.
+
+
+Impact
+======
+
+The new ViewHelper can be used in all new projects. There is no interference with any part of existing code.
+
+
+Examples
+========
+
+Usage example:
+
+.. code-block:: html
+
+       <f:be.menus.actionMenu>
+               <f:be.menus.actionMenuItem label="Default: Welcome" controller="Default" action="index" />
+               <f:be.menus.actionMenuItem label="Community: get in touch" controller="Community" action="index" />
+
+               <f:be.menus.actionMenuItemGroup label="Information">
+                       <f:be.menus.actionMenuItem label="PHP Information" controller="Information" action="listPhpInfo" />
+                       <f:be.menus.actionMenuItem label="Documentation" controller="Information" action="documentation" />
+                       <f:be.menus.actionMenuItem label="Hooks" controller="Information" action="hooks" />
+                       <f:be.menus.actionMenuItem label="Signals" controller="Information" action="signals" />
+                       <f:be.menus.actionMenuItem label="XClasses" controller="Information" action="xclass" />
+               </f:be.menus.actionMenuItemGroup>
+       </f:be.menus.actionMenu>
diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Be/Menus/ActionMenuItemGroupViewHelper.php
new file mode 100644 (file)
index 0000000..fffd69b
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Menus;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 3
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
+
+/**
+ * View helper which groups options of an option tag.
+ *
+ * = Example =
+ *
+ *     <f:be.menus.actionMenu>
+ *             <f:be.menus.actionMenuItem label="Default: Welcome" controller="Default" action="index" />
+ *             <f:be.menus.actionMenuItem label="Community: get in touch" controller="Community" action="index" />
+ *
+ *             <f:be.menus.actionMenuItemGroup label="Information">
+ *                     <f:be.menus.actionMenuItem label="PHP Information" controller="Information" action="listPhpInfo" />
+ *                     <f:be.menus.actionMenuItem label="Documentation" controller="Information" action="documentation" />
+ *                     <f:be.menus.actionMenuItem label="Hooks" controller="Information" action="hooks" />
+ *                     <f:be.menus.actionMenuItem label="Signals" controller="Information" action="signals" />
+ *                     <f:be.menus.actionMenuItem label="XClasses" controller="Information" action="xclass" />
+ *             </f:be.menus.actionMenuItemGroup>
+ *     </f:be.menus.actionMenu>
+ *
+ */
+class ActionMenuItemGroupViewHelper extends ActionMenuViewHelper {
+
+       /**
+        * @var string
+        */
+       protected $tagName = 'optgroup';
+
+       /**
+        * @param string $label
+        * @return string
+        */
+       public function render($label = '') {
+               $this->tag->addAttribute('label', $label);
+               $options = '';
+               foreach ($this->childNodes as $childNode) {
+                       if ($childNode instanceof ViewHelperNode && $childNode->getViewHelperClassName() === ActionMenuItemViewHelper::class) {
+                               $options .= $childNode->evaluate($this->renderingContext);
+                       }
+               }
+               $this->tag->setContent($options);
+               return $this->tag->render();
+       }
+}