-2

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',
    );
  }
}

I didn't get what I want.

1 Answer 1

1

The syntax of the link element is wrong.

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

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

How do I create a link? has several answers with methods to produce the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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