2 namespace wcf\system\form\builder\field\devtools\project;
3 use wcf\data\package\Package;
4 use wcf\system\form\builder\field\AbstractFormField;
5 use wcf\system\form\builder\field\TDefaultIdFormField;
8 * Form field implementation for the excluded packages of a devtools project.
10 * @author Matthias Schmidt
11 * @copyright 2001-2018 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\System\Form\Builder\Field\Devtools\Project
16 class DevtoolsProjectExcludedPackagesFormField extends AbstractFormField {
17 use TDefaultIdFormField;
22 protected $templateName = '__devtoolsProjectExcludedPackagesFormField';
27 protected $__value = [];
32 public function readValue() {
33 if ($this->getDocument()->hasRequestData($this->getPrefixedId()) && is_array($this->getDocument()->getRequestData($this->getPrefixedId()))) {
34 $this->__value = $this->getDocument()->getRequestData($this->getPrefixedId());
44 public function validate() {
45 // everything is already validated by JavaScript thus we skip
46 // reporting specific errors and simply remove manipulated values
47 $excludedPackages = [];
48 $packageIdentifiers = [];
49 foreach ($this->getValue() as $package) {
50 // ensure that all relevant elements are present
51 if (!is_array($package) || !isset($package['packageIdentifier']) || !isset($package['version'])) {
55 // validate package identifier
56 if (!Package::isValidPackageName($package['packageIdentifier']) || in_array($package['packageIdentifier'], $packageIdentifiers)) {
61 if ($package['version'] !== '' && !Package::isValidVersion($package['version'])) {
65 $excludedPackages[] = $package;
68 $this->value($excludedPackages);
74 protected static function getDefaultId() {
75 return 'excludedPackages';