You are here

public function MigrationDefinitionCreator::buildMigrationDefinition in GatherContent 8.5

Builds the migration definition.

2 calls to MigrationDefinitionCreator::buildMigrationDefinition()
MigrationDefinitionCreator::getDefinitions in src/MigrationDefinitionCreator.php
Return the concatenated definitions created from the grouped data.
MigrationDefinitionCreator::setReferenceDependencies in src/MigrationDefinitionCreator.php
Set reference migration dependencies and processes.

File

src/MigrationDefinitionCreator.php, line 345

Class

MigrationDefinitionCreator
Create dynamic migration definitions.

Namespace

Drupal\gathercontent

Code

public function buildMigrationDefinition(array $baseData, array $data, $plugin) {
  $entityDefinition = $this->entityTypeManager
    ->getDefinition($baseData['entityType']);
  $baseDataLabel = [
    $this->mapping
      ->getGathercontentProject(),
    $this->mapping
      ->getGathercontentTemplate(),
    $this->mapping
      ->getMappedEntityType(),
  ];
  $language = $this->siteDefaultLangCode;
  if (isset($data['language'])) {
    $language = $data['language'];
  }
  $definition = self::BASIC_SCHEMA_GC_DESTINATION_CONFIG;
  $definition['langcode'] = $language;
  $definition['id'] = implode('_', $baseData) . "_{$language}";
  $definition['label'] = implode('_', $baseDataLabel) . "_{$language}";
  $definition['source']['projectId'] = $this->mapping
    ->getGathercontentProjectId();
  $definition['source']['templateId'] = $this->mapping
    ->getGathercontentTemplateId();
  $definition['source']['templateName'] = $this->mapping
    ->getGathercontentTemplate();
  $definition['source']['metatagFields'] = $data['metatag_elements'] ?? [];
  $bundleKey = $entityDefinition
    ->getKey('bundle');
  if (!empty($bundleKey)) {
    $definition['process'][$bundleKey] = [
      'plugin' => 'default_value',
      'default_value' => $baseData['contentType'],
    ];
  }
  $definition['destination']['plugin'] = $plugin . ':' . $baseData['entityType'];
  $this
    ->setDefinitionFieldProperties($definition, $data, $entityDefinition);
  if (!$this
    ->isNewConfiguration($definition['id'])) {
    $config = $this->configFactory
      ->getEditable('migrate_plus.migration.' . $definition['id']);
    $config
      ->delete();
  }
  return $definition;
}