I'm trying to programmatically render a Views pane (ie. a Pane display of a view) with a taxonomy term as argument (passed in the pane context)
The following code illustrate how the pane is rendered
$selected_type = 'views_panes';
$selected_subtype = 'persona_display-panel_pane_1';
$context = array(
'context_taxonomy_term_1' => ctools_context_create('entity:taxonomy_term', $fully_loaded_taxonomy_term);
);
ctools_content_render($selected_type, $selected_subtype, array(), array(), array(), $context);
It mostly works and the view is rendered. However, the taxonomy term in the context is not used as argument for the view.
In the pane views display's settings, the "Argument input" for the one views' argument is configured as "Term ID" "From context":
I looked at the code for the view display handler. Arguments handling is done in views_content_plugin_display_panel_pane::pane_process_conf()
. I checked there and the issues seems to be that $conf['context']
is not set. So $context_keys
ends up being an empty array. Later in the switch statement, $key = array_shift($context_keys)
sets $key
to NULL
, the isset($contexts[$key])
test fails and the $argument
is ignored.
I have no idea if this is a bug with Views pane, or if something is missing in the pane rendering code.
Note: I'm actually using a Pane Field field in a Paragraphs bundle.
Get taxonomy term ID from url
. This way you do not have to pass any term ID programmatically.