I'm trying to load a view X times but with a different contextual filter value each time. My code generates the correct amount of view blocks, but they are all the exact same. They all correspond to the first value passed. Here's my code (in hook_preprocess_node) :
if ($node->getType() == 'parent'){
$parent= $node->field_datas_taxonomy->getValue()[0]['target_id'];
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadChildren($parent);
foreach($terms as $term){
$pname = $term->get('name')->value;
$tid = $term->get('tid')->value;
$args = [$tid];
$view = \Drupal\views\Views::getView('vue_datas');
if (is_object($view)) {
$view->setArguments($args);
$view->setDisplay('block_a');
$view->preExecute();
$view->execute();
$content = $view->buildRenderable('block_a', $args);
$variables['view_datas'][] = $content;
}
}
}
If this issue is tied to a contextual filters restriction, I'm ok with using a filter instead, I just don't know how.
Any advice? Thanks.