TYPO3  7.6
styled_content/Classes/ViewHelpers/Menu/SectionViewHelper.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\FluidStyledContent\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 
18 
48 {
49  use MenuViewHelperTrait;
50 
56  public function initializeArguments()
57  {
58  $this->registerArgument('as', 'string', 'Name of the template variable that will contain selected pages', true);
59  $this->registerArgument('column', 'integer', 'Column number (colPos) from which to select content', false, 0);
60  $this->registerArgument('pageUid', 'integer', 'UID of page containing section-objects; defaults to current page', false, null);
61  $this->registerArgument('type', 'string', 'Search method when selecting indices from page', false, '');
62  }
63 
69  public function render()
70  {
71  $as = (string)$this->arguments['as'];
72  $pageUid = (int)$this->arguments['pageUid'];
73  $type = (string)$this->arguments['type'];
74 
75  if (empty($pageUid)) {
76  $pageUid = $this->getTypoScriptFrontendController()->id;
77  }
78 
79  if (!empty($type) && !in_array($type, array('all', 'header'), true)) {
80  return '';
81  }
82 
83  return $this->renderChildrenWithVariables(array(
84  $as => $this->findBySection($pageUid, $type, (int)$this->arguments['column'])
85  ));
86  }
87 
105  protected function findBySection($pageUid, $type = '', $column = 0)
106  {
107  $constraints = array(
108  'colPos = ' . (int)$column
109  );
110 
111  switch ($type) {
112  case 'all':
113  break;
114  case 'header':
115  $constraints[] = 'sectionIndex = 1';
116  $constraints[] = 'header <> \'\'';
117  $constraints[] = 'header_layout <> 100';
118  break;
119  default:
120  $constraints[] = 'sectionIndex = 1';
121  }
122 
123  $whereStatement = implode(' AND ', $constraints);
124 
125  $contentElements = $this->getTypoScriptFrontendController()->cObj->getRecords('tt_content', [
126  'where' => $whereStatement,
127  'orderBy' => 'sorting',
128  'languageField = sys_language_uid',
129  'pidInList' => (int)$pageUid
130  ]);
131 
132  return $contentElements;
133  }
134 }