Send the actually attached file's url within an e-mail

Events happening in the community are now at Drupal community events on www.drupal.org.
pene's picture

I have a Drupal 7 site with a custom node type with a custom attachment field. After a (kind of this custom) node has been published, I got an e-mail with the help of Rules module. I would like to set up an another rule, which sends me an another e-mail, when somebody edits this node and uploads an attachment. Inside the mail, I want to see the full url to the uploaded file.

After a several test, I'm not able to insert the full path to the uploaded file. The [node:field-attachment:file] doesn't work at all. I'm able to insert (manually) the url where this file resides, but after I can not insert the file name (so even the filename would be enough for me).

So with the [node:field-attachment:file] I got an error: Fatal error: Call to a member function value() on a non-object in /home/xxx/sites/all/modules/entity/entity_token.tokens.inc on line 297.

Which is exactly this:

/**
 * Gets the token replacement by correctly obeying the options.
 */
function _entity_token_get_token($wrapper, $options) {

   if ($wrapper->value() === NULL) {
// Do not provide a replacement if there is no value.
return NULL;
}

With the [node:field-attachment], I'm getting the e-mail, but it contains this: You can download the file from here: Property 0

Which token should I use to get the url (or the filename) of the actually uploaded file when I edit the node?

Comments

After a couple hours of

pene's picture

After a couple hours of testing, I must admit that this problem can not be solved with tokens ([node:field-attachment:file:x:name] doesn't help either). However php always does, as you can see Drupal's built-in db_select method under:

<?php
    $query
= db_select('file_managed', 'fm');
   
$query->fields('fm', array('filename'))
    ->
orderBy('fid', 'DESC')
    ->
range(0,1);

   
$result = $query->execute()->fetchField();

    echo
$result;
?>

I know, this isn't the best way, but it's enough for lil' sites, and may help somebody sometime to get a link for the last uploaded file.

Updated Entity API

firfin's picture

Working with tokens now. At least with entity token enabled and with a multivalued field I can use the following token to get the files' URL. Substitute field-foto-s with your field name. And 0 with the number of the photo you want (0 is first picture, 1 is second etc)
[node:field-foto-s:0:file:url]

Also see [#1440928]

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: