‪TYPO3CMS  9.5
AbstractSection.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
27 
40 {
41 
49  public function ‪__construct(string ‪$identifier, string ‪$type)
50  {
51  if (!is_string(‪$identifier) || strlen(‪$identifier) === 0) {
52  throw new ‪IdentifierNotValidException('The given identifier was not a string or the string was empty.', 1477082501);
53  }
54 
55  $this->identifier = ‪$identifier;
56  $this->type = ‪$type;
57  }
58 
64  public function ‪getElements(): array
65  {
66  return ‪$this->renderables;
67  }
68 
74  public function ‪getElementsRecursively(): array
75  {
76  return $this->‪getRenderablesRecursively();
77  }
78 
85  public function ‪addElement(‪FormElementInterface $formElement)
86  {
87  $this->‪addRenderable($formElement);
88  }
89 
105  public function ‪createElement(string ‪$identifier, string $typeName): ‪FormElementInterface
106  {
107  $formDefinition = $this->‪getRootForm();
108 
109  $typeDefinitions = $formDefinition->getTypeDefinitions();
110  if (isset($typeDefinitions[$typeName])) {
111  $typeDefinition = $typeDefinitions[$typeName];
112  } else {
113  ‪$renderingOptions = $formDefinition->getRenderingOptions();
114  $skipUnknownElements = isset(‪$renderingOptions['skipUnknownElements']) && ‪$renderingOptions['skipUnknownElements'] === true;
115  if (!$skipUnknownElements) {
116  throw new ‪TypeDefinitionNotFoundException(sprintf('Type "%s" not found. Probably some configuration is missing.', $typeName), 1382364019);
117  }
118 
119  $element = GeneralUtility::makeInstance(ObjectManager::class)
120  ->get(UnknownFormElement::class, ‪$identifier, $typeName);
121  $this->‪addElement($element);
122  return $element;
123  }
124 
125  if (!isset($typeDefinition['implementationClassName'])) {
126  throw new ‪TypeDefinitionNotFoundException(sprintf('The "implementationClassName" was not set in type definition "%s".', $typeName), 1325689855);
127  }
128 
129  $implementationClassName = $typeDefinition['implementationClassName'];
130  $element = GeneralUtility::makeInstance(ObjectManager::class)
131  ->get($implementationClassName, ‪$identifier, $typeName);
132  if (!$element instanceof ‪FormElementInterface) {
133  throw new ‪TypeDefinitionNotValidException(sprintf('The "implementationClassName" for element "%s" ("%s") does not implement the FormElementInterface.', ‪$identifier, $implementationClassName), 1327318156);
134  }
135  unset($typeDefinition['implementationClassName']);
136 
137  $this->‪addElement($element);
138  $element->setOptions($typeDefinition);
139 
140  $element->initializeFormElement();
141  return $element;
142  }
143 
152  public function ‪moveElementBefore(‪FormElementInterface $elementToMove, ‪FormElementInterface $referenceElement)
153  {
154  $this->‪moveRenderableBefore($elementToMove, $referenceElement);
155  }
156 
165  public function ‪moveElementAfter(‪FormElementInterface $elementToMove, ‪FormElementInterface $referenceElement)
166  {
167  $this->‪moveRenderableAfter($elementToMove, $referenceElement);
168  }
169 
175  public function ‪removeElement(‪FormElementInterface $elementToRemove)
176  {
177  $this->‪removeRenderable($elementToRemove);
178  }
179 }
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\getElementsRecursively
‪FormElementInterface[] getElementsRecursively()
Definition: AbstractSection.php:74
‪TYPO3\CMS\Form\Domain\Model\Exception\FormDefinitionConsistencyException
Definition: FormDefinitionConsistencyException.php:25
‪TYPO3\CMS\Form\Domain\Exception\TypeDefinitionNotFoundException
Definition: TypeDefinitionNotFoundException.php:27
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable
Definition: AbstractCompositeRenderable.php:30
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable\moveRenderableAfter
‪moveRenderableAfter(RenderableInterface $renderableToMove, RenderableInterface $referenceRenderable)
Definition: AbstractCompositeRenderable.php:105
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\addElement
‪addElement(FormElementInterface $formElement)
Definition: AbstractSection.php:85
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable\removeRenderable
‪removeRenderable(RenderableInterface $renderableToRemove)
Definition: AbstractCompositeRenderable.php:159
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:27
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable\moveRenderableBefore
‪moveRenderableBefore(RenderableInterface $renderableToMove, RenderableInterface $referenceRenderable)
Definition: AbstractCompositeRenderable.php:69
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable\getRenderablesRecursively
‪RenderableInterface[] getRenderablesRecursively()
Definition: AbstractCompositeRenderable.php:137
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\moveElementBefore
‪moveElementBefore(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
Definition: AbstractSection.php:152
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$type
‪string $type
Definition: AbstractRenderable.php:46
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$renderingOptions
‪array $renderingOptions
Definition: AbstractRenderable.php:70
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\getRootForm
‪FormDefinition getRootForm()
Definition: AbstractRenderable.php:313
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection
Definition: AbstractSection.php:40
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:36
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable\$renderables
‪TYPO3 CMS Form Domain Model Renderable RenderableInterface[] $renderables
Definition: AbstractCompositeRenderable.php:36
‪TYPO3\CMS\Form\Domain\Exception\TypeDefinitionNotValidException
Definition: TypeDefinitionNotValidException.php:27
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\createElement
‪FormElementInterface createElement(string $identifier, string $typeName)
Definition: AbstractSection.php:105
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\removeElement
‪removeElement(FormElementInterface $elementToRemove)
Definition: AbstractSection.php:175
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractRenderable\$identifier
‪string $identifier
Definition: AbstractRenderable.php:52
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\getElements
‪FormElementInterface[] getElements()
Definition: AbstractSection.php:64
‪TYPO3\CMS\Form\Domain\Model\Renderable\AbstractCompositeRenderable\addRenderable
‪addRenderable(RenderableInterface $renderable)
Definition: AbstractCompositeRenderable.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\moveElementAfter
‪moveElementAfter(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
Definition: AbstractSection.php:165
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection\__construct
‪__construct(string $identifier, string $type)
Definition: AbstractSection.php:49
‪TYPO3\CMS\Form\Domain\Model\FormElements
Definition: AbstractFormElement.php:3