I have used variable_email but with no success as mentioned in a another issue
but I managed to get "send email" rules action to work properly with entityforms

I have a scenario where there is a file attached to the form (core file field)
of which I like to include the URL in the notification email to the admin (so one can download)

I have managed to be able to include the URL (using TOKENS) in the email when using the VBO action "send email to admin" but when the rule gets executed on the actual form submission that TOKEN is empty (we are talking about the same exact rule though)

I have the feeling that the rule executes before the file field has actually been able to put the file in its proper place and create its permanent URL

I have picked inside the file field using devel and custom_formatters and I realized that the
FID is there but the file_load(fid) function gives the correct file name but before its renamed by file_create_filename (file.inc) and the actual path that it gives me is wrong

I even tried to press upload before submitting the form which uploaded the file and the permanent URL (path) had already been created

any pointers on how to debug this ? or is there something that might be done on the entityform side ?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tedbow’s picture

The Rules are invoked in hook_entity_update and hook_entity_insert

These hook are actually called by EntityAPIController->save() (I think)

It could be that order of the hooks make another modules hook_entity_update and hook_entity_insert run after this.

Or it could from this which runs after:

// Field API always saves as default revision, so if the revision saved
        // is not default we have to restore the field values of the default
        // revision now by invoking field_attach_update() once again.
        if ($this->revisionKey && !$entity->{$this->defaultRevisionKey} && !empty($this->entityInfo['fieldable'])) {
          field_attach_update($this->entityType, $entity->original);
        }
tedbow’s picture

Status: Active » Fixed
GoZ’s picture

Status: Fixed » Active
FileSize
1 KB

i think it's not fixed or my issue is not the same (i don't see commit for that issue and your paste doesn't look to resolve this).

Problem is when rules called to send mail, it uses tokens to generate mail (with variable_mail).
In entityform_tokens(), $entityform entity founded on $data is the form entity, and not view entity, so the file field doesn't have view file field information (like uri), but datas to configure form (fid, transfer button etc).

What we have in $entityform['field_file']

Array
                (
                    [fid] => 88
                    [display] => 1
                    [description] => 
                    [upload_button] => Upload
                    [remove_button] => Delete
                    [upload] => 
                )

What we should have to be renderable by field_view_value() :

Array
                (
                    [fid] => 88
                    [display] => 1
                    [description] => 
                    [uid] => 1
                    [filename] => thefile.pdf
                    [uri] => public://thefile.pdf
                    [filemime] => application/pdf
                    [filesize] => 298595
                    [status] => 1
                    [timestamp] => 1379510450
                    [type] => document
                    [metatags] => Array
                        (
                        )

                    [metadata] => Array
                        (
                        )

                    [alt] => 
                    [title] => 
                )

Solution is to load the real entity in hook_tokens(). Patch below fix this.

This patch is part of the #1day1patch initiative.

tedbow’s picture

Status: Active » Needs work
+    // Get entity data and not form entity
+    $entityform = array_shift(entity_load($type, array($data['entityform']->entityform_id)));

Wouldn't this cause a problem because this is also used in Validation Rules. If this is new Entityform submission there would be no entityform_id

I have not tested this further but pretty sure are going to at least need if statement to check to see if entityform_id is empty.

tedbow’s picture

Title: notification is probably done before some field have finished work » All File Field tokens not available in notification Rules
Category: support » bug

changed title to be more descriptive

AIGAIJ’s picture

and possibly a loop, in case there are multiple files.

chrinor2002’s picture

Issue summary: View changes

For those looking for a temp solution to at least get the urls for files I was able to do so by changing the rules to re-load the entity prior to running replacements on a body. The rule changed was:
rules_entityform_notification_add_submission

Direct rules link:
/admin/config/workflow/rules/components/manage/rules_entityform_notification_add_submission

By adding a fetch entity by id and fetching the entityform_submission, and then running a data set replacing the entityform variable with the entity-fetched variable, I was able to get urls to show up in my email.

It looks like the issue is that the data being used for token (and being passed to entity2text) is actually the form data, and not the real fully loaded entity. Not sure where all that is buried in the code, but I hope this helps someone.

boutrosa’s picture

Hi @chrinor2002.
I have the same issue. I am trying to include an attached file with the email notification in entityform rule for a long time now (Drupal7: How to Include an ATTACHMENT to a Drupal's Entityform Submission Email ).

It'll be fine if at least I can include in the email the link of the attached file and not the file itself.
Can you show few screen shots of what you did in this section.
"By adding a fetch entity by id and fetching the entityform_submission, and then running a data set replacing the entityform variable with the entity-fetched variable, I was able to get urls to show up in my email."

I am following what you said but it is not working for me.
Probably I am missing something and screen shots of what you did would help.
Thanks.

chrinor2002’s picture

Hi @boutrosa

I did not want to attach them directly to the issue as they are more of a work around, less of a step to a resolution. As such here is a folder in my gdrive:
https://drive.google.com/open?id=0B0zWT1pko3BXfllaVF9VXzNFVmtKaFZyZk45U1...

Basically the issue was and maybe still is, that the entity that is passed along into the rule that actually renders the tokens used in the final email is not a true entity. It is just the submitted form data from when the user submitted data.

The idea behind my process is to load the saved submission entity, and then pass that in, instead of the submitted data.

I was not able to get it working quickly on my sandbox for this example, but it should help get things going in the right direction for some people.

chrinor2002’s picture

Oh! and its probably worth noting that I created a custom display for my entityform type. A display type of email, and i set the formatter for the file field to be of type url to file, not generic file.

hmdnawaz’s picture

I got it working like this.

Switched to data selection mode. Then move over to my file in the patterns which was something like this
entityform:field-image:0:file:url

Copied it and then again switched to direct input mode and paste it in the body field with brackets
[entityform:field-image:0:file:url]

I successfully get the uploaded image url in the email body. Hope it helps someone.

sanjay.soni’s picture

Hi,

token "[entityform:field-image:0:file:url]" is working fine if the file field is limited to single values.

If We change the file with unlimited values then the above token is not working.

Any suggestion, how we can Put link of uploded file with unlimited file uplode values.

Is there any chance to send the all file in attachment of email ?

Thanks,
Sanjay