Needs review
Project:
Entityqueue
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
20 Apr 2015 at 13:55 UTC
Updated:
29 Apr 2019 at 23:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
torgospizzaWe need this for our site, as I'd like to automatically add nodes to a subqueue when they're flagged. Attached is my first pass at a patch for this - it lets you configure a Rule that adds an entity to a subqueue:
- Adds hook_rules_action_info()
- Adds a callback to list subqueues in the Rules Action config form
- Adds a callback to perform the action
I haven't yet written the action to remove an item from the queue, and also, I'm not doing anything yet to verify that the content type matches, etc. - this is a quick solution that for the moment will require a bit of knowledge by the admin about the queue and entity they're adding.
This works so far in my testing and hopefully will be a good starting point for anyone else who would like to contribute more lines of code :)
Comment #2
torgospizzaPrevious patch somehow was missing changes to the .info and .module files. Complete patch attached.
Comment #3
jennypanighetti commentedtorgos, thank you SO MUCH for this. Nodequeue wasn't working properly so I switched to Entityqueue but absolutely needed Rules integration. This worked perfectly.
+1 should be committed
Comment #4
amateescu commentedWe need to retrieve the proper field name of the queue here, otherwise this would only work for nodes :)
Comment #5
torgospizzaGood point! Here's a new patch that loads the queue, and then retrieves the field via
_entityqueue_get_target_field_name().Also set the entity to not be wrapped, since I don't think we really need an EMW for this. Interdiff also attached.
Comment #6
amateescu commentedThat looks much better, thanks! I looked at the patch again and I have two more questions :)
entityqueue_rules_queues_list()doesn't seem to be used in the patch, can we remove it?How about using the existing
entityqueue_get_options()for this?Comment #7
torgospizzaGood catch - that was going to be intended for filtering just queues (and not subqueues) but I can save that for another time.
I tried that, but it looks like we can't - Rules requires entities to be specified by ID, whereas
entityqueue_get_options()returns an array of subqueues keyed by name. (I also tried setting`named_parameter' => TRUEin the action definition, but Rules was still unable to evaluate the action callback. Perhaps I'm doing something wrong? My code was based on other modules doing similar things with their "options list" callbacks, so it seemed like more or less the best practice for this particular operation, but I'm definitely into reusing existing functions as much as possible.In any case, new patch and interdiff attached. I also utilized the EntityMetadataWrapper to more easily get the ID of the entity since we might not know which property that is.