ReferenceBase.php in Drupal 10
File
core/modules/migrate_drupal/src/Plugin/migrate/field/ReferenceBase.php
View source
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
abstract class ReferenceBase extends FieldPluginBase {
protected abstract function getEntityTypeMigrationId();
protected abstract function entityId();
public function alterFieldInstanceMigration(MigrationInterface $migration) {
parent::alterFieldInstanceMigration($migration);
$migration_dependencies = $migration
->getMigrationDependencies();
array_push($migration_dependencies['required'], $this
->getEntityTypeMigrationId());
$migration_dependencies['required'] = array_unique($migration_dependencies['required']);
$migration
->set('migration_dependencies', $migration_dependencies);
}
public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'sub_process',
'source' => $field_name,
'process' => [
'target_id' => $this
->entityId(),
],
];
$migration
->setProcessOfProperty($field_name, $process);
}
public function getFieldWidgetMap() {
return [
$this->pluginId . '_select' => 'options_select',
$this->pluginId . '_buttons' => 'options_buttons',
$this->pluginId . '_autocomplete' => 'entity_reference_autocomplete_tags',
];
}
}