Would love to have Rules support for entityqueue. My specific use case would be having an action available that adds an entity to a specific queue/subqueue.

I think some work on this was already done here: https://www.drupal.org/node/2224219#comment-8924175

Comments

torgospizza’s picture

Status: Active » Needs review
StatusFileSize
new1.59 KB

We 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 :)

torgospizza’s picture

StatusFileSize
new2.6 KB

Previous patch somehow was missing changes to the .info and .module files. Complete patch attached.

jennypanighetti’s picture

Status: Needs review » Reviewed & tested by the community

torgos, 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

amateescu’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/entityqueue.module
@@ -1243,3 +1243,11 @@ function _entityqueue_set_breadcrumb($path = 'admin/structure/entityqueue/list')
+  $subqueue->eq_node[LANGUAGE_NONE][] = array('target_id' => $entity->getIdentifier());

We need to retrieve the proper field name of the queue here, otherwise this would only work for nodes :)

torgospizza’s picture

Status: Needs work » Needs review
StatusFileSize
new2.75 KB
new1.11 KB

Good 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.

amateescu’s picture

That looks much better, thanks! I looked at the patch again and I have two more questions :)

  1. +++ b/entityqueue.rules.inc
    @@ -0,0 +1,56 @@
    +function entityqueue_rules_queues_list() {
    

    entityqueue_rules_queues_list() doesn't seem to be used in the patch, can we remove it?

  2. +++ b/entityqueue.rules.inc
    @@ -0,0 +1,56 @@
    +function entityqueue_rules_subqueues_list() {
    

    How about using the existing entityqueue_get_options() for this?

torgospizza’s picture

StatusFileSize
new2.49 KB
new2.05 KB

entityqueue_rules_queues_list() doesn't seem to be used in the patch, can we remove it?

Good catch - that was going to be intended for filtering just queues (and not subqueues) but I can save that for another time.

How about using the existing entityqueue_get_options() for this?

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' => TRUE in 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.