You are here

function _title_validate_class in Title 7

Validate the list of values.

Validate that a space-separated list of values are lowercase and appropriate for use as HTML classes.

See also

title_field_formatter_settings_form()

1 string reference to '_title_validate_class'
title_field_formatter_settings_form in ./title.field.inc
Implements hook_field_formatter_settings_form().

File

./title.field.inc, line 198
Implement a title field formater.

Code

function _title_validate_class($element, &$form_state) {
  static $validated_class = array();
  $value = drupal_array_get_nested_value($form_state['values'], $element['#parents']);
  $classes = explode(' ', $value);
  foreach ($classes as $class) {
    if (!isset($validated_class[$class])) {

      // Using drupal_clean_css_identifier() directly to allow a double
      // underscore in addition to core defaults.
      // @see: https://www.drupal.org/node/2009584.
      $validated_class[$class] = drupal_clean_css_identifier(drupal_strtolower($class), array(
        ' ' => '-',
        '__' => '__',
        '_' => '-',
        '/' => '-',
        '[' => '-',
        ']' => '',
      ));
    }
    if ($class !== $validated_class[$class]) {
      form_error($element, t('Wrapper classes contain illegal characters; classes should be lowercase and may contain letters, numbers, dashes and double underscores.'));
      return;
    }
  }
}