You are here

external.module in External New Tab 8

Same filename and directory in other branches
  1. 6 external.module
  2. 7 external.module

File

external.module
View source
<?php

// $Id$

/**
 * Implements hook_help().
 */
function external_help($path) {
  $output = '';
  switch ($path) {
    case "admin/help#external":
      $output = '<p>' . t("Opens external links and PDFs in new tabs with jQuery") . '</p>';
      break;
  }
  return $output;
}

/**
 * Implements hook_page_attachments().
 */
function external_page_attachments(&$page) {
  $settings = [
    'externalpdf' => \Drupal::config('external.settings')
      ->get('external_docs_enabled'),
  ];
  if (external_active() && \Drupal::config('external.settings')
    ->get('external_enabled')) {
    $page['#attached']['drupalSettings']['external'] = $settings;
    $page['#attached']['library'][] = 'external/external';
  }
}

/**
 * Determine if the module is active for the page being viewed.
 */
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;
}

Functions

Namesort descending Description
external_active Determine if the module is active for the page being viewed.
external_help Implements hook_help().
external_page_attachments Implements hook_page_attachments().