50331c2e901064bdd0c56ed79c0f49685826e827
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\form\builder\field\data\processor;
3 use wcf\system\form\builder\IFormDocument;
4
5 /**
6 * Field data processor implementation that voids a certain data property.
7 *
8 * @author Matthias Schmidt
9 * @copyright 2001-2018 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package WoltLabSuite\Core\System\Form\Builder\Field\Data\Processor
12 * @since 3.2
13 */
14 class VoidFormFieldDataProcessor implements IFormFieldDataProcessor {
15 /**
16 * is `true` if the property is stored in the `data` array
17 * @var bool
18 */
19 protected $isDataProperty;
20
21 /**
22 * name of the voided property
23 * @var string
24 */
25 protected $property;
26
27 /**
28 * Initializes a new CustomFormFieldDataProcessor object.
29 *
30 * @param string $property name of the voided property
31 * @param bool $isDataProperty is `true` if the property is stored in the `data` array
32 */
33 public function __construct($property, $isDataProperty = true) {
34 $this->property = $property;
35 $this->isDataProperty = $isDataProperty;
36 }
37
38 /**
39 * @inheritDoc
40 */
41 public function __invoke(IFormDocument $document, array $parameters) {
42 if ($this->isDataProperty) {
43 if (isset($parameters['data'][$this->property])) {
44 unset($parameters['data'][$this->property]);
45 }
46 }
47 else if (isset($parameters[$this->property])) {
48 unset($parameters[$this->property]);
49 }
50
51 return $parameters;
52 }
53 }