TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractSection.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Domain\Model\FormElements;
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 
26 
39 {
40 
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 
65  public function getElements(): array
66  {
67  return $this->renderables;
68  }
69 
76  public function getElementsRecursively(): array
77  {
78  return $this->getRenderablesRecursively();
79  }
80 
89  public function addElement(FormElementInterface $formElement)
90  {
91  $this->addRenderable($formElement);
92  }
93 
110  public function createElement(string $identifier, string $typeName): FormElementInterface
111  {
112  $formDefinition = $this->getRootForm();
113 
114  $typeDefinitions = $formDefinition->getTypeDefinitions();
115  if (isset($typeDefinitions[$typeName])) {
116  $typeDefinition = $typeDefinitions[$typeName];
117  } else {
118  $element = GeneralUtility::makeInstance(ObjectManager::class)
119  ->get(UnknownFormElement::class, $identifier, $typeName);
120  $this->addElement($element);
121  return $element;
122  }
123 
124  if (!isset($typeDefinition['implementationClassName'])) {
125  throw new TypeDefinitionNotFoundException(sprintf('The "implementationClassName" was not set in type definition "%s".', $typeName), 1325689855);
126  }
127 
128  $implementationClassName = $typeDefinition['implementationClassName'];
129  $element = GeneralUtility::makeInstance(ObjectManager::class)
130  ->get($implementationClassName, $identifier, $typeName);
131  if (!$element instanceof FormElementInterface) {
132  throw new TypeDefinitionNotValidException(sprintf('The "implementationClassName" for element "%s" ("%s") does not implement the FormElementInterface.', $identifier, $implementationClassName), 1327318156);
133  }
134  unset($typeDefinition['implementationClassName']);
135 
136  $this->addElement($element);
137  $element->setOptions($typeDefinition);
138 
139  $element->initializeFormElement();
140  return $element;
141  }
142 
153  public function moveElementBefore(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
154  {
155  $this->moveRenderableBefore($elementToMove, $referenceElement);
156  }
157 
168  public function moveElementAfter(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
169  {
170  $this->moveRenderableAfter($elementToMove, $referenceElement);
171  }
172 
180  public function removeElement(FormElementInterface $elementToRemove)
181  {
182  $this->removeRenderable($elementToRemove);
183  }
184 
196  public function onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments = [])
197  {
198  }
199 }
moveElementAfter(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
removeElement(FormElementInterface $elementToRemove)
moveElementBefore(FormElementInterface $elementToMove, FormElementInterface $referenceElement)
moveRenderableBefore(RenderableInterface $renderableToMove, RenderableInterface $referenceRenderable)
createElement(string $identifier, string $typeName)
moveRenderableAfter(RenderableInterface $renderableToMove, RenderableInterface $referenceRenderable)
onSubmit(FormRuntime $formRuntime, &$elementValue, array $requestArguments=[])
static makeInstance($className,...$constructorArguments)