You are here

RealnameReplaceToken.php in Real Name 2.x

Same filename and directory in other branches
  1. 8 src/Plugin/migrate/process/RealnameReplaceToken.php

File

src/Plugin/migrate/process/RealnameReplaceToken.php
View source
<?php

namespace Drupal\realname\Plugin\migrate\process;

use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;

/**
 * If the source evaluates to empty, we skip the current row.
 *
 * @MigrateProcessPlugin(
 *   id = "realname_replace_token",
 *   handle_multiples = TRUE
 * )
 */
class RealnameReplaceToken extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    list($realname_pattern) = $value;

    // Previous D7 realname token need to be replaced by D8 core token.
    //
    // At least two tokens may exists:
    // - [user:name-raw]
    // - [current-user:name-raw].
    return str_ireplace(':name-raw]', ':account-name]', $realname_pattern);
  }

}

Classes

Namesort descending Description
RealnameReplaceToken If the source evaluates to empty, we skip the current row.