contextual_test.module 1004 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * @file
  4. * Provides test contextual link on blocks.
  5. */
  6. use Drupal\Core\Block\BlockPluginInterface;
  7. /**
  8. * Implements hook_block_view_alter().
  9. */
  10. function contextual_test_block_view_alter(array &$build, BlockPluginInterface $block) {
  11. $build['#contextual_links']['contextual_test'] = [
  12. 'route_parameters' => [],
  13. ];
  14. }
  15. /**
  16. * Implements hook_contextual_links_view_alter().
  17. *
  18. * @todo Apparently this too late to attach the library?
  19. * It won't work without contextual_test_page_attachments_alter()
  20. * Is that a problem? Should the contextual module itself do the attaching?
  21. */
  22. function contextual_test_contextual_links_view_alter(&$element, $items) {
  23. if (isset($element['#links']['contextual-test-ajax'])) {
  24. $element['#attached']['library'][] = 'core/drupal.dialog.ajax';
  25. }
  26. }
  27. /**
  28. * Implements hook_page_attachments_alter().
  29. */
  30. function contextual_test_page_attachments_alter(array &$attachments) {
  31. $attachments['#attached']['library'][] = 'core/drupal.dialog.ajax';
  32. }