function ContextualHooks::pageAttachments

Same name and namespace in other branches
  1. 11.x core/modules/contextual/src/Hook/ContextualHooks.php \Drupal\contextual\Hook\ContextualHooks::pageAttachments()

Implements hook_page_attachments().

Adds the drupal.contextual-links library to the page for any user who has the 'access contextual links' permission.

Attributes

#[Hook('page_attachments')]

See also

contextual_preprocess()

File

core/modules/contextual/src/Hook/ContextualHooks.php, line 65

Class

ContextualHooks
Hook implementations for contextual.

Namespace

Drupal\contextual\Hook

Code

public function pageAttachments(array &$page) : void {
  if (!\Drupal::currentUser()->hasPermission('access contextual links')) {
    return;
  }
  $page['#attached']['library'][] = 'contextual/drupal.contextual-links';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.