You are here

public function StrReplace::transform in Migrate Plus 8.5

Same name and namespace in other branches
  1. 8.4 src/Plugin/migrate/process/StrReplace.php \Drupal\migrate_plus\Plugin\migrate\process\StrReplace::transform()

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides ProcessPluginBase::transform

File

src/Plugin/migrate/process/StrReplace.php, line 84

Class

StrReplace
Uses the str_replace() method on a source string.

Namespace

Drupal\migrate_plus\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (!isset($this->configuration['search'])) {
    throw new MigrateException('"search" must be configured.');
  }
  if (!isset($this->configuration['replace'])) {
    throw new MigrateException('"replace" must be configured.');
  }
  $this->multiple = is_array($value);
  $this->configuration += [
    'case_insensitive' => FALSE,
    'regex' => FALSE,
  ];
  $function = 'str_replace';
  if ($this->configuration['case_insensitive']) {
    $function = 'str_ireplace';
  }
  if ($this->configuration['regex']) {
    $function = 'preg_replace';
  }
  return $function($this->configuration['search'], $this->configuration['replace'], $value);
}