0

This is part of my code in custom module in src/Plugin/Block/FavoriteBlock.php:

$build['ajax_link'] = [
  '#type' => 'link',
  '#title' => $this->npxFavoritesRepository->getTitle($node),
  '#attached' => ['library' => ['npx_favorites/npx_favorites-library']],
  '#attributes' => ['class' => $classes],
  '#url' => Url::fromRoute('npx_favorites.ajax_link_callback', ['node' => $node->id()]),
];

And it results with output, that is fine, but it doesn't trigger the AJAX event:

<a href="/pl/favorite/1045/toggle" data-once="ajax" class="use-ajax n-favourite favorite-1045 active">Usuń z ulubionych</a>

So when I click on that it brings me to page that looks like that:

ajaxpageresult

I have also another 'use-ajax' class from VUE template on the same page and it triggers the AJAX event. How can I make sure it is triggered, when I render this link from block?

0

2 Answers 2

2

Try attaching the drupal.ajax library.

$build['#attached']['library'][] = 'core/drupal.ajax';
1
  • I have this included, but it doesn't work
    – rukya
    Jun 27, 2022 at 12:34
0

It turned out, that VUE had conflicts with Ajax script.

Your Answer

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

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