5 * Provides test contextual link on blocks.
8 use Drupal\Core\Block\BlockPluginInterface;
11 * Implements hook_block_view_alter().
13 function contextual_test_block_view_alter(array &$build, BlockPluginInterface $block) {
14 $build['#contextual_links']['contextual_test'] = [
15 'route_parameters' => [],
20 * Implements hook_contextual_links_view_alter().
22 * @todo Apparently this too late to attach the library?
23 * It won't work without contextual_test_page_attachments_alter()
24 * Is that a problem? Should the contextual module itself do the attaching?
26 function contextual_test_contextual_links_view_alter(&$element, $items) {
27 if (isset($element['#links']['contextual-test-ajax'])) {
28 $element['#attached']['library'][] = 'core/drupal.dialog.ajax';
33 * Implements hook_page_attachments_alter().
35 function contextual_test_page_attachments_alter(array &$attachments) {
36 $attachments['#attached']['library'][] = 'core/drupal.dialog.ajax';