You are here

function views_dependent_filters_recreate_html_id in Views Dependent Filters 8

Same name and namespace in other branches
  1. 7 views_dependent_filters.module \views_dependent_filters_recreate_html_id()

Convert a string to an HTML id matching one made with drupal_html_id().

We can't simply call drupal_html_id() because that only returns unique ids; this is intended for when the ID already exists and we want to recreate it from the original input.

File

./views_dependent_filter.module, line 48
views_dependent_filters.module Provides a Views exposed filter which makes other filters depend on values in yet further filters for their visiblity and processing. For example: if the 'node type' filter is set to 'article', show a…

Code

function views_dependent_filters_recreate_html_id($id) {
  $id = strtr(Unicode::strtolower($id), array(
    ' ' => '-',
    '_' => '-',
    '[' => '-',
    ']' => '',
  ));

  // As defined in http://www.w3.org/TR/html4/types.html#type-name, HTML IDs can
  // only contain letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
  // colons (":"), and periods ("."). We strip out any character not in that
  // list. Note that the CSS spec doesn't allow colons or periods in identifiers
  // (http://www.w3.org/TR/CSS21/syndata.html#characters), so we strip those two
  // characters as well.
  $id = preg_replace('/[^A-Za-z0-9\\-_]/', '', $id);

  // Removing multiple consecutive hyphens.
  $id = preg_replace('/\\-+/', '-', $id);
  return $id;
}