-1

I want to add a custom contextual link on the top of every block. there are many answers available on the site but these answers are about adding a contextual link to a specific block. and I need to add a contextual link which appears in the contextual menu of every block available in the site. I have tried this function.

function MYMODULE_contextual_links_view_alter(&$element, &$items) {
   if (isset($element['#element']['#block'])) {
      $element['#links']['animation'] = array(
      'title' => 'change animation',
       );
  }
}

But I have not get what I want.

1

The syntax of link element is wrong.

This is a sample from the documentation of Link render element:

Usage example:

$build['examples_link'] = [
    '#title' => $this->t('Examples'),
    '#type' => 'link',
    '#url' => Url::fromRoute('examples.description')
  ];

link: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21Element%21Link.php/class/Link/8.4.x

This question has several answers with methods to produce the Link:

How do I create a link?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.