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

Cleans a CSS identifier, taking into account views tokenization.

Parameters

string $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 2301
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.
    $substrings = preg_split('/(\[[^\]]*])/i', $class, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    foreach ($substrings as &$substring) {
      $tokenized = $plugin->tokenize_value($substring, $row_index);
      if ($tokenized == $substring) {
        // No token replacement, keep entered string as it is.
        $substring = $tokenized;
      }
      else {
        // Tokens that are replaced should be additionally sanitized, such
        // as replacing underscores with hyphens.
        // To avoid unexpected replacement at the start of this substring, we
        // prefix two hyphens and remove them again.
        $substring = substr(backdrop_clean_css_identifier('--' . $tokenized), 2);
      }
    }
    // Merge strings into class identifier.
    $class = implode('', $substrings);
    // Return cleaned identifier, all valid CSS characters allowed.
    return backdrop_clean_css_identifier($class, array());
  }
}