You are here

function juicebox_element_validate_config in Juicebox HTML5 Responsive Image Galleries 8.2

Same name and namespace in other branches
  1. 8.3 juicebox.module \juicebox_element_validate_config()
  2. 7.2 juicebox.module \juicebox_element_validate_config()

Form validation callback: validate Juicebox configuration options.

1 string reference to 'juicebox_element_validate_config'
JuiceboxFormatter::confBaseForm in src/JuiceboxFormatter.php
Get common elements for Juicebox configuration forms.

File

./juicebox.module, line 185
Module file for Juicebox.

Code

function juicebox_element_validate_config($element, FormStateInterface $form_state, $form) {

  // We are looking for input in the format of: optionName="optionValue".
  // The check here is not too strict, it is just meant to catch general
  // formatting issues.
  $custom_options = explode("\n", $element['#value']);
  foreach ($custom_options as $key => $option) {
    $option = trim($option);
    $line_number = $key + 1;
    if (!empty($option) && !preg_match('/^[A-Za-z0-9]+?="[^"]+?"$/u', $option)) {
      $form_state
        ->setError($element, t('One of your manual configuration options appears to be formatted incorrectly. Please check line @line of this field and ensure that you are using the format <strong>optionName="optionValue"</strong> and that all spaces have been removed.', [
        '@line' => $line_number,
      ]));
    }
  }
}