Score:0

How to alter pagination url of embedded view programmatically?

sj flag

I m trying to send mail which contain some data along with embedded view result programmatically. This mail is trigger on submit of webform. Webform ajax property is enable. Due to which it send incorrect url.

Used below code

$view = Views::getView($viewID);
$view->initDisplay();
.....
$vars['result_table'] = $view->buildRenderable('email', $contetxtualFilter);

In twig file

{{ result_table }}

Here output of first page is send in mail correctly but the pagination link has incorrect url.

Ex of incorrect pagination link of Page 1 is - "?_wrapper_format=drupal_ajax&ajax_form=1&page=0"
Ex of correct pagination link of Page 1 is - "www.test.com/productone?page=0"

Do you have any idea, how can I send correct pagination link in email without turning off webform ajax property. So that when user click on pagination in mail he is redirect to specific page.

No Sssweat avatar
ua flag
Seems like you have ajax enabled in your view settings. Try turning off and see if it sends correctly in email.
Sudha avatar
sj flag
Already checked but still same issue.
Score:0
in flag

It seems that the incorrect pagination link is being generated due to the _wrapper_format and ajax_form query parameters being added to the URL. These query parameters are used by Drupal to render views using AJAX, but they should not be included in a regular URL.

To fix this issue, you can try setting the use_ajax option to false when building the renderable array:

$vars['result_table'] = $view->buildRenderable('email', $contetxtualFilter, null, ['use_ajax' => false]);

This should generate the correct pagination links in the email.

Sudha avatar
sj flag
Even without passing any argument it still show incorrect url. Also after trying above solution it still shows the same.
Vikram8888 avatar
in flag
Is above code is updated in question is it a full code ?
Sudha avatar
sj flag
Yes.. I figure out issue. Usually I send mail on submit of webform. So the Webform ajax property was enable due to which pager link were generated in ajax format.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.