WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Writing a custom Drupal 8 migration plugin for field processing

Submitted by barnettech on Wed, 01/30/2019 - 09:49

This file goes within the custom/d7custommigration/src/Plugin/migrate/process directory


/**
 * @file
 * Contains \Drupal\complimentmigration\Plugin\migrate\process\StripOutHTML.
 */

namespace Drupal\complimentmigration\Plugin\migrate\process;

use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * @MigrateProcessPlugin(
 *   id = "stripouthtml"
 * )
 */
 class StripOutHTML extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    // $value: cut off .Z and replace by Z
    if( is_null($value) )
    {
      return $value;
    }

    // $old = $value;

    $value= strip_tags($value);
    // drush_print_r( $old . ' -> ' . $value );

    return $value;
  }

}