public function Substr::transform in Drupal 10
Same name and namespace in other branches
- 8 core/modules/migrate/src/Plugin/migrate/process/Substr.php \Drupal\migrate\Plugin\migrate\process\Substr::transform()
- 9 core/modules/migrate/src/Plugin/migrate/process/Substr.php \Drupal\migrate\Plugin\migrate\process\Substr::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
mixed The newly transformed value.
Overrides ProcessPluginBase::transform
File
- core/
modules/ migrate/ src/ Plugin/ migrate/ process/ Substr.php, line 73
Class
- Substr
- Returns a substring of the input value.
Namespace
Drupal\migrate\Plugin\migrate\processCode
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$start = $this->configuration['start'] ?? 0;
if (!is_int($start)) {
throw new MigrateException('The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.');
}
$length = $this->configuration['length'] ?? NULL;
if ($length !== NULL && !is_int($length)) {
throw new MigrateException('The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.');
}
if (!is_string($value)) {
throw new MigrateException('The input value must be a string.');
}
// Use optional start or length to return a portion of $value.
return mb_substr($value, $start, $length);
}