You are here

public static function ReflectImageEffect::validateColor in ImageCache Reflect 8

Validates to ensure a hexadecimal color value or empty.

@todo Use drupal 8 validation API? Symfony has regex validator.

File

lib/Drupal/imagecache_reflect/Plugin/ImageEffect/ReflectImageEffect.php, line 118
Contains \Drupal\imagecache_reflect\Plugin\ImageEffect\ReflectImageEffect.

Class

ReflectImageEffect
Creates a reflection-like effect on an image resource.

Namespace

Drupal\imagecache_reflect\Plugin\ImageEffect

Code

public static function validateColor(array $element, array &$form_state) {
  if (!preg_match('/^#[0-9A-F]{3}([0-9A-F]{3})?$|^$/', $element['#value'])) {
    \Drupal::formBuilder()
      ->setError($element, \t('!name must be a hexadecimal color value or empty.', array(
      '!name' => $element['#title'],
    )));
  }
}