Same name and namespace in other branches
  1. 8.9.x core/modules/migrate/src/Plugin/migrate/process/Explode.php \Drupal\migrate\Plugin\migrate\process\Explode
  2. 9 core/modules/migrate/src/Plugin/migrate/process/Explode.php \Drupal\migrate\Plugin\migrate\process\Explode

Hierarchy

  • class \Drupal\migrate\Plugin\migrate\process\Explode extends \Drupal\migrate\ProcessPluginBase

Expanded class hierarchy of Explode

1 file declares its use of Explode
ExplodeTest.php in core/modules/migrate/tests/src/Unit/process/ExplodeTest.php

File

core/modules/migrate/src/Plugin/migrate/process/Explode.php, line 92

Namespace

Drupal\migrate\Plugin\migrate\process
View source
class Explode extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    if (empty($this->configuration['delimiter'])) {
      throw new MigrateException('delimiter is empty');
    }
    $strict = array_key_exists('strict', $this->configuration) ? $this->configuration['strict'] : TRUE;
    if ($strict && !is_string($value)) {
      throw new MigrateException(sprintf('%s is not a string', var_export($value, TRUE)));
    }
    elseif (!$strict) {

      // Check if the incoming value can cast to a string.
      $original = $value;
      if (!is_string($original) && $original != ($value = @strval($value))) {
        throw new MigrateException(sprintf('%s cannot be casted to a string', var_export($original, TRUE)));
      }

      // Empty strings should be exploded to empty arrays.
      if ($value === '') {
        return [];
      }
    }
    $limit = $this->configuration['limit'] ?? PHP_INT_MAX;
    return explode($this->configuration['delimiter'], $value, $limit);
  }

  /**
   * {@inheritdoc}
   */
  public function multiple() {
    return TRUE;
  }

}

Members