Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Substr.php

function Substr::transform

Overrides ProcessPluginBase::transform

File

core/modules/migrate/src/Plugin/migrate/process/Substr.php, line 71

Class

Substr
Returns a substring of the input value.

Namespace

Drupal\migrate\Plugin\migrate\process

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal