class ParagraphsStripFieldPrefix

Remove 'field_' from the start of a string.

Plugin annotation


@MigrateProcessPlugin(
  id = "paragraphs_strip_field_prefix"
)

Hierarchy

Expanded class hierarchy of ParagraphsStripFieldPrefix

See also

\Drupal\migrate\Plugin\MigrateProcessInterface

File

paragraphs/src/Plugin/migrate/process/ParagraphsStripFieldPrefix.php, line 21

Namespace

Drupal\paragraphs\Plugin\migrate\process
View source
class ParagraphsStripFieldPrefix extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    if (!is_string($value)) {
      throw new MigrateException('The input value must be a string.');
    }
    if (mb_substr($value, 0, FieldCollection::FIELD_COLLECTION_PREFIX_LENGTH) === 'field_') {
      return mb_substr($value, FieldCollection::FIELD_COLLECTION_PREFIX_LENGTH);
    }
    else {
      return $value;
    }
  }

}

Members