You are here

function _facetapi_html_id in Facet API 6.3

1 call to _facetapi_html_id()
FacetapiWidgetLinks::buildListItems in plugins/facetapi/widget_links.inc
Recursive function that converts the render array into an array that can be passed to theme_item_list().

File

./facetapi.module, line 1334
An abstracted facet API that can be used by various search backends.

Code

function _facetapi_html_id($id) {
  $id_counter =& ctools_static(__FUNCTION__, array());
  $id = strtr(drupal_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);
  if (isset($id_counter[$id])) {
    $id_counter[$id]++;
  }
  else {
    $id_counter[$id] = 0;
  }
  $id .= '-' . $id_counter[$id];
  return $id;
}