[TASK] EXT:form - make 'grid rows' independent from 'grid containers'
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Model / FormElements / GridRow.php
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
18 use TYPO3\CMS\Form\Domain\Exception\TypeDefinitionNotValidException;
19
20 /**
21 * A grid row, being part of a grid container
22 *
23 * This class contains multiple FormElements ({@link FormElementInterface}).
24 *
25 * Please see {@link FormDefinition} for an in-depth explanation.
26 *
27 * Scope: frontend
28 * **This class is NOT meant to be sub classed by developers.**
29 */
30 class GridRow extends Section implements GridRowInterface
31 {
32
33 /**
34 * Add a new form element at the end of the grid row
35 *
36 * @param FormElementInterface $formElement The form element to add
37 * @return void
38 * @throws TypeDefinitionNotValidException if FormElement is already added to a section
39 * @api
40 */
41 public function addElement(FormElementInterface $formElement)
42 {
43 if ($formElement instanceof GridContainerInterface) {
44 throw new TypeDefinitionNotValidException(
45 sprintf('Grid containers ("%s") within grid rows ("%s") are not allowed.', $formElement->getIdentifier(), $this->getIdentifier()),
46 1489413379
47 );
48 }
49
50 $this->addRenderable($formElement);
51 }
52
53 /**
54 * Create a form element with the given $identifier and attach it to this container.
55 *
56 * @param string $identifier Identifier of the new form element
57 * @param string $typeName type of the new form element
58 * @return GridRowInterface the newly created frid row
59 * @throws TypeDefinitionNotValidException
60 * @api
61 */
62 public function createElement(string $identifier, string $typeName): FormElementInterface
63 {
64 $element = parent::createElement($identifier, $typeName);
65
66 if ($element instanceof GridContainerInterface) {
67 throw new TypeDefinitionNotValidException(
68 sprintf('Grid containers ("%s") within grid rows ("%s") are not allowed.', $element->getIdentifier(), $this->getIdentifier()),
69 1489413538
70 );
71 }
72
73 return $element;
74 }
75 }