function beautytips_manager_page_attachments in BeautyTips 8
Implements hook_page_attachments().
File
- beautytips_manager/
beautytips_manager.module, line 17 - Code related to defining and displaying custom beautytips and styles.
Code
function beautytips_manager_page_attachments(&$page) {
$options = [];
$tips = beautytips_manager_get_custom_tips();
if (count($tips)) {
foreach ($tips as $tip) {
if (!$tip->enabled) {
continue;
}
// Match path if necessary.
if ($tip->pages) {
$pathCarrent = Url::fromRoute('<current>');
$path = Drupal::service('path.alias_manager.cached')
->getPathAlias($pathCarrent);
// Compare with the internal and path alias (if any).
$page_match = \Drupal::service('path.matcher')
->matchPath($path, $tip->pages);
if ($path != $pathCarrent) {
$page_match = $page_match || \Drupal::service('path.matcher')
->matchPath($pathCarrent, $tip->pages);
}
// When $tip->visibility has a value of 0, the beautytip is displayed on
// all pages except those listed in $tip->pages. When set to 1, it
// is displayed only on those pages listed in $tip->pages.
$page_match = !($tip->visibility xor $page_match);
}
else {
if (!$tip->visibility) {
$page_match = TRUE;
}
else {
$page_match = FALSE;
}
}
if ($page_match) {
$options['beautytips_manager_custom_' . $tip->id] = beautytips_manager_build_beautytip($tip);
}
}
}
if (count($options)) {
beautytips_add_beautytips($page, $options);
}
}