function sharemessage_page_attachments in Share Message 8
Implements hook_page_attachments().
File
- ./
sharemessage.module, line 138 - New Sharing Module.
Code
function sharemessage_page_attachments(&$page) {
$config = \Drupal::config('sharemessage.settings');
\Drupal::service('renderer')
->addCacheableDependency($page, $config);
if ($config
->get('message_enforcement')) {
$smid = \Drupal::request()->query
->get('smid');
$page['#cache']['contexts'][] = 'url.query_args:smid';
if (!empty($smid)) {
/** @var \Drupal\sharemessage\ShareMessageInterface $sharemessage */
$sharemessage = ShareMessage::load($smid);
if ($sharemessage) {
\Drupal::service('renderer')
->addCacheableDependency($page, $sharemessage);
foreach ($sharemessage
->buildOGTags($sharemessage
->getContext()) as $tag) {
$page['#attached']['html_head'][] = [
$tag,
str_replace(':', '_', $tag['#attributes']['property']),
];
}
}
}
}
}