diff --git a/core/modules/migrate/src/Plugin/migrate/process/Substr.php b/core/modules/migrate/src/Plugin/migrate/process/Substr.php index 8ebc98c..fe99e59 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Substr.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Substr.php @@ -23,6 +23,11 @@ class Substr extends ProcessPluginBase { * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + // Don't fail if $value is NULL. For instance during a stub-migration. + if (is_null($value)) { + return $value; + } + $start = isset($this->configuration['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.'); diff --git a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php index fb84509..439e5aa 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubstrTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubstrTest.php @@ -89,4 +89,13 @@ public function testLengthIsString() { $this->plugin->transform(['foo'], $this->migrateExecutable, $this->row, 'destinationproperty'); } + /** + * Tests that Substr does not throw an Exception when the value is NULL + */ + public function testSubstrNull() { + $configuration = []; + $this->plugin = new Substr($configuration, 'map', []); + $value = $this->plugin->transform(NULL, $this->migrateExecutable, $this->row, 'destinationproperty'); + $this->assertNull($value); + } }