[!!!][FEATURE] Streamline Fluid Styled Content and CSS Styled Content
[Packages/TYPO3.CMS.git] / typo3 / sysext / compatibility7 / Classes / ViewHelpers / Menu / SectionViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Compatibility7\ViewHelpers\Menu;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * A view helper which returns content elements with 'Show in Section Menus' enabled
21 *
22 * By default only content in colPos=0 will be found. This can be overruled by using "column"
23 *
24 * If you set property "type" to 'all', then the 'Show in Section Menus' checkbox is not considered
25 * and all content elements are selected.
26 *
27 * If the property "type" is 'header' then only content elements with a visible header layout
28 * (and a non-empty 'header' field!) are selected.
29 * In other words, if the header layout of an element is set to 'Hidden' then the element will not be in the results.
30 *
31 * = Example =
32 *
33 * <code title="Content elements in page with uid = 1 and 'Show in Section Menu's' enabled">
34 * <ce:menu.section pageUid="1" as="contentElements">
35 * <f:for each="{contentElements}" as="contentElement">
36 * {contentElement.header}
37 * </f:for>
38 * </ce:menu.section>
39 * </code>
40 *
41 * <output>
42 * Content element 1 in page with uid = 1 and "Show in section menu's" enabled
43 * Content element 2 in page with uid = 1 and "Show in section menu's" enabled
44 * Content element 3 in page with uid = 1 and "Show in section menu's" enabled
45 * </output>
46 */
47 class SectionViewHelper extends AbstractMenuViewHelper
48 {
49 /**
50 * Output escaping is disabled as child content contains HTML by default
51 *
52 * @var bool
53 */
54 protected $escapeOutput = false;
55
56 /**
57 * Initialize ViewHelper arguments
58 *
59 * @return void
60 */
61 public function initializeArguments()
62 {
63 $this->registerArgument('as', 'string', 'Name of the template variable that will contain selected pages', true);
64 $this->registerArgument('column', 'string', 'Column numbers (colPos) from which to select content', false, '0');
65 $this->registerArgument('pageUid', 'integer', 'UID of page containing section-objects; defaults to current page', false, null);
66 $this->registerArgument('type', 'string', 'Search method when selecting indices from page', false, '');
67 }
68
69 /**
70 * Render the view helper
71 *
72 * @return string
73 */
74 public function render()
75 {
76 $as = (string)$this->arguments['as'];
77 $pageUid = (int)$this->arguments['pageUid'];
78 $type = (string)$this->arguments['type'];
79
80 if (empty($pageUid)) {
81 $pageUid = $this->getTypoScriptFrontendController()->id;
82 }
83
84 if (!empty($type) && !in_array($type, ['all', 'header'], true)) {
85 return '';
86 }
87
88 return $this->renderChildrenWithVariables([
89 $as => $this->findBySection($pageUid, $type, $this->arguments['column'])
90 ]);
91 }
92
93 /**
94 * Find content with 'Show in Section Menus' enabled in a page
95 *
96 * By default only content in colPos=0 will be found. This can be overruled by using $column
97 *
98 * If you set property type to "all", then the 'Show in Section Menus' checkbox is not considered
99 * and all content elements are selected.
100 *
101 * If the property $type is 'header' then only content elements with a visible header layout
102 * (and a non-empty 'header' field!) is selected.
103 * In other words, if the header layout of an element is set to 'Hidden' then the page will not appear in the menu.
104 *
105 * @param int $pageUid The page uid
106 * @param string $type Search method
107 * @param string $column Restrict content by the column number
108 * @return array
109 */
110 protected function findBySection($pageUid, $type = '', $column = '')
111 {
112 $constraints = [];
113 if (trim($column) !== '') {
114 $colPosList = implode(',', GeneralUtility::intExplode(',', $column, true));
115 $constraints[] = 'colPos IN(' . ($colPosList !== '' ? $colPosList : '0') . ')';
116 }
117
118 switch ($type) {
119 case 'all':
120 break;
121 case 'header':
122 $constraints[] = 'sectionIndex = 1';
123 $constraints[] = 'header <> \'\'';
124 $constraints[] = 'header_layout <> 100';
125 break;
126 default:
127 $constraints[] = 'sectionIndex = 1';
128 }
129
130 $whereStatement = implode(' AND ', $constraints);
131
132 $contentElements = $this->getTypoScriptFrontendController()->cObj->getRecords('tt_content', [
133 'where' => $whereStatement,
134 'orderBy' => 'sorting',
135 'languageField' => 'sys_language_uid',
136 'pidInList' => (int)$pageUid
137 ]);
138
139 return $contentElements;
140 }
141 }