[FEATURE] Add to "additionalWhere" to TypoScript menus 42/19242/5
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sun, 28 Dec 2014 17:19:26 +0000 (18:19 +0100)
committerBenjamin Mack <benni@typo3.org>
Tue, 30 Dec 2014 17:29:45 +0000 (18:29 +0100)
Allow for TMENU/GMENU to have a new option called
"additionalWhere" to narrow down the SQL query put
in the makeMenu function in the PageRepository.

The patch adds a new TypoScript option which is just
sending an extra parameter to the getMenu() function.

This is possible for all HMENU options supported by
the TYPO3 CMS core.

Releases: master
Resolves: #46624
Change-Id: Ia96b6aa95049ea6de9ecfd4a5adb69e71ccde2b7
Reviewed-on: http://review.typo3.org/19242
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-46624-AdditionalWhereForMenu.rst [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-46624-AdditionalWhereForMenu.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-46624-AdditionalWhereForMenu.rst
new file mode 100644 (file)
index 0000000..623935a
--- /dev/null
@@ -0,0 +1,16 @@
+==========================================================
+Feature: #46624 - HMENU item selection via additionalWhere
+==========================================================
+
+Description
+===========
+
+The TypoScript Content Object HMENU menu options have a new property called "additionalWhere" to
+allow for a more specific database query based on any page properties.
+
+.. code-block:: typoscript
+
+       lib.authormenu = HMENU
+       lib.authormenu.1 = TMENU
+       lib.authormenu.1.additionalWhere = AND author!=""
+       ...
index fb16e6e..208a837 100644 (file)
@@ -385,6 +385,18 @@ class AbstractMenuContentObject {
                                // Temporarily removing fe_group checking!
                                $this->sys_page->where_groupAccess = '';
                        }
+
+                       // additional where clause, usually starts with AND (as usual with all additionalWhere functionality in TS)
+                       if (isset($this->mconf['additionalWhere']) || isset($this->mconf['additionalWhere.'])) {
+                               if (isset($this->mconf['additionalWhere.'])) {
+                                       $additionalWhere = $this->parent_cObj->stdWrap($this->mconf['additionalWhere'], $this->mconf['additionalWhere.']);
+                               } else {
+                                       $additionalWhere = $this->mconf['additionalWhere'];
+                               }
+                       } else {
+                               $additionalWhere = '';
+                       }
+
                        // Begin production of menu:
                        $temp = array();
                        $altSortFieldValue = trim($this->mconf['alternativeSortingField']);
@@ -742,7 +754,7 @@ class AbstractMenuContentObject {
                                                                $recArr['index'] = $this->sys_page->getPage($recArr['up']['pid']);
                                                        }
                                                        // prev / next is found
-                                                       $prevnext_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($value_rec['pid'], '*', $altSortField));
+                                                       $prevnext_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($value_rec['pid'], '*', $altSortField, $additionalWhere));
                                                        $lastKey = 0;
                                                        $nextActive = 0;
                                                        foreach ($prevnext_menu as $k_b => $v_b) {
@@ -765,12 +777,12 @@ class AbstractMenuContentObject {
                                                        // prevsection / nextsection is found
                                                        // You can only do this, if there is a valid page two levels up!
                                                        if (is_array($recArr['index'])) {
-                                                               $prevnextsection_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($recArr['index']['uid'], '*', $altSortField));
+                                                               $prevnextsection_menu = $this->removeInaccessiblePages($this->sys_page->getMenu($recArr['index']['uid'], '*', $altSortField, $additionalWhere));
                                                                $lastKey = 0;
                                                                $nextActive = 0;
                                                                foreach ($prevnextsection_menu as $k_b => $v_b) {
                                                                        if ($nextActive) {
-                                                                               $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($v_b['uid'], '*', $altSortField));
+                                                                               $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($v_b['uid'], '*', $altSortField, $additionalWhere));
                                                                                if (count($sectionRec_temp)) {
                                                                                        reset($sectionRec_temp);
                                                                                        $recArr['nextsection'] = pos($sectionRec_temp);
@@ -781,7 +793,7 @@ class AbstractMenuContentObject {
                                                                        }
                                                                        if ($v_b['uid'] == $value_rec['pid']) {
                                                                                if ($lastKey) {
-                                                                                       $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($prevnextsection_menu[$lastKey]['uid'], '*', $altSortField));
+                                                                                       $sectionRec_temp = $this->removeInaccessiblePages($this->sys_page->getMenu($prevnextsection_menu[$lastKey]['uid'], '*', $altSortField, $additionalWhere));
                                                                                        if (count($sectionRec_temp)) {
                                                                                                reset($sectionRec_temp);
                                                                                                $recArr['prevsection'] = pos($sectionRec_temp);
@@ -839,9 +851,8 @@ class AbstractMenuContentObject {
                        } elseif ($this->mconf['sectionIndex']) {
                                $temp = $this->sectionIndex($altSortField);
                        } else {
-                               // Default:
-                               // gets the menu
-                               $temp = $this->sys_page->getMenu($this->id, '*', $altSortField);
+                               // Default, gets a hierarchical menu based on subpages of $this->id
+                               $temp = $this->sys_page->getMenu($this->id, '*', $altSortField, $additionalWhere);
                        }
                        $c = 0;
                        $c_b = 0;