You are here

function external_active in External New Tab 8

Same name and namespace in other branches
  1. 6 external.module \external_active()
  2. 7 external.module \external_active()

Determine if the module is active for the page being viewed.

1 call to external_active()
external_page_attachments in ./external.module
Implements hook_page_attachments().

File

./external.module, line 33

Code

function external_active() {
  $current_path = \Drupal::service('path.current')
    ->getPath();
  $path = \Drupal::service('path.alias_manager')
    ->getAliasByPath($current_path);
  $patterns = \Drupal::config('external.settings')
    ->get('external_disabled_patterns');
  $front_page = \Drupal::configFactory()
    ->getEditable('system.site')
    ->get('page.front');
  $regexp = '/^(' . preg_replace(array(
    '/(\\r\\n?|\\n)/',
    '/\\\\\\*/',
    '/(^|\\|)\\\\<front\\\\>($|\\|)/',
  ), array(
    '|',
    '.*',
    '\\1' . preg_quote($front_page, '/') . '\\2',
  ), preg_quote($patterns, '/')) . ')$/';

  // Compare with the internal and path alias (if any).
  $page_match = preg_match($regexp, $path);
  if ($path != $current_path) {
    $page_match = $page_match || preg_match($regexp, $current_path);
  }
  return !$page_match;
}