TYPO3 CMS  TYPO3_8-7
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 
28 
41 {
42 
51  public function __construct(string $identifier, string $type)
52  {
53  if (!is_string($identifier) || strlen($identifier) === 0) {
54  throw new IdentifierNotValidException('The given identifier was not a string or the string was empty.', 1477082501);
55  }
56 
57  $this->identifier = $identifier;
58  $this->type = $type;
59  }
60 
67  public function getElements(): array
68  {
69  return $this->renderables;
70  }
71 
78  public function getElementsRecursively(): array
79  {
80  return $this->getRenderablesRecursively();
81  }
82 
90  public function addElement(FormElementInterface $formElement)
91  {
92  $this->addRenderable($formElement);
93  }
94 
111  public function createElement(string $identifier, string $typeName): FormElementInterface
112  {
113  $formDefinition = $this->getRootForm();
114 
115  $typeDefinitions = $formDefinition->getTypeDefinitions();
116  if (isset($typeDefinitions[$typeName])) {
117  $typeDefinition = $typeDefinitions[$typeName];
118  } else {
119  $renderingOptions = $formDefinition->getRenderingOptions();
120  $skipUnknownElements = isset($renderingOptions['skipUnknownElements']) && $renderingOptions['skipUnknownElements'] === true;
121  if (!$skipUnknownElements) {
122  throw new TypeDefinitionNotFoundException(sprintf('Type "%s" not found. Probably some configuration is missing.', $typeName), 1382364019);
123  }
124 
125  $element = GeneralUtility::makeInstance(ObjectManager::class)
126  ->get(UnknownFormElement::class, $identifier, $typeName);
127  $this->addElement($element);
128  return $element;
129  }
130 
131  if (!isset($typeDefinition['implementationClassName'])) {
132  throw new TypeDefinitionNotFoundException(sprintf('The "implementationClassName" was not set in type definition "%s".', $typeName), 1325689855);
133  }
134 
135  $implementationClassName = $typeDefinition['implementationClassName'];
136  $element = GeneralUtility::makeInstance(ObjectManager::class)
137  ->get($implementationClassName, $identifier, $typeName);
138  if (!$element instanceof FormElementInterface) {
139  throw new TypeDefinitionNotValidException(sprintf('The "implementationClassName" for element "%s" ("%s") does not implement the FormElementInterface.', $identifier, $implementationClassName), 1327318156);
140  }
141  unset($typeDefinition['implementationClassName']);
142 
143  $this->addElement($element);
144  $element->setOptions($typeDefinition);
145 
146  $element->initializeFormElement();
147  return $element;
148  }
149 
159  public function moveElementBefore(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
160  {
161  $this->moveRenderableBefore($elementToMove, $referenceElement);
162  }
163 
173  public function moveElementAfter(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
174  {
175  $this->moveRenderableAfter($elementToMove, $referenceElement);
176  }
177 
184  public function removeElement(FormElementInterface $elementToRemove)
185  {
186  $this->removeRenderable($elementToRemove);
187  }
188 
200  public function onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments = [])
201  {
203  }
204 }
removeElement(FormElementInterface $elementToRemove)
moveRenderableAfter(RenderableInterface $renderableToMove, RenderableInterface $referenceRenderable)
moveRenderableBefore(RenderableInterface $renderableToMove, RenderableInterface $referenceRenderable)
static makeInstance($className,... $constructorArguments)
createElement(string $identifier, string $typeName)
moveElementAfter(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments=[])
moveElementBefore(FormElementInterface $elementToMove, FormElementInterface $referenceElement)