Skip to content

Instantly share code, notes, and snippets.

@juampynr
Last active January 11, 2016 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juampynr/e949f2c20e4ea92b26b1 to your computer and use it in GitHub Desktop.
Save juampynr/e949f2c20e4ea92b26b1 to your computer and use it in GitHub Desktop.

This is the output when the field has a value:

juampy@Juampy/var/www/drupal8(8.0.x)$ drush scr script
string(32) "Some text Un articulo more text."

This is the output when the field does not have a value:

juampy@Juampy/var/www/drupal8(8.0.x)$ drush scr script
string(38) "Some text [node:field_slug] more text."
<?php
use Drupal\node\Entity\Node;
$node = Node::load(102);
$text = 'Some text [node:field_slug] more text.';
$token_service = \Drupal::service('token');
$processed_text = $token_service->replace($text, ['node' => $node]);
var_dump($processed_text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment