1

D7. Using the File Field Rules module, I am trying to copy the content of the image field of the user's account ("picture") to another image field ("field_node_image") in the same user's image gallery (each user has his own photo gallery.)

The purpose of this is for when a user uploads a picture to his account profile, a copy of it is also posted in his image gallery along with all the other pictures he may post there (displayed via Views.)

The module requires the selection of a source entity and a destination entity. Then a field is chosen from each entity.

I am making the event react upon updating the user's account, so that gives me access to the "account" selector for the source entity where the module finds the "picture" field.

But I need help in finding the destination selector. This, evidently, should be a node since the gallery is a content type. It also has to be a node that belongs to the user. But all base selectors I have begin by "site" or "account."

Can anyone help me find this second selector?

Thanks. :)

1 Answer 1

2

I think you need to add some more stuff in that Rule; namely, following from your explanation, you need to:

  1. "Create a new entity": Create a new node in an action, before the image-copying action. This new entity is a Gallery-type node.
  2. Use the "entity_created" variable as the destination entity.

That should be enough to accomplish your goal, hope this helped some!

Appendix A: An export of such a Rule that worked.

{ "rules_196457" : {
    "LABEL" : "196457",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "file_rules" ],
    "ON" : { "user_update" : [] },
    "IF" : [
      { "NOT data_is_empty" : { "data" : [ "account:field-user-image:file" ] } },
      { "NOT data_is" : {
          "data" : [ "account:field-user-image:file" ],
          "value" : [ "account-unchanged:field-user-image:file" ]
        }
      }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "article",
            "param_title" : "New pic for [account:name] | [site:current-date]",
            "param_author" : [ "account" ]
          },
          "PROVIDE" : { "entity_created" : { "new_article" : "Created entity" } }
        }
      },
      { "file_rules_copy_file" : {
          "source_entity" : [ "account" ],
          "source_field" : "field_user_image",
          "destination_entity" : [ "new-article" ],
          "destination_field" : "field_image",
          "remove_source" : "0"
        }
      },
      { "drupal_message" : { "message" : "A new Article has been created with the new user\u0027s image" } }
    ]
  }
}

Appendix B: An screenshot of the Rules UI

enter image description here

15
  • Interesting logic, I wouldn't have figured it out by myself. When the action creates the entity, the picture in it does not show, just an empty placeholder. Is there something else I should add?
    – user14666
    Mar 31, 2016 at 0:38
  • You need two actions, right? First creates the gallery node entity, second one copies the image from user into the new entity. Did you set it up like this? Mar 31, 2016 at 7:48
  • Sorry for late answer. I need to fix other rules issues before I tackle this one. Will revert soon. Thanks for your patience.
    – user14666
    Apr 5, 2016 at 2:41
  • Good to hear you are still on this. Looking forward to an update. Thanks for the ping! Apr 5, 2016 at 17:04
  • I am about to give up on this thing. Creating a new entity works but doesn't name a field to have a photo inside. So I had to add an action "set data value" to the created entity field taking the field from the user's picture. That worked. But I still can't copy the content of the new field to the gallery (1) it appears the module doesn't work and (2) outside the module, I still can't find the right selector to copy the image field to. So it's back to square one. Thanks anyway.
    – user14666
    Apr 7, 2016 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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