function ContentEntity::__construct

Overrides SourcePluginBase::__construct

File

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

Class

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

Namespace

Drupal\migrate\Plugin\migrate\source

Code

public function __construct(array $configuration, string $plugin_id, array $plugin_definition, MigrationInterface $migration, protected EntityTypeManagerInterface $entityTypeManager, protected EntityFieldManagerInterface $entityFieldManager, protected EntityTypeBundleInfoInterface $entityTypeBundleInfo) {
  if (empty($plugin_definition['entity_type'])) {
    throw new InvalidPluginDefinitionException($plugin_id, 'Missing required "entity_type" definition.');
  }
  $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);
}

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