You are here

public function Color::getRgb in Color API 8

Retrieve RGB value array of the Color Field Color data object.

Return value

array An array containing the following keys:

  • red: The value for the RGB "red". An integer between 0 and 255.
  • green: The value for the RGB "green". An integer between 0 and 255.
  • blue: The value for the RGB "blue". An integer between 0 and 255.

Overrides ColorInterface::getRgb

File

src/Entity/Color.php, line 73

Class

Color
The Color API Color entity definition.

Namespace

Drupal\colorapi\Entity

Code

public function getRgb() {
  if ($color = $this
    ->get('color')) {
    $service = \Drupal::service('colorapi.service');
    return [
      'red' => $service
        ->hexToRgb($color, 'red'),
      'green' => $service
        ->hexToRgb($color, 'green'),
      'blue' => $service
        ->hexToRgb($color, 'blue'),
    ];
  }
}