3 namespace Drupal\user\Plugin\migrate\process;
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\ProcessPluginBase;
8 use Drupal\migrate\Row;
11 * Plugin to replace !tokens with [tokens].
13 * @MigrateProcessPlugin(
14 * id = "convert_tokens",
15 * handle_multiples = TRUE
18 class ConvertTokens extends ProcessPluginBase {
23 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
25 '!site' => '[site:name]',
26 '!username' => '[user:name]',
27 '!mailto' => '[user:mail]',
28 '!login_uri' => '[site:login-url]',
29 '!uri_brief' => '[site:url-brief]',
30 '!edit_uri' => '[user:edit-url]',
31 '!login_url' => '[user:one-time-login-url]',
32 '!uri' => '[site:url]',
33 '!date' => '[date:medium]',
37 // Given that our source is a database column that could hold a NULL
38 // value, sometimes that filters down to here. str_replace() cannot
39 // handle NULLs as the subject, so we reset to an empty string.
40 if (is_null($value)) {
44 if (is_string($value)) {
45 return str_replace(array_keys($tokens), $tokens, $value);
48 throw new MigrateException('Value must be a string.');