function structured_data_page_attachments_alter in Structured Data (JSON+LD Rich Snippets) 8
Implements hook_page_attachments_alter().
File
- ./
structured_data.module, line 67 - Contains module functions for Structured Data.
Code
function structured_data_page_attachments_alter(array &$attachments) {
$page_meta = Helper::getCurrentPageMeta();
$obj = Helper::getPageJson($page_meta);
if (!empty($obj)) {
$tag = [
'#type' => 'html_tag',
'#tag' => 'script',
'#attributes' => [
'type' => 'application/ld+json',
],
'#value' => $obj->json,
];
$attachments['#attached']['html_head'][] = [
$tag,
'structured_data_json',
];
}
$user = \Drupal::currentUser();
if ($user
->hasPermission('manage page structured data json')) {
$attachments['#attached']['library'][] = 'structured_data/toolbar';
}
}