You are here

function _syntaxhighlighter_page_match in Syntax Highlighter 8

Same name and namespace in other branches
  1. 6.2 syntaxhighlighter.module \_syntaxhighlighter_page_match()
  2. 6 syntaxhighlighter.module \_syntaxhighlighter_page_match()
  3. 7.2 syntaxhighlighter.module \_syntaxhighlighter_page_match()
  4. 7 syntaxhighlighter.module \_syntaxhighlighter_page_match()

Page matching helper.

1 call to _syntaxhighlighter_page_match()
syntaxhighlighter_page_attachments in ./syntaxhighlighter.module
Implements hook_page_attachments().

File

./syntaxhighlighter.module, line 190
Syntax highlight code using the SyntaxHighlighter Javascript library.

Code

function _syntaxhighlighter_page_match() {
  $config = \Drupal::config('syntaxhighlighter.settings');
  $inject = $config
    ->get('inject');
  $pages = $config
    ->get('pages');
  if ($inject != SYNTAXHIGHLIGHTER_INJECT_PHP) {
    $current_path = \Drupal::service('path.current')
      ->getPath();
    $path_alias = Drupal::service('path.alias_manager')
      ->getAliasByPath($current_path);

    // Compare with the internal and path alias (if any).
    $page_match = \Drupal::service('path.matcher')
      ->matchPath($path_alias, $pages);
    if ($path_alias != $current_path) {
      $page_match = $page_match || \Drupal::service('path.matcher')
        ->matchPath($current_path, $pages);
    }
    return !($inject xor $page_match);
  }
  else {

    // If the PHP module is not enabled, we just return FALSE
    // which just ends up disabling the syntaxhighlighter.
    return function_exists('php_eval') && php_eval($pages);
  }
}