You are here

public function ContentEntity::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php \Drupal\migrate_drupal\Plugin\migrate\source\ContentEntity::__construct()

Constructs a \Drupal\Component\Plugin\PluginBase object.

Parameters

array $configuration: A configuration array containing information about the plugin instance.

string $plugin_id: The plugin_id for the plugin instance.

mixed $plugin_definition: The plugin implementation definition.

Overrides SourcePluginBase::__construct

File

core/modules/migrate_drupal/src/Plugin/migrate/source/ContentEntity.php, line 116

Class

ContentEntity
Source plugin to get content entities from the current version of Drupal.

Namespace

Drupal\migrate_drupal\Plugin\migrate\source

Code

public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
  if (empty($plugin_definition['entity_type'])) {
    throw new InvalidPluginDefinitionException($plugin_id, 'Missing required "entity_type" definition.');
  }
  $this->entityTypeManager = $entity_type_manager;
  $this->entityFieldManager = $entity_field_manager;
  $this->entityTypeBundleInfo = $entity_type_bundle_info;
  $this->entityType = $this->entityTypeManager
    ->getDefinition($plugin_definition['entity_type']);
  if (!$this->entityType instanceof ContentEntityTypeInterface) {
    throw new InvalidPluginDefinitionException($plugin_id, sprintf('The entity type (%s) is not supported. The "content_entity" source plugin only supports content entities.', $plugin_definition['entity_type']));
  }
  if (!empty($configuration['bundle'])) {
    if (!$this->entityType
      ->hasKey('bundle')) {
      throw new \InvalidArgumentException(sprintf('A bundle was provided but the entity type (%s) is not bundleable.', $plugin_definition['entity_type']));
    }
    $bundle_info = array_keys($this->entityTypeBundleInfo
      ->getBundleInfo($this->entityType
      ->id()));
    if (!in_array($configuration['bundle'], $bundle_info, TRUE)) {
      throw new \InvalidArgumentException(sprintf('The provided bundle (%s) is not valid for the (%s) entity type.', $configuration['bundle'], $plugin_definition['entity_type']));
    }
  }
  parent::__construct($configuration + $this->defaultConfiguration, $plugin_id, $plugin_definition, $migration);
}