1

Working with Drupal 7.58 and File Entity 2.19 and Rules 2.10

First I needed to fire a rule when saving a new file and I found a solution (here).

Now I would like to fire a rule when an user removes an image (file) from a content (Image field with multiple values).

I can not find any event to start working after an image is removed?

EDIT 1 :

Following @Pierre.Vriens "check list approach", I have tried to create a simple rule fired when an image is removed :

{ "rules_verify_pictures_removed" : {
    "LABEL" : "Verify pictures removed",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "image" ],
    "REQUIRES" : [ "rules_conditional", "rules" ],
    "ON" : { "node_update--article" : { "bundle" : "article" } },
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "node-unchanged:field-pictures" ] },
          "ITEM" : { "list_item" : "Previous list item" },
          "DO" : [
            { "CONDITIONAL" : [
                {
                  "IF" : { "NOT list_contains" : { "list" : [ "node:field-pictures" ], "item" : [ "list-item" ] } },
                  "DO" : [
                    { "drupal_message" : { "message" : "Picture has been removed.", "type" : "warning" } }
                  ]
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

Unfortunately, condition is always False and I get the message even if no item has been removed (One message for each item, unchanged, added or removed)

0

To my knowledge there is no Rules Event like the one you are looking for. However, as illustrated in my answer to the question you linked to, you can use an approach like so:

  • iterate over all field values of your field of the unchanged node.
  • within each iteration step, check if the list of items in the changed node does NOT contain the field value being processed in the current iteration step ... If it is NOT contained in it anymore, it means the values is removed.

Note: processing image fields in Rules is a bit special. You may have to use a token like [node:field-pictures:file:url] and [list-item:file:url]. And if they appear to be empty, then retry by adding a Rules Condition like "content is of type = article"

  • Thanks @Pierre for your answer. I have tried this approach that makes sense. Unfortunately, with an Image field, condition is always False if you check each item from a list of pictures. Would you please try your approach with an Image field (multi-values) and tell me if you manage to show the right message when an item is removed? – Toki Apr 19 '18 at 8:27
  • Hey @Toki, can you edit (update) your question to add an export of the Rule you tried (as you wrote in your prior comment)? – Pierre.Vriens Apr 19 '18 at 10:24
  • Edit OK @Pierre – Toki Apr 19 '18 at 11:22
  • @Toki can you review the "note" I added? – Pierre.Vriens Apr 19 '18 at 20:37
  • tokens you mentioned are not really useful here and content type is set by the event. I am still stuck unfortunately, do you know maybe how to write a rules event "When removing a file from content"? – Toki Apr 23 '18 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.