Currently on draggableviews.module we only broadcast the name of the view triggering the draggableviews_rules_event_sorted event. While broadcasting the $view->name alone is useful, it has it's limitations. If I want an action to be triggered depending on the current display being viewed, I can't. Adding the current display to the draggableviews_rules_event_sorted event allows for a more fine grained control of which actions get fired. My change allows me to create a ruleset that says:

If the name of the draggableview that fired the sort event is "primary news", and it's display name is "homepage", evaluate the action that clears the caches for the "primary news" block, "homepage" channel.

Without my change I would be forced to create a draggableview for each one of my channels.

Current:

if (module_exists('rules')) {
  rules_invoke_event('draggableviews_rules_event_sorted', $view->name);
}

Proposed:

if (module_exists('rules')) {
  rules_invoke_event('draggableviews_rules_event_sorted', $view->name, $view->current_display);
}

Uploading patch on next post.

Comments

alexander allen’s picture

Issue summary: View changes

Formatting

alexander allen’s picture

Issue summary: View changes

formatting

alexander allen’s picture

Issue summary: View changes

nitpicking

alexander allen’s picture

Status: Active » Needs review
StatusFileSize
new1.1 KB

Uploaded patch.

alexander allen’s picture

Re-rolled patch with correct Git comment.

alexander allen’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
StatusFileSize
new1.1 KB

Re-rolled patch against 7.x-2.x-dev version for the benefit of others as well. I'd be nice if this could be committed to both branches.

Thank you!

alexander allen’s picture

Assigned: alexander allen » Unassigned
ygerasimov’s picture

Status: Needs review » Needs work

Will it be better to pass complete views object instead of simple views name and display name?

alexander allen’s picture

Status: Needs work » Needs review

While convenient, I'm afraid this might not be possible without significant effort. When specifying variables for hook_rules_event_info(), the data type of the variable must be limited to the types declared in hook_rules_data_info() or supported by hook_entity_property_info(). The only two data types that support objects are entity and struct. Entity is limited to entities such as node, user, etc, which in turn need to be declared with hook_entity_info(), and Views are not declared as entity objects. As for the struct data type, quote:

additional metadata has to be specified with the 'property info' key.

where 'property info' is

an array of info for an arbitrary data structure (that specifies) metadata in the same way as defined for this hook.

If there would be a generic "object" data type available, I would be all in for this, however at this point I am not even sure how to "Specify (the) metadata in the same way as defined for this hook". I'm currently thinking that with the basic information our event provides (View name and current display), if the user needs more detailed information about the view he call always do a $view = views_get_view('name_of_my_view');, which at this point would be efficient because it would be served from cache. And if he needed other kind of information not provided by views_get_view, he could always just implement one of the other Views hooks. If I am missing something, or you think there is still a use case we don't cover with this solution, then perhaps we can explore implementing the 'struct' data type. That would be best implemented by another person though.

ygerasimov’s picture

Status: Needs review » Fixed

Alright. I have committed patch passing only display name (http://drupalcode.org/project/draggableviews.git/commit/c0bc790). Thank you.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

compulsive formatting syndrome