contextual_test.module

Same filename in other branches
  1. 9 core/modules/contextual/tests/modules/contextual_test/contextual_test.module
  2. 8.9.x core/modules/contextual/tests/modules/contextual_test/contextual_test.module
  3. 11.x core/modules/contextual/tests/modules/contextual_test/contextual_test.module

Provides test contextual link on blocks.

File

core/modules/contextual/tests/modules/contextual_test/contextual_test.module

View source
<?php


/**
 * @file
 * Provides test contextual link on blocks.
 */
use Drupal\Core\Block\BlockPluginInterface;

/**
 * Implements hook_block_view_alter().
 */
function contextual_test_block_view_alter(array &$build, BlockPluginInterface $block) {
    $build['#contextual_links']['contextual_test'] = [
        'route_parameters' => [],
    ];
}

/**
 * Implements hook_contextual_links_view_alter().
 *
 * @todo Apparently this too late to attach the library?
 * It won't work without contextual_test_page_attachments_alter()
 * Is that a problem? Should the contextual module itself do the attaching?
 */
function contextual_test_contextual_links_view_alter(&$element, $items) {
    if (isset($element['#links']['contextual-test-ajax'])) {
        $element['#attached']['library'][] = 'core/drupal.dialog.ajax';
    }
}

/**
 * Implements hook_page_attachments_alter().
 */
function contextual_test_page_attachments_alter(array &$attachments) {
    $attachments['#attached']['library'][] = 'core/drupal.dialog.ajax';
}

Functions

Title Deprecated Summary
contextual_test_block_view_alter Implements hook_block_view_alter().
contextual_test_contextual_links_view_alter Implements hook_contextual_links_view_alter().
contextual_test_page_attachments_alter Implements hook_page_attachments_alter().

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