I really need the views object in a hook_ds_views_view_mode_alter() implementation. My use case is somewhat complex and I realize it's an edge case, but I hope I can make the case here that it would be valuable to add the view object to the context. What I am doing is this:

I have a views panel pane with exposed filters and custom settings. The view displays it's results in DS. I need to alter the output of the entity in DS based on my custom settings and based on exposed filters. I know there is also the hook_ds_views_row_render_entity_alter() which DOES pass the view object, but that doesn't pass in the entity for alteration, so I have no way to connect these 2 in either hook.

Proposed solution: pass on the view as follows:

     $context = array(
      'entity' => $this->entities[$row->{$this->field_alias}],
      'view_name' => $this->view->name,
      'display' => $this->view->current_display,
      'view' => &$this->view, // <-- Added the view object, in a similar manner as in ds_views_row_render_entity (meaning, by reference)
    );
    drupal_alter('ds_views_view_mode', $view_mode, $context);

I will attach a patch.

CommentFileSizeAuthor
#1 add_view_object_to_context-2187543-1.patch657 bytesdagomar

Comments

dagomar’s picture

StatusFileSize
new657 bytes
dagomar’s picture

Status: Active » Needs review
netsensei’s picture

Status: Needs review » Needs work

As the views_plugin_ds_entity_view class is just a row plugin, I would suggest trying this: just extend the class and override the render() method with your own implementation. This would avoid patching DS for, as you point out, a pretty specific use case.

Give https://drupal.org/project/vcd a look. I do exactly that to make the module work.

-> views_plugin_row_vcd extends the views_plugin_ds_entity_view class
-> I've overridden the ds_views_row_render_entity() method. In your case, that would be the render function (Just copy & paste it and make your changes)
-> Register your custom class with hook_views_plugins() (Checkout vcd.views.inc on how I did that)

Granted, it might look a bit more convoluted, but you'll be able to write app specific code which is cleanly separated from contrib.

aspilicious’s picture

Status: Needs work » Closed (won't fix)

Netsensei thnx for the clear explanation.
This is a won't fix.

dagomar’s picture

Thanks both, I'll look into the alternative.