3 namespace wcf\system\form\builder\field\devtools\project;
5 use wcf\data\package\Package;
6 use wcf\system\form\builder\field\AbstractFormField;
7 use wcf\system\form\builder\field\TDefaultIdFormField;
10 * Form field implementation for the optional packages of a devtools project.
12 * @author Matthias Schmidt
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Form\Builder\Field\Devtools\Project
18 class DevtoolsProjectOptionalPackagesFormField extends AbstractFormField
20 use TDefaultIdFormField;
25 protected $templateName = '__devtoolsProjectOptionalPackagesFormField';
30 protected $value = [];
35 public function readValue()
38 $this->getDocument()->hasRequestData($this->getPrefixedId())
39 && \is_array($this->getDocument()->getRequestData($this->getPrefixedId()))
41 $this->value = $this->getDocument()->getRequestData($this->getPrefixedId());
50 public function validate()
52 // everything is already validated by JavaScript thus we skip
53 // reporting specific errors and simply remove manipulated values
54 $excludedPackages = [];
55 $packageIdentifiers = [];
56 foreach ($this->getValue() as $package) {
57 // ensure that all relevant elements are present
58 if (!\is_array($package) || !isset($package['packageIdentifier'])) {
62 // validate package identifier
64 !Package::isValidPackageName($package['packageIdentifier'])
65 || \in_array($package['packageIdentifier'], $packageIdentifiers)
70 $excludedPackages[] = $package;
73 $this->value($excludedPackages);
79 protected static function getDefaultId()
81 return 'optionalPackages';