Rules 2 has the nice feature of loops, allowing you to execute actions on "lists" – arrays of Rules objects.
I just finished the first version of an action "Load a node list with Views" in Rules Bonus Pack (http://drupal.org/project/rb), making it possible to use Views to load node lists and then execute actions on them. (I hope to extend this to include all entities recognized by Rules.)
I've been calling VBO from Rules quite much in Drupal 6, and I feel that this approach is *much* more easy to use – and also allows using Rules objects much more flexibly.
Thus, I suggest *not* adding a Rules action for executing VBO:s. (I suggest this as a start of a discussion, not as an end of it.)
Comments
Comment #1
bojanz commentedPeeking at http://drupalcode.org/project/rb.git/commitdiff/c05a6ce?hp=c9d37479ae97d...
Does seem like a better approach. Having an action that fetches the results from a vbo view (though it would need to be a bit smarter because the VBO field might be on a relationship..)
Would love if people actually told me what they are even using the "Execute VBO from rules" functionality for.
EDIT: Updated the comment to reflect the fact that I find this preferable than the old "execute vbo" approach.
Comment #2
bojanz commentedRetitling.
Comment #3
renat commentedLooks very promising! Hope there will be next RB -dev soon, to test all this.
Comment #4
itangalo commented@renat: It is in dev!
@bojanz: The use case I have is almost always "update a number of nodes" or "send e-mail to a number of users". (Mostly the former.) Pretty often it includes arguments sent off to the view (or "contextual filter values", in the modern language). I have never used the exposed filter options.
Comment #5
bojanz commented@Itangalo
Okay, thanks. I will be stealing the RB's approach soon ;)
Comment #6
itangalo commented@bojanz: Note that this functionality is not VBO specific – you can load nodes from any View. It may still make sense to have this functionality in VBO, since it integrates Views and Rules, but I'm not 100% sure.
(Updating the title to reflect this point.)
Comment #7
bojanz commentedIt needs to be VBO specific because that's how it determines which entities to get.
An example is a node view showing node authors as well (user relationship). The VBO field can be on nodes, or on users. Two different types of entities.
Comment #8
itangalo commentedOh!
My idea was to just take the objects corresponding to the base table of the view, but allowing flexibility is of course a good thing.
Comment #9
bojanz commentedhttp://drupalcode.org/project/views_bulk_operations.git/commitdiff/1bd08...
Thanks, Itangalo!
Comment #10
itangalo commentedSweet! Looking forward to trying this one out, and creating simple examples with awesome results. (Here's one example: Flag this node to get e-mail notifications on new comments.)
Comment #12
itangalo commentedSorry to re-open this issue. I just tried the new feature, and have a comment.
When loading a list of entities in Rules, I couldn't find any way to tell Rules what kind of entities are loaded. The result is that Rules becomes unable to do more or less anything at all with the entities – such as sending e-mails to users or publishing nodes.
I tried to add conditions "entity is of type", but no luck. To investigate further, I tried adding two different VBO fields to a view – acting on nodes or users. Rules didn't pick up this difference, which makes me believe that Rules doesn't really have a chance of knowing which type of entity should be treated as the base object in the loaded list.
I suggest changing this feature to an approach where each VBO field is listed as an action in Rules ("Load a list of users using field XYZ" or "Load a list of content using field ABC"), or possibly another option in the action configuration where you get to choose which VBO field should be used for loading the list.
Makes sense?
Edit: I'm opening an issue for a sub-module to VBO, dedicated to Rules/Views integration – #1243900: Separate most Rules/Views integration to a sub module.
Comment #13
bojanz commentedVBO assumes you only have one VBO field on a view. You can't have multiple VBO fields on a view, only the first one is used. That's how the code works right now, and since that's the way it works, it doesn't make much sense to allow that for Rules only.
The VBO field knows what entity type it's working on ($vbo->get_entity_type()), so it should be able to provide additional info to Rules, if what it returns right now is not enough.
Which module is that?
Comment #14
bojanz commentedOkay, I see the problem now. VBO returns a list of entities (list<entity>) so the actions that want a specific type (node, commerce_product) fail to accept it.
So, if fago doesn't give us some magical trick, I'm guessing we either create an action for each entity type, or for each VBO field. Not sure which one would produce more entries. I'm more for creating it per entity type right now.
Comment #15
itangalo commentedI think we need one action per VBO field.
Example: You have a node view, with a relation using a node reference field. You add a VBO field utilizing this relation. When invoking this from Rules, you want to fetch the related nodes, not the base objects. If only fetching a selected entity type, Rules won't be able to know this.
Comment #16
bojanz commentedThat's not a problem.
Well, if you select a "Load user entities from a VBO view", the dropdown will only show views that have a VBO field operating on that entity type. Including a node view with a VBO field on authors, for example.
It all comes down to which version ("Load $entity_type entities from a VBO view" VS "Load entities from the $view_name VBO view") is more user friendly and obvious.
Comment #17
bojanz commentedThat's not a problem.
Well, if you select a "Load user entities from a VBO view", the dropdown will only show views that have a VBO field operating on that entity type. Including a node view with a VBO field on authors, for example.
It all comes down to which version ("Load $entity_type entities from a VBO view" VS "Load entities from the $view_name VBO view") is more user friendly and obvious.
Comment #18
itangalo commentedOh, now I get it. Thanks. (If you have two different node VBO fields on one view you would still have the problem though, but that's a rather hypothetical case even for a VBO maniac like myself.)
The choice of action name is pretty tricky. I think me and most others think "I wanna load users", which speaks in favour of "Load $entity_type entities from a VBO view". On the other hand, you have probably just built the VBO you want to use to load users, so "Use $view_name to load entities" might be a better candidate.
In either case, I think it is just a minor difference in usability. If one is significantly easier to code, I say that's the choice.
What's your opinion?
Comment #19
bojanz commentedHere's a fix without all that. I asked fago, and of course, he knew a smarter solution :)
Please confirm that it works for you.
Comment #20
itangalo commentedI am shocked to hear that fago had a smarter solution.
I tried the patch, but got AJAX errors when trying to use the action "Load a list of entities from a VBO View.", saying that the $view on line 186 in views_bulk_operations.rules.inc isn't an object.
Some more digging around tells me that the function _views_bulk_operations_rules_get_field() gets called without the proper arguments sometime during the configuration form building, but I can't really tell when.
When bypassing this (by hard-coding a view name into the rules.inc file), it seems to be working nicely. (There were some error messages on the config screen, but that is most likely due to the missing function arguments.)
What do you say about having a BoF in London and talk more about VBO + Rules? It would be interesting to hear fago's ideas as well.
Thanks for good work.
Comment #21
bojanz commentedAnd.. updated.
Comment #22
itangalo commentedWorks like a charm!
Comment #23
bojanz commentedCommitted :) Thanks for testing.
Comment #25
GlitchFreak commentedHi all
Apologies for reopening, but I'd like to find out what the solution for #12 was regarding telling rules what type of entities are being provided by VBO.
I have the -dev version loaded and I do not see the options proposed above.
Thank you for a great module!
Comment #26
itangalo commented@GlitchFreak: You'll have to loop through the results from the View, and then call a rule set (or something) inside the loop – doing conditions and subsequent actions from the rule set.
Kind of quirky, I know, but that's the only way to do condition checks inside loops right now.
Comment #27
GlitchFreak commentedAh I never thought that.
Thanks Johan. I appreciate the help and thanks for all your screencasts as well. They have helped me immensely!