You are here

public function BlockPluginId::transform in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block/src/Plugin/migrate/process/BlockPluginId.php \Drupal\block\Plugin\migrate\process\BlockPluginId::transform()
  2. 10 core/modules/block/src/Plugin/migrate/process/BlockPluginId.php \Drupal\block\Plugin\migrate\process\BlockPluginId::transform()

Set the block plugin id.

Overrides ProcessPluginBase::transform

File

core/modules/block/src/Plugin/migrate/process/BlockPluginId.php, line 99

Class

BlockPluginId
Plugin annotation @MigrateProcessPlugin( id = "block_plugin_id" )

Namespace

Drupal\block\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (is_array($value)) {
    list($module, $delta) = $value;
    switch ($module) {
      case 'aggregator':
        list($type, $id) = explode('-', $delta);
        if ($type == 'feed') {
          return 'aggregator_feed_block';
        }
        break;
      case 'menu':
        return "system_menu_block:{$delta}";
      case 'block':
        if ($this->blockContentStorage) {

          // This BC layer is included because if the plugin constructor was
          // called in the legacy way with a migration_lookup process plugin,
          // it  may have been preconfigured with a different migration to
          // look up against. While this is unlikely, for maximum BC we will
          // continue to use the plugin to do the lookup if it is provided,
          // and support for this will be removed in Drupal 9.
          if ($this->migrationPlugin) {
            $block_id = $this->migrationPlugin
              ->transform($delta, $migrate_executable, $row, $destination_property);
          }
          else {
            $lookup_result = $this->migrateLookup
              ->lookup([
              'd6_custom_block',
              'd7_custom_block',
            ], [
              $delta,
            ]);
            if ($lookup_result) {
              $block_id = $lookup_result[0]['id'];
            }
          }
          if (!empty($block_id)) {
            return 'block_content:' . $this->blockContentStorage
              ->load($block_id)
              ->uuid();
          }
        }
        break;
      default:
        break;
    }
  }
  else {
    return $value;
  }
}