X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmigrate%2Fsrc%2FPlugin%2Fmigrate%2Fprocess%2FSubstr.php;h=b8f5f497b8b3ae6fa86b5b59079165eeb1d728a5;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=1f852a9238b69460dab82157d9f4c7598904b6d2;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/migrate/src/Plugin/migrate/process/Substr.php b/web/core/modules/migrate/src/Plugin/migrate/process/Substr.php index 1f852a923..b8f5f497b 100644 --- a/web/core/modules/migrate/src/Plugin/migrate/process/Substr.php +++ b/web/core/modules/migrate/src/Plugin/migrate/process/Substr.php @@ -6,25 +6,23 @@ use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use Drupal\migrate\MigrateException; -use Drupal\Component\Utility\Unicode; /** * Returns a substring of the input value. * * The substr process plugin returns the portion of the input value specified by - * the start and length parameters. This is a wrapper around the PHP substr() - * function. + * the start and length parameters. This is a wrapper around mb_substr(). * * Available configuration keys: * - start: (optional) The returned string will start this many characters after - * the beginning of the string. Defaults to NULL. + * the beginning of the string, defaults to 0. * - length: (optional) The maximum number of characters in the returned - * string. Defaults to NULL. + * string, defaults to NULL. * - * If start is NULL and length is an integer, the start position is the + * If start is 0 and length is an integer, the start position is the * beginning of the string. If start is an integer and length is NULL, the * substring starting from the start position until the end of the string will - * be returned. If both start and length are NULL the entire string is returned. + * be returned. If start is 0 and length is NULL the entire string is returned. * * Example: * @@ -33,19 +31,33 @@ use Drupal\Component\Utility\Unicode; * new_text_field: * plugin: substr * source: some_text_field - * start: 6 - * length: 10 + * start: 6 + * length: 10 * @endcode - * * If some_text_field was 'Marie Skłodowska Curie' then * $destination['new_text_field'] would be 'Skłodowska'. * * The PHP equivalent of this is: - * * @code * $destination['new_text_field'] = substr($source['some_text_field'], 6, 10); * @endcode * + * The substr plugin requires that the source value is not empty. If empty + * values are expected, combine skip_on_empty process plugin to the pipeline: + * @code + * process: + * new_text_field: + * - + * plugin: skip_on_empty + * method: process + * source: some_text_field + * - + * plugin: substr + * source: some_text_field + * start: 6 + * length: 10 + * @endcode + * * @see \Drupal\migrate\Plugin\MigrateProcessInterface * * @MigrateProcessPlugin( @@ -71,7 +83,7 @@ class Substr extends ProcessPluginBase { } // Use optional start or length to return a portion of $value. - $new_value = Unicode::substr($value, $start, $length); + $new_value = mb_substr($value, $start, $length); return $new_value; }