*/ protected $attributes = [ 'type' => 'color', ]; /** @var null|ValidatorInterface */ protected $validator; /** * Get validator */ protected function getValidator(): ValidatorInterface { if (null === $this->validator) { $this->validator = new RegexValidator('/^#[0-9a-fA-F]{6}$/'); } return $this->validator; } /** * Provide default input rules for this element * * Attaches a color validator. * * @inheritDoc */ public function getInputSpecification(): array { $spec = [ 'required' => true, 'filters' => [ ['name' => StringTrim::class], ['name' => StringToLower::class], ], 'validators' => [ $this->getValidator(), ], ]; $name = $this->getName(); if ($name !== null) { $spec['name'] = $name; } return $spec; } }