1

I am attempting to send a list of uploaded files on a newly created node via email.

In a content type, I have a File Field that allows unlimited values.

Within Rules, I created a loop calling the current item "current_file".

enter image description here

I am trying to concatenate all of the values into one longtext field called "file_list".

I intend to use the token for the value of "file_list" in the body of an email.

Unfortunately, I am unable to do so.

While in Data Selection mode, I can access the tokens created by the loop:

enter image description here

However, while in Direct Input mode, the tokens are not available to me. They are not listed in the "Replacement patterns" section.

When I attempt to fill the value with the following, I have no success:

[node:field-file-list]
[current-file:file:url]

What can be done to make the tokens available to me in Direct Input mode?

If I am doing this incorrectly, is there a different way for me to concatenate all of the URLs of each file so that I can put it in the body of an email action?

1

If what you're looking for is not available, then just make it available, which is "a different way to concatenate all of the URLs of each file" (as in your question). Read on for more details ...

Have a look at this example of a Rule (in Rules export format), which is a variation of what you're asking for:

{ "rules_show_list_of_fields" : {
    "LABEL" : "Show list of fields",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert" : [], "node_update" : [] },
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } }
    ],
    "DO" : [
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : "StartOfList-" },
          "PROVIDE" : { "variable_added" : { "email_list" : "List of eMail IDs" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "node:field-email-addresses" ] },
          "ITEM" : { "current_email" : "Current eMail" },
          "DO" : [
            { "data_set" : {
                "data" : [ "email-list" ],
                "value" : "[email-list:value][current-email:value]-"
              }
            }
          ]
        }
      },
      { "data_set" : { "data" : [ "email-list" ], "value" : "[email-list:value]EndOfList" } },
      { "drupal_message" : { "message" : "The value of the email_list variable is: [email-list:value]." } }
    ]
  }
}

Here is a summary of what this rule does:

  • Add a new variable email_list.
  • Init the email_list value with some prefix.
  • For each item within the loop, append the value of that item, followed by a separator character.
  • Add a suffix to the email_list value.

In my case I'm using a multi value text field with machine name field_email_addresses, which contains eMail Ids, and just want to dispay a Status message with a concatenation of those eMail IDs, separated by a "-", and with a prefix (=StartOfList) / suffix (=EndOfList). And I also use Rules Events "Update existing node".

Replace the machine name of my list field to your list field, and replace all 'eMail' by 'file' and you should be able to import this rule in your own site (if you have the Rules UI enabled).

Not sure if you want the prefix or suffix, and/or the separator character (="-"). Adapt or remove any of these to fit your needs.

Voilà ...

Demo

Here is how the Status message looks like after you create a new node, or update an existing node (of type Article):

The value of the email_list variable is: StartOfList-user2@example.com-user4@example.com-EndOfList.

  • Hi Pierre. Thank you for your response. I appreciate the help. Unfortunately, this did not work for me. I imported your rule (but used my fields in its place) and the tokens were not printing anything. Despite that, your answer did help spark an idea to help me out! I discovered a workaround and will post the solution soon. – AndrewMRiv Nov 28 '16 at 20:11
  • @AndrewMRiv merci for your feedback. As per your "your answer did help ...", are you familiar with this? – Pierre.Vriens Nov 28 '16 at 20:49
  • I got this to work as well but I would like to know if you also know how to put the final value: [email-list:value] in a Bcc: field of the email so that not everyone sees who gets this email. I think it should be possible with a module but if there is an easier and less performance-heavy solution, I'd love to hear it. Much appreciated. – BassPlaya Aug 11 at 6:15
0

This answer assumes that you have basic knowledge in using the Rules module and understand how to use a loop to return all values of a field with unlimited allowed inputs.

(Also, this will only cover reacting on a newly created node.)


So the main issue was that loop variables in rules were not available to me while in "Direct Input" mode BUT were available "Data Selection" mode.

I needed to concatenate all of the file names and file urls for an unlimited value file field and output them in an un-ordered html list in a Long Text field (Filtered HTML).

There may be a better way to do this, but this was currently the only way I could make this work.


1.) Create Extra Fields

Since the Loop variable tokens are not available in Direct Input mode BUT regular Field tokens are, we are going to put the loop variable info into the new fields AND THEN concatenate them.

You will create fields for the following:

  • Uploading the files (File Field set to accept unlimited values)
  • File Name field (Long text field. It is important that this is set to plain text. I experienced issues when this was not plain text)
  • File Path/URL field (Also long text, also plain text for the same reason)
  • File List field in plain text (Long text field in plain text. This is the field that will grab all of the concatenated values. It will make sense later. This also needs to be plain text or Rules will not concatenate the values for some reason).
  • File List field in filtered html (Long text field with filtered html. This is the field that will be displayed to the users.)

enter image description here

In the above fields, only the very first and very last fields will be visible to the users. The rest should be hidden with the Field Permissions module.

The extra fields are just going to be used by the Rules module.


2.) Create a Loop

Since this file field has unlimited inputs, you will create a loop and select the File field.

I have named the current file in the loop "current_file".

enter image description here


3.) Grab the File name

Within the newly created loop, we will create an action to "Set a Data value". It will grab the newly created File Name field and grab the value of the current file's file name.

Be sure that you are not in direct input mode or the tokens will not be available to you.

enter image description here

4.) Grab the File's URL

This step is similar to the last.

Add another action to "Set Data Value" for the newly created File URL/Path field. Set it to grab data from the current file's file URL.

Once again, be sure that you are not in direct input mode or the tokens will not be available to you.

enter image description here

5.) Concatenate the Values

Finally, in the Plain Text File List field, we are going to concatenate the values.

We first enter in the token that represents the current field and below it, we will add on the current file name and path.

This time, be sure to be in Direct Input mode so that you type in whatever you like:

enter image description here

6.) Add ul tags

Make sure that this is outside of the loop.

Add an action to Set a Data value that adds ul tags around the value.

enter image description here

7.) Put the Concatenated Values into the Filtered HTML field

We are going to add another action to Set a Data value. It will put the value of the Plain Text File list into the Filtered HTML File List field.

The reason two different file list fields were created is because concatenating in a filtered html field does not work for some reason.

enter image description here

8.) See the Results

If all of the steps are followed, you should be given an un-ordered HTML list of each uploaded file that is linked to its file url:

enter image description here

I feel like this 'should' be able to be accomplished in far less steps, but this was the only way I could solve the problem.

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.