2

I want to add node-field data into the web from block via tokes as with Webform 7.x-4.1 this should work.

But tokens from custom fields are not available in a webform(block) ?

[node:title] and [node:author] work but [node:field_mycustumfield] or [node:field-mycustumfield] does not work .

Any help appreciated!

  • you need create custom token use hook_token_info and hook_tokens – vinhdv Aug 31 '18 at 8:04
0

I know this was asked years ago, but if someone comes across this, here's the solution:

https://www.drupal.org/node/919760#comment-9973163

Node tokens in a Webform block refer to the Webform node, not the current node which the block is placed on. Currently, the Token module does not expose node tokens to the Webform block.

There is a patch in this thread which exposes tokens to the Webform block, and should do just what you need. Hopefully it will get committed to the Token module soon. :-)

As an alternative, you could also use https://www.drupal.org/project/token_custom and create a custom token that exposes the field you need.

0

You can use function hook_tokens

it is provide replacement values for placeholder tokens.

Example code:

function MYMODULE_token_info() {
  $info['tokens']['node']['title_first_letter'] = array(
    'name' => t('Title first letter'),
    'description' => t('Generates first letter of node title')
  );
  return $info;
}

function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  if ($type == 'node' && !empty($data['node'])) {
    $node = $data['node'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'title_first_letter':
          $replacements[$original] = substr($node->title, 0, 1); // get first letter of the title here 
          break;
      }
    }
  }
  return $replacements;
}

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.