You are here

public function IsotopeController::sanitize in Isotope (with Masonry and Packery) 8

Strip all special chars to make value suitable for css class name.

Parameters

string|array $raw: The raw value to be sanitized. Arrays will be imploded by space.

Return value

string The sanitized value.

2 calls to IsotopeController::sanitize()
template_preprocess_isotope_filter in ./isotope.theme.inc
Prepares variables for isotope filter template.
template_preprocess_isotope_grid in ./isotope.theme.inc
Prepares variables for isotope grid template.

File

src/Controller/IsotopeController.php, line 97
Contains \Drupal\isotope\Controller\IsotopeController.

Class

IsotopeController
Controller routines for admin block routes.

Namespace

Drupal\isotope\Controller

Code

public function sanitize($raw) {
  $safe = $raw;

  // Recursively sanitize arrays.
  if (is_array($raw)) {
    $safe = [];
    foreach ($raw as $i) {
      $safe[] = $this
        ->sanitize($i);
    }
    return implode(' ', $safe);
  }

  // Transliterate non-latin characters.
  // @TODO: Using services means stop using static.
  $language_code = $this->languageManager
    ->getDefaultLanguage()
    ->getId();
  $safe = $this->transliteration
    ->transliterate($safe, $language_code);

  // Basic class-name rules.
  $safe = strtolower($safe);
  $safe = preg_replace('/[^a-z0-9]/s', '-', $safe);
  $safe = preg_replace('/-{2,}/', '-', $safe);
  return $safe;
}