1 views.module _views_tokenized_clean_css_identifier($class, $plugin, $row_index)

Cleans a CSS identifier, taking into account views tokenization.

Parameters

sring $class: A single CSS class, as entered into the Views user interface.

object $plugin: The complete view plugin object for tokenization.

string $row_index: The index indicating the row of the view.

Return value

string $class: A sanitized clean css identifier with tokens replaced.

File

core/modules/views/views.module, line 2232
Primarily Backdrop hooks and global API functions to manipulate views.

Code

function _views_tokenized_clean_css_identifier($class, $plugin, $row_index) {
  if (!empty($class)) {
    // To support a class that is part hand-typed and part token, split out tokens.
    $subclasses = preg_split('/(\[[^\]]*])/i', $class, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    foreach ($subclasses as &$subclass) {
      $tokenized = $plugin->tokenize_value($subclass, $row_index);
      if ($tokenized == $subclass) {
        // No token replacement, all valid CSS characters allowed.
        $subclass = backdrop_clean_css_identifier($tokenized, array());
      }
      else {
        // Tokens that are replaced should be additionally sanitized, such
        // as replacing underscores with hyphens.
        $subclass = backdrop_clean_css_identifier($tokenized);
      }
      $class = implode('', $subclasses);
    }
    return $class;
  }
}