3

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?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Pene
  • 93
  • 1
  • 6
  • 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: `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. – Pene Nov 09 '12 at 18:55

1 Answers1

2

2 solutions

1 - You can write a simple module that hooks the node submit and handle the URL there and then mail it.

2 - You can create an action in rules module to execute a custom PHP code. There you will get all details of node in $node. You can also send an email using drupal mail API

mantish
  • 400
  • 3
  • 12