I came across a situation where being able to dynamically chose a different Views Display based on the contextual arguments was necessary. One solution is to allow an override property in ResultRow during render to switch the view/display and use hook_views_pre_render to add the override to the rows when needed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kducharm created an issue. See original summary.

kducharm’s picture

A patch using ResultRow views_field_view__view_override and views_field_view__display_override

Sample hook_views_pre_render code:

/**
 * Implements hook_views_pre_render().
 */
function mymodule_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'myview') {
    foreach ($view->result as &$row) {
       if ($row->somedata) {
          $row->views_field_view__display_override = 'block_myotherdisplay';
       }
    }
  }
}
damiankloip’s picture

Hmm, not sure we want this kind of 'magic' property checked on the value object. Another suggestion, how about we refactor the Field plugin slightly so there is a method just to get the view id and display id. You could then extend the plugin class to add your own behaviour for this.

kducharm’s picture

@damiankloip I like that idea... this was definitely just a patch idea to get the ball rolling, will see if I can find bandwidth to make some getter/setters in the class so it can be extended.

jibran’s picture

Status: Active » Needs work

NW for #3.