/
BooleanField.php
43 lines (32 loc) · 1.13 KB
/
BooleanField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Concrete\Core\Command\Task\Input\Definition;
use Concrete\Core\Command\Task\Input\Field as LoadedField;
use Concrete\Core\Command\Task\Input\FieldInterface as LoadedFieldInterface;
use Concrete\Core\Console\Command\TaskCommand;
use Symfony\Component\Console\Input\InputOption;
defined('C5_EXECUTE') or die("Access Denied.");
class BooleanField extends Field
{
public function __construct(string $key, string $label, string $description)
{
parent::__construct($key, $label, $description, false);
}
public function addToCommand(TaskCommand $command)
{
$command->addOption($this->getKey(), null, InputOption::VALUE_NONE, $this->getDescription());
}
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
$data = parent::jsonSerialize();
$data['type'] = FieldInterface::FIELD_TYPE_BOOLEAN;
return $data;
}
public function loadFieldFromRequest(array $data): ?LoadedFieldInterface
{
if ($data[$this->getKey()] === '1') {
return new LoadedField($this->getKey(), $data[$this->getKey()]);
}
return null;
}
}