function easymeta_page_attachments in Easymeta 8
Implements hook_page_attachments().
File
- ./
easymeta.module, line 27 - Contains easy_meta.module.
Code
function easymeta_page_attachments(array &$page) {
$current_path = \Drupal::service('path.current')
->getPath();
$current_language = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$meta = new Meta($current_language, $current_path);
$meta_values = $meta
->getValue();
if ($meta_values) {
foreach ($meta_values as $meta_value) {
$meta_tag = NULL;
if (isset($meta_value['tag']) && isset($meta_value['value']) && !empty($meta_value['value'])) {
$meta_tag['#tag'] = $meta_value['tag'];
if (isset($meta_value['name_property'])) {
$meta_tag['#attributes']['name'] = $meta_value['name_property'];
}
if (isset($meta_value['property'])) {
$meta_tag['#attributes']['property'] = $meta_value['property'];
}
if ($meta_value['name'] != "og_image") {
$meta_tag['#attributes']['content'] = $meta_value['value'];
}
else {
$url = NULL;
if (isset($meta_value['value'][0])) {
$file = file_load($meta_value['value'][0]);
if ($file) {
$url = file_create_url($file
->getFileUri());
}
}
$meta_tag['#attributes']['content'] = $url;
}
$page['#attached']['html_head'][] = [
$meta_tag,
$meta_value['name'],
];
}
}
}
}