FormConfigDTO.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\DTO\Form; |
| 4 | |
| 5 | use Kirki\Framework\Sanitizer; |
| 6 | |
| 7 | defined('ABSPATH') || exit; |
| 8 | |
| 9 | use Kirki\Framework\DTO; |
| 10 | |
| 11 | class FormConfigDTO extends DTO |
| 12 | { |
| 13 | /** @var string The form element's builder id. */ |
| 14 | public $id; |
| 15 | |
| 16 | /** @var string Whether the form posts to this site ('default') or an external URL ('external'). Not used server-side. */ |
| 17 | public $type; |
| 18 | |
| 19 | /** @var string */ |
| 20 | public $name; |
| 21 | |
| 22 | /** @var array */ |
| 23 | public $fields = []; |
| 24 | |
| 25 | /** @var array */ |
| 26 | public $actions = []; |
| 27 | |
| 28 | /** @var array Client-side "what to show after submit" config. Not used server-side. */ |
| 29 | public $onSubmit = []; |
| 30 | |
| 31 | /** @var array */ |
| 32 | public $maxEntry = []; |
| 33 | |
| 34 | /** @var array */ |
| 35 | public $responseLimit = []; |
| 36 | |
| 37 | /** @var bool */ |
| 38 | public $saveData = false; |
| 39 | |
| 40 | public function __construct(array $data = []) |
| 41 | { |
| 42 | parent::__construct($data); |
| 43 | |
| 44 | $this->id = (string) $this->id; |
| 45 | $this->type = (string) $this->type; |
| 46 | $this->name = (string) $this->name; |
| 47 | $this->fields = is_array($this->fields) ? $this->fields : []; |
| 48 | $this->actions = is_array($this->actions) ? $this->actions : []; |
| 49 | $this->onSubmit = is_array($this->onSubmit) ? $this->onSubmit : []; |
| 50 | $this->maxEntry = is_array($this->maxEntry) ? $this->maxEntry : []; |
| 51 | $this->responseLimit = is_array($this->responseLimit) ? $this->responseLimit : []; |
| 52 | $this->saveData = Sanitizer::apply_rule($this->saveData, Sanitizer::BOOL); |
| 53 | } |
| 54 | } |
| 55 |