558d6edcd5ed628efebee062b3e81b98c2a011ba
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\form\builder\field\data\processor;
3 use wcf\system\form\builder\field\IFormField;
4 use wcf\system\form\builder\IFormDocument;
5 use wcf\system\form\builder\IFormNode;
6 use wcf\system\form\builder\IFormParentNode;
7
8 /**
9 * Default field data processor that maps the form fields to entries in
10 * the `data` sub-array with the field ids as array keys and field values
11 * as array values.
12 *
13 * @author Matthias Schmidt
14 * @copyright 2001-2018 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Form\Builder\Field\Data\Processor
17 * @since 5.2
18 */
19 class DefaultFormFieldDataProcessor implements IFormFieldDataProcessor {
20 /**
21 * @inheritDoc
22 */
23 public function __invoke(IFormDocument $document, array $parameters) {
24 $parameters['data'] = [];
25
26 $this->getData($document, $parameters['data']);
27
28 return $parameters;
29 }
30
31 /**
32 * Fetches all data from the given node and stores it in the given array.
33 *
34 * @param IFormNode $node node whose data will be fetched
35 * @param array $data data storage
36 */
37 protected function getData(IFormNode $node, array &$data) {
38 if ($node->checkDependencies()) {
39 if ($node instanceof IFormParentNode) {
40 foreach ($node as $childNode) {
41 $this->getData($childNode, $data);
42 }
43 }
44 else if ($node instanceof IFormField && $node->isAvailable() && $node->hasSaveValue()) {
45 $data[$node->getObjectProperty()] = $node->getSaveValue();
46 }
47 }
48 }
49 }