EntityBlock.php

Same filename in other branches
  1. 9 core/modules/block/src/Plugin/migrate/destination/EntityBlock.php
  2. 8.9.x core/modules/block/src/Plugin/migrate/destination/EntityBlock.php
  3. 11.x core/modules/block/src/Plugin/migrate/destination/EntityBlock.php

Namespace

Drupal\block\Plugin\migrate\destination

File

core/modules/block/src/Plugin/migrate/destination/EntityBlock.php

View source
<?php

namespace Drupal\block\Plugin\migrate\destination;

use Drupal\Core\Config\Schema\SchemaIncompleteException;
use Drupal\migrate\Attribute\MigrateDestination;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
use Drupal\migrate\Row;

/**
 * Migrate destination for block entity.
 */
class EntityBlock extends EntityConfigBase {
    
    /**
     * {@inheritdoc}
     */
    protected function getEntityId(Row $row) {
        // Try to find the block by its plugin ID and theme.
        $properties = [
            'plugin' => $row->getDestinationProperty('plugin'),
            'theme' => $row->getDestinationProperty('theme'),
        ];
        $blocks = array_keys($this->storage
            ->loadByProperties($properties));
        return reset($blocks);
    }
    
    /**
     * {@inheritdoc}
     */
    public function import(Row $row, array $old_destination_id_values = []) {
        try {
            $entity_ids = parent::import($row, $old_destination_id_values);
        } catch (SchemaIncompleteException $e) {
            throw new MigrateException($e->getMessage());
        }
        return $entity_ids;
    }

}

Classes

Title Deprecated Summary
EntityBlock Migrate destination for block entity.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.