‪TYPO3CMS  ‪main
FieldInformation.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
33 {
34  public function ‪__construct(
35  private readonly ‪NodeFactory $nodeFactory,
36  private readonly ‪DependencyOrderingService $dependencyOrderingService,
37  ) {}
38 
46  public function ‪render(): array
47  {
48  $result = $this->‪initializeResultArray();
49  if (!isset($this->data['renderData']['fieldInformation'])) {
50  return $result;
51  }
52 
53  $fieldInformation = $this->data['renderData']['fieldInformation'];
54  $orderedFieldInformation = $this->dependencyOrderingService->orderByDependencies($fieldInformation);
55 
56  foreach ($orderedFieldInformation as $anOrderedFieldInformation => $orderedFieldInformationConfiguration) {
57  if (isset($orderedFieldInformationConfiguration['disabled']) && $orderedFieldInformationConfiguration['disabled']
58  || !isset($fieldInformation[$anOrderedFieldInformation]['renderType'])
59  ) {
60  // Don't consider this control if disabled.
61  // Also ignore if renderType is not given.
62  // Missing renderType may happen if an element registers a default field control
63  // as disabled, and TCA enabled that. If then additionally for instance the
64  // element renderType is changed to an element that doesn't register the control
65  // by default anymore, this would then fatal if we don't continue here.
66  // @todo: the above scenario indicates a small configuration flaw, maybe log an error somewhere?
67  continue;
68  }
69 
70  $options = ‪$this->data;
71  $options['renderType'] = $fieldInformation[$anOrderedFieldInformation]['renderType'];
72  $options['renderData']['fieldInformationOptions'] = $orderedFieldInformationConfiguration['options'] ?? [];
73  $informationResult = $this->nodeFactory->create($options)->render();
74 
75  $allowedTags = '<a><br><br/><div><em><i><p><strong><span><code>';
76  if (strip_tags($informationResult['html'], $allowedTags) !== $informationResult['html']) {
77  throw new \RuntimeException(
78  'The field information API supports only a limited number of HTML tags within the result'
79  . ' HTML of children. Allowed tags are: "' . $allowedTags . '" Child'
80  . ' ' . $options['renderType'] . ' violated this rule. Either remove offending tags or'
81  . ' switch to a different API like "fieldWizard" or "fieldControl".',
82  1485084419
83  );
84  }
85 
86  $result = $this->‪mergeChildReturnIntoExistingResult($result, $informationResult);
87  }
88  return $result;
89  }
90 }
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldInformation
Definition: FieldInformation.php:33
‪TYPO3\CMS\Backend\Form\AbstractNode\mergeChildReturnIntoExistingResult
‪array mergeChildReturnIntoExistingResult(array $existing, array $childReturn, bool $mergeHtml=true)
Definition: AbstractNode.php:104
‪TYPO3\CMS\Backend\Form\AbstractNode\$data
‪array $data
Definition: AbstractNode.php:35
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Backend\Form\NodeExpansion
Definition: FieldControl.php:18
‪TYPO3\CMS\Backend\Form\NodeFactory
Definition: NodeFactory.php:40
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldInformation\__construct
‪__construct(private readonly NodeFactory $nodeFactory, private readonly DependencyOrderingService $dependencyOrderingService,)
Definition: FieldInformation.php:34
‪TYPO3\CMS\Backend\Form\AbstractNode
Definition: AbstractNode.php:29
‪TYPO3\CMS\Backend\Form\NodeExpansion\FieldInformation\render
‪array render()
Definition: FieldInformation.php:46
‪TYPO3\CMS\Backend\Form\AbstractNode\initializeResultArray
‪initializeResultArray()
Definition: AbstractNode.php:77