unset_html_head_link.module in Unset HTML head link 8
File
unset_html_head_link.module
View source
<?php
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\NodeInterface;
function unset_html_head_link_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
if ($build['#view_mode'] !== 'full' && $entity instanceof NodeInterface) {
return;
}
_remove_header_links($build);
}
function unset_html_head_link_page_attachments_alter(array &$attachments) {
_remove_header_links($attachments);
}
function _remove_header_links(array &$attachments) {
if (!isset($attachments['#attached']['html_head_link'])) {
return;
}
$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',
];
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]);
}
}
}
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;
}
}