public static function BreakpointFormTrait::breakpointFormValidate in Doubleclick for Publishers (DFP) 8
Validation function used by an individual breakpoint.
File
- src/
Form/ BreakpointFormTrait.php, line 20  - Contains \Drupal\dfp\Form\BreakpointFormTrait.
 
Class
- BreakpointFormTrait
 - Provides form for adding breakpoints to a DFP tag.
 
Namespace
Drupal\dfp\FormCode
public static function breakpointFormValidate(array $element, FormStateInterface &$form_state) {
  if (empty($element['browser_size']['#value']) && !empty($element['ad_sizes']['#value'])) {
    $form_state
      ->setError($element['browser_size'], t('The browser size cannot be empty if ad size(s) exists.'));
  }
  elseif (!empty($element['browser_size']['#value']) && empty($element['ad_sizes']['#value'])) {
    $form_state
      ->setError($element['ad_sizes'], t('The ad size(s) cannot be empty if a browser size exists. If you wish to suppress an ad slot for a given browser size, you can enter "@none" in the ad size(s) field.', array(
      '@none' => '<none>',
    )));
  }
  if (!empty($element['browser_size']['#value']) && !empty($element['ad_sizes']['#value'])) {
    if (preg_match('/[^x|0-9]/', $element['browser_size']['#value'])) {
      $form_state
        ->setError($element['browser_size'], t('The browser size can only contain numbers and the character x.'));
    }
    elseif ($element['ad_sizes']['#value'] != '<none>' && preg_match('/[^x|,|0-9]/', $element['ad_sizes']['#value'])) {
      $form_state
        ->setError($element['ad_sizes'], t('The ad size(s) string can only contain numbers, the character x and commas (unless it is the special keyword "@none").', array(
        '@none' => '<none>',
      )));
    }
  }
}