1

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": enter image description here

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.

  • Note that this has been cross-posted as a support request in CTools' issues queue at drupal.org/node/2827763 – Pierre Buyle Nov 15 '16 at 13:07
  • Perhaps, if I understood this correctly, a work around, you could set the view contextual filter to Get taxonomy term ID from url. This way you do not have to pass any term ID programmatically. – No Sssweat Nov 16 '16 at 1:55
  • That does not work neither. – Pierre Buyle Nov 17 '16 at 20:23
1

I got it to work with

$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);
);
$config = array(
  'context' => array('context_taxonomy_term_1');
);
ctools_content_render($selected_type, $selected_subtype, $config, array(), array(), $context);

So, in order to render a Views Pane display with contextual filters coming from the pane's context you to populate $context and inform the display handler on which entries of $context to use for each contextual filter with $config['context'].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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