TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CategoriesViewHelper.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 
19 
39 {
45  protected $escapeOutput = false;
46 
52  public function initializeArguments()
53  {
54  $this->registerArgument('categoryUids', 'array', 'The categories assigned', true);
55  $this->registerArgument('as', 'string', 'Name of the template variable that will contain resolved pages', true);
56  $this->registerArgument('relationField', 'string', 'The category field for MM relation table', true);
57  $this->registerArgument('table', 'string', 'The table to which categories are assigned (source table)', true);
58  }
59 
65  public function render()
66  {
67  $categoryUids = (array)$this->arguments['categoryUids'];
68  $as = (string)$this->arguments['as'];
69  if (empty($categoryUids)) {
70  return '';
71  }
72 
73  return $this->renderChildrenWithVariables([
74  $as => $this->findByCategories($categoryUids, $this->arguments['relationField'], $this->arguments['table'])
75  ]);
76  }
77 
87  protected function findByCategories($categoryUids, $relationField, $tableName = 'pages')
88  {
89  $result = [];
90 
91  foreach ($categoryUids as $categoryUid) {
92  try {
93  $collection = CategoryCollection::load(
94  $categoryUid,
95  true,
96  $tableName,
97  $relationField
98  );
99  if ($collection->count() > 0) {
100  foreach ($collection as $record) {
101  $result[$record['uid']] = $record;
102  }
103  }
104  } catch (\RuntimeException $e) {
105  throw new Exception($e->getMessage(), 1476122186);
106  }
107  }
108 
109  return $result;
110  }
111 }
findByCategories($categoryUids, $relationField, $tableName= 'pages')