Monday, December 9, 2019

how to remove w3 validation Bad value revision for attribute rel on element link in drupal 8



/**
 * Implements hook_entity_view_alter().
 * @param array $build
 * @param EntityInterface $entity
 * @param EntityViewDisplayInterface $display
 */
function Demo_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  // Cheking view_mode for node.
  if ($build['#view_mode'] !== 'full' && $entity Instanceof NodeInterface) {
    return;
  }
  _remove_header_links($build);
}
function _remove_header_links(array &$attachments) {
  // Cheking 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'
  ];
  // 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]);
    }
  }
}

No comments:

Post a Comment

If you have any problem please let me know.