View source
<?php
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;
}
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';
}
}
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, '/')) . ')$/';
$page_match = preg_match($regexp, $path);
if ($path != $current_path) {
$page_match = $page_match || preg_match($regexp, $current_path);
}
return !$page_match;
}