You are here

public function RgbColorDefinition::getPropertyDefinitions in Color API 8

Gets an array of property definitions of contained properties.

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An array of property definitions of contained properties, keyed by property name.

Overrides MapDataDefinition::getPropertyDefinitions

File

src/TypedData/Definition/RgbColorDefinition.php, line 16

Class

RgbColorDefinition
Definition class for Typed Data API RGB Color Complex Data types.

Namespace

Drupal\colorapi\TypedData\Definition

Code

public function getPropertyDefinitions() {
  if (!isset($this->propertyDefinitions)) {
    $this->propertyDefinitions['red'] = DataDefinition::create('integer')
      ->setLabel('Red')
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 255,
    ])
      ->setDescription('The red value of the RGB color')
      ->setRequired(TRUE);
    $this->propertyDefinitions['green'] = DataDefinition::create('integer')
      ->setLabel('Green')
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 255,
    ])
      ->setDescription('The red value of the RGB color')
      ->setRequired(TRUE);
    $this->propertyDefinitions['blue'] = DataDefinition::create('string')
      ->setLabel('Blue')
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 255,
    ])
      ->setDescription('The blue value of the RGB color')
      ->setRequired(TRUE);
  }
  return $this->propertyDefinitions;
}