‪TYPO3CMS  ‪main
TextMenuContentObject.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 {
34  public function ‪writeMenu()
35  {
36  if (empty($this->result)) {
37  return '';
38  }
39 
40  $frontendController = $this->‪getTypoScriptFrontendController();
41  $cObjectForCurrentMenu = GeneralUtility::makeInstance(ContentObjectRenderer::class);
42  $menuContent = '';
43  $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
44  $subMenuObjSuffixes = $typoScriptService->explodeConfigurationForOptionSplit(['sOSuffix' => $this->mconf['submenuObjSuffixes'] ?? null], count($this->result));
45  $explicitSpacerRenderingEnabled = ($this->mconf['SPC'] ?? false);
46  foreach ($this->result as $key => $val) {
47  $frontendController->register['count_HMENU_MENUOBJ']++;
48  $frontendController->register['count_MENUOBJ']++;
49 
50  // Initialize the cObj with the page record of the menu item
51  $cObjectForCurrentMenu->setRequest($this->request);
52  $cObjectForCurrentMenu->start($this->menuArr[$key], 'pages');
53  $this->I = [];
54  $this->I['key'] = $key;
55  $this->I['val'] = $val;
56  $this->I['title'] = $this->‪getPageTitle($this->menuArr[$key]['title'] ?? '', $this->menuArr[$key]['nav_title'] ?? '');
57  $this->I['title.'] = $this->I['val']['stdWrap.'] ?? [];
58  $this->I['title'] = $cObjectForCurrentMenu->stdWrapValue('title', $this->I ?? []);
59  $this->I['uid'] = $this->menuArr[$key]['uid'] ?? 0;
60  $this->I['mount_pid'] = $this->menuArr[$key]['mount_pid'] ?? 0;
61  $this->I['pid'] = $this->menuArr[$key]['pid'] ?? 0;
62  $this->I['spacer'] = $this->menuArr[$key]['isSpacer'] ?? false;
63  // Make link tag
64  $this->I['val']['additionalParams'] = $cObjectForCurrentMenu->stdWrapValue('additionalParams', $this->I['val']);
65  $linkResult = $this->‪link((int)$key, (string)($this->I['val']['altTarget'] ?? ''), ($this->mconf['forceTypeValue'] ?? ''));
66  if ($linkResult === null) {
67  $this->I['val']['doNotLinkIt'] = 1;
68  }
69  // Title attribute of links
70  $titleAttrValue = $cObjectForCurrentMenu->stdWrapValue('ATagTitle', $this->I['val']);
71  if ($linkResult && $titleAttrValue !== '') {
72  $linkResult = $linkResult->withAttribute('title', $titleAttrValue);
73  }
74  $this->I['linkHREF'] = $linkResult;
75  $this->I['val']['doNotLinkIt'] = (bool)$cObjectForCurrentMenu->stdWrapValue('doNotLinkIt', $this->I['val']);
76  // Compile link tag
77  if (!$this->I['spacer'] && !$this->I['val']['doNotLinkIt']) {
78  $this->‪setATagParts($linkResult);
79  } else {
80  $this->I['A1'] = '';
81  $this->I['A2'] = '';
82  }
83  // ATagBeforeWrap processing:
84  if ($this->I['val']['ATagBeforeWrap'] ?? false) {
85  $wrapPartsBefore = explode('|', $this->I['val']['linkWrap'] ?? '');
86  $wrapPartsAfter = ['', ''];
87  } else {
88  $wrapPartsBefore = ['', ''];
89  $wrapPartsAfter = explode('|', $this->I['val']['linkWrap'] ?? '');
90  }
91  if (($this->I['val']['stdWrap2'] ?? false) || isset($this->I['val']['stdWrap2.'])) {
92  $stdWrap2 = (string)(isset($this->I['val']['stdWrap2.']) ? $cObjectForCurrentMenu->stdWrap('|', $this->I['val']['stdWrap2.']) : '|');
93  $stdWrap2Value = (string)($this->I['val']['stdWrap2'] ?? '|');
94  $stdWrap2Value = $stdWrap2Value !== '' ? $stdWrap2Value : '|';
95  $wrapPartsStdWrap = explode($stdWrap2Value, $stdWrap2);
96  } else {
97  $wrapPartsStdWrap = ['', ''];
98  }
99  // Make before, middle and after parts
100  $this->I['parts'] = [];
101  $this->I['parts']['before'] = $this->‪getBeforeAfter('before', $cObjectForCurrentMenu);
102  $this->I['parts']['stdWrap2_begin'] = $wrapPartsStdWrap[0] ?? '';
103  // stdWrap for doNotShowLink
104  $this->I['val']['doNotShowLink'] = $cObjectForCurrentMenu->stdWrapValue('doNotShowLink', $this->I['val']);
105  if (!$this->I['val']['doNotShowLink']) {
106  $this->I['parts']['notATagBeforeWrap_begin'] = $wrapPartsAfter[0] ?? '';
107  $this->I['parts']['ATag_begin'] = $this->I['A1'];
108  $this->I['parts']['ATagBeforeWrap_begin'] = $wrapPartsBefore[0] ?? '';
109  $this->I['parts']['title'] = $this->I['title'];
110  $this->I['parts']['ATagBeforeWrap_end'] = $wrapPartsBefore[1] ?? '';
111  $this->I['parts']['ATag_end'] = $this->I['A2'];
112  $this->I['parts']['notATagBeforeWrap_end'] = $wrapPartsAfter[1] ?? '';
113  }
114  $this->I['parts']['stdWrap2_end'] = $wrapPartsStdWrap[1] ?? '';
115  $this->I['parts']['after'] = $this->‪getBeforeAfter('after', $cObjectForCurrentMenu);
116  // Passing I to a user function
117  if ($this->mconf['IProcFunc'] ?? false) {
118  $this->I = $this->‪userProcess('IProcFunc', $this->I);
119  }
120  // Merge parts + beforeAllWrap
121  $this->I['theItem'] = implode('', $this->I['parts']);
122  $allWrap = $cObjectForCurrentMenu->stdWrapValue('allWrap', $this->I['val']);
123  $this->I['theItem'] = $cObjectForCurrentMenu->wrap($this->I['theItem'], $allWrap);
124  if ($this->I['val']['subst_elementUid'] ?? false) {
125  $this->I['theItem'] = str_replace('{elementUid}', (string)$this->I['uid'], $this->I['theItem']);
126  }
127  if (is_array($this->I['val']['allStdWrap.'] ?? null)) {
128  $this->I['theItem'] = $cObjectForCurrentMenu->stdWrap($this->I['theItem'], $this->I['val']['allStdWrap.']);
129  }
130  $isSpacerPage = $this->I['spacer'] ?? false;
131  // If rendering of SPACERs is enabled, also allow rendering submenus with Spacers
132  if (!$isSpacerPage || $explicitSpacerRenderingEnabled) {
133  // Add part to the accumulated result + fetch submenus
134  $this->I['theItem'] .= $this->‪subMenu($this->I['uid'], $subMenuObjSuffixes[$key]['sOSuffix'] ?? '', $key);
135  }
136  $part = $cObjectForCurrentMenu->stdWrapValue('wrapItemAndSub', $this->I['val']);
137  $menuContent .= $part ? $cObjectForCurrentMenu->wrap($this->I['theItem'], $part) : $this->I['theItem'];
138  }
139  if (is_array($this->mconf['stdWrap.'] ?? null)) {
140  $menuContent = (string)$cObjectForCurrentMenu->stdWrap($menuContent, $this->mconf['stdWrap.']);
141  }
142  return $cObjectForCurrentMenu->wrap($menuContent, $this->mconf['wrap'] ?? '');
143  }
144 
156  protected function ‪getBeforeAfter(string $pref, ‪ContentObjectRenderer $cObjectForCurrentMenu): string
157  {
158  $processedPref = $cObjectForCurrentMenu->‪stdWrapValue($pref, $this->I['val']);
159  if (isset($this->I['val'][$pref . 'Wrap'])) {
160  return $cObjectForCurrentMenu->‪wrap($processedPref, $this->I['val'][$pref . 'Wrap']);
161  }
162  return $processedPref;
163  }
164 }
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\getPageTitle
‪string getPageTitle($title, $nav_title)
Definition: AbstractMenuContentObject.php:1540
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\link
‪LinkResultInterface null link($key, $altTarget, $typeOverride)
Definition: AbstractMenuContentObject.php:1172
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
Definition: AbstractMenuContentObject.php:53
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\userProcess
‪mixed userProcess($mConfKey, $passVar)
Definition: AbstractMenuContentObject.php:1514
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string int bool null stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1139
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\wrap
‪string wrap($content, $wrap, $char='|')
Definition: ContentObjectRenderer.php:4359
‪TYPO3\CMS\Frontend\ContentObject\Menu\TextMenuContentObject
Definition: TextMenuContentObject.php:26
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\subMenu
‪string subMenu(int $uid, string $objSuffix, int $menuItemKey)
Definition: AbstractMenuContentObject.php:1249
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\getTypoScriptFrontendController
‪getTypoScriptFrontendController()
Definition: AbstractMenuContentObject.php:1753
‪TYPO3\CMS\Frontend\ContentObject\Menu
Definition: AbstractMenuContentObject.php:16
‪TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject\setATagParts
‪setATagParts(?LinkResultInterface $linkResult)
Definition: AbstractMenuContentObject.php:1527
‪TYPO3\CMS\Core\TypoScript\TypoScriptService
Definition: TypoScriptService.php:27
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Frontend\ContentObject\Menu\TextMenuContentObject\getBeforeAfter
‪string getBeforeAfter(string $pref, ContentObjectRenderer $cObjectForCurrentMenu)
Definition: TextMenuContentObject.php:156
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Frontend\ContentObject\Menu\TextMenuContentObject\writeMenu
‪string writeMenu()
Definition: TextMenuContentObject.php:34