This repository has been archived by the owner on Aug 18, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
unset_html_head_link.module
65 lines (61 loc) · 1.88 KB
/
unset_html_head_link.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\NodeInterface;
/**
* Implements hook_entity_view_alter().
* @param array $build
* @param EntityInterface $entity
* @param EntityViewDisplayInterface $display
*/
function unset_html_head_link_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
// Checking view_mode for node.
if ($build['#view_mode'] !== 'full' && $entity Instanceof NodeInterface) {
return;
}
_remove_header_links($build);
}
/**
* Implements hook_page_attachments_alter().
* @param array $attachments
*/
function unset_html_head_link_page_attachments_alter(array &$attachments) {
_remove_header_links($attachments);
}
function _remove_header_links(array &$attachments) {
// Checking html_head_link on attached tags in head.
if (!isset($attachments['#attached']['html_head_link'])) {
return;
}
// Array to unset.
$unset_html_head_link = [
'delete-form',
'edit-form',
'version-history',
'revision',
'display',
'drupal:content-translation-overview',
'drupal:content-translation-add',
'drupal:content-translation-edit',
'drupal:content-translation-delete',
'shortlink',
'canonical',
'clone-form'
];
// Unset loop.
foreach ($attachments['#attached']['html_head_link'] as $key => $value) {
if (isset($value[0]['rel']) && in_array($value[0]['rel'], $unset_html_head_link)) {
unset($attachments['#attached']['html_head_link'][$key]);
}
}
}
/**
* Implements hook_module_implements_alter().
*/
function unset_html_head_link_module_implements_alter(&$implementations, $hook) {
if ($hook === 'page_attachments_alter') {
$group = $implementations['unset_html_head_link'];
unset($implementations['unset_html_head_link']);
$implementations['unset_html_head_link'] = $group;
}
}