[FOLLOWUP][TASK] EXT:form - change signal slots to hooks
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / Domain / Factory / AbstractFormFactory.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\Domain\Factory;
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
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Object\ObjectManager;
22 use TYPO3\CMS\Form\Domain\Model\FormDefinition;
23
24 /**
25 * Base class for custom *Form Factories*. A Form Factory is responsible for building
26 * a {@link TYPO3\CMS\Form\Domain\Model\FormDefinition}.
27 *
28 * {@inheritDoc}
29 *
30 * Example
31 * =======
32 *
33 * Generally, you should use this class as follows:
34 *
35 * <pre>
36 * class MyFooBarFactory extends AbstractFormFactory {
37 * public function build(array $configuration, $prototypeName) {
38 * $configurationService = GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationService::class);
39 * $prototypeConfiguration = $configurationService->getPrototypeConfiguration($prototypeName);
40 * $formDefinition = GeneralUtility::makeInstance(ObjectManager::class)->get(FormDefinition::class, 'nameOfMyForm', $prototypeConfiguration);
41 *
42 * // now, you should call methods on $formDefinition to add pages and form elements
43 *
44 * return $formDefinition;
45 * }
46 * }
47 * </pre>
48 *
49 * Scope: frontend / backend
50 * **This class is meant to be sub classed by developers.**
51 * @api
52 */
53 abstract class AbstractFormFactory implements FormFactoryInterface
54 {
55 /**
56 * Helper to be called by every AbstractFormFactory after everything has been built to call the "afterBuildingFinished"
57 * hook on all form elements.
58 *
59 * @param FormDefinition $form
60 * @return void
61 * @api
62 */
63 protected function triggerFormBuildingFinished(FormDefinition $form)
64 {
65 foreach ($form->getRenderablesRecursively() as $renderable) {
66 GeneralUtility::deprecationLog('EXT:form - calls for "onBuildingFinished" are deprecated since TYPO3 v8 and will be removed in TYPO3 v9');
67 $renderable->onBuildingFinished();
68
69 if (
70 isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished'])
71 && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished'])
72 ) {
73 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['afterBuildingFinished'] as $className) {
74 $hookObj = GeneralUtility::makeInstance($className);
75 if (method_exists($hookObj, 'afterBuildingFinished')) {
76 $hookObj->afterBuildingFinished(
77 $renderable
78 );
79 }
80 }
81 }
82 }
83 }
84 }