Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / contextual / tests / modules / contextual_test / contextual_test.module
1 <?php
2
3 /**
4  * @file
5  * Provides test contextual link on blocks.
6  */
7
8 use Drupal\Core\Block\BlockPluginInterface;
9
10 /**
11  * Implements hook_block_view_alter().
12  */
13 function contextual_test_block_view_alter(array &$build, BlockPluginInterface $block) {
14   $build['#contextual_links']['contextual_test'] = [
15     'route_parameters' => [],
16   ];
17 }
18
19 /**
20  * Implements hook_contextual_links_view_alter().
21  *
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?
25  */
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';
29   }
30 }
31
32 /**
33  * Implements hook_page_attachments_alter().
34  */
35 function contextual_test_page_attachments_alter(array &$attachments) {
36   $attachments['#attached']['library'][] = 'core/drupal.dialog.ajax';
37 }