function add_to_head_match_page in Add To Head 8
Same name and namespace in other branches
- 7 add_to_head.module \add_to_head_match_page()
Determines if code should be displayed on a particular page.
Originally from block_list().
Parameters
array $profile: The profile to check against
string $path: Allow injection of non-current path for checking.
Return value
boolean TRUE if the code should be displayed on the page; FALSE otherwise.
1 call to add_to_head_match_page()
- _add_to_head_profile_visible in ./
add_to_head.module - Is this profile visible?
File
- ./
add_to_head.module, line 136 - Add To Head allows arbitrary insertion of code into the head of the page based on path selection.
Code
function add_to_head_match_page(array $profile, $path = NULL) {
// Determine if the code should be visible on the current page.
$visibility = isset($profile['paths']['visibility']) ? $profile['paths']['visibility'] : 'exclude';
$paths = isset($profile['paths']['paths']) ? $profile['paths']['paths'] : '';
// Get the current path.
if (!isset($path)) {
$path = \Drupal::service('path.current')
->getPath();
}
// Compare with the internal and path alias (if any).
$page_match = \Drupal::service('path.matcher')
->matchPath($path, $paths);
if (!empty($_GET['q']) && $path != $_GET['q']) {
$page_match = $page_match || \Drupal::service('path.matcher')
->matchPath($_GET['q'], $paths);
}
// Check alias
if (!$page_match) {
$alias = \Drupal::service('path_alias.manager')
->getAliasByPath($path);
$page_match = \Drupal::service('path.matcher')
->matchPath($alias, $paths);
}
$visibility = $visibility == 'exclude' ? 0 : 1;
// When $visibility has a value of 0, the code is displayed on
// all pages except those listed in $paths. When set to 1, it
// is displayed only on those pages listed in $paths.
return !($visibility xor $page_match);
}