I am using Drupal 9 and views_field_view to embed a "child" view within a "parent" view. Because there are multiple rows in the parent view, I end up with multiple of the same "child" view being rendered. This prevents the "pagination" from rendering because the "pager id" is the same for the multiple rendered child views.
I am able to circumvent that render issue by programmatically setting the pager id. See code below.
use Drupal\views\ViewExecutable;
function hook_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
if ($view->id() == '<view_id>') {
$unique_id = $view->args[0]; // argument that is a unique ID
$view->pager->options['id'] = $unique_id;
}
}
By using the above code in a module, the child view's pager now appears. However, clicking the pager numbers or buttons results in the parent view updating instead of the child view.
How can I change the pager for the "child" view so that it updates the child view instead of the parent?
It seems that I need to properly initialize the pager or alter the jquery so it updates the child view instead of the parent? How might I go about doing that?
Here are a some things I've been looking into, but so far have not helped:
- Drupal 7 views fix - not applicable since views moved into core?
- Views load more issue, Views show more module, Views infinite scroll issue
- Within the views_field_view module it seems that it attempts to set a unique id for the pager before using the following
$view->initPager();
to initialize the pager. However debugging shows that the ID that is set does not get applied on to the $view. Did something maybe change with initPager? (though the API doesn't make any indication that it has)