You are here

public function D7EckDeriver::getDerivativeDefinitions in Entity Construction Kit (ECK) 8

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/migrate/D7EckDeriver.php, line 70

Class

D7EckDeriver
Deriver for Drupal 7 ECK.

Namespace

Drupal\eck\Plugin\migrate

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $eck_types = static::getSourcePlugin('d7_eck_entity_type');
  $eck_bundles = static::getSourcePlugin('d7_eck_entity_bundle');
  try {
    $eck_types
      ->checkRequirements();
    $eck_bundles
      ->checkRequirements();
  } catch (RequirementsException $e) {

    // If the requirements failed, there is nothing to generate.
    return $this->derivatives;
  }
  try {
    foreach ($eck_types as $type_row) {
      $entity_type = $type_row
        ->getSourceProperty('name');
      foreach (static::getSourcePlugin('d7_eck_entity_bundle') as $bundle_row) {
        $bundle = $bundle_row
          ->getSourceProperty('name');
        $bundle_entity_type = $bundle_row
          ->getSourceProperty('entity_type');

        // Not for this entity type.
        if ($bundle_entity_type != $entity_type) {
          continue;
        }
        $values = $base_plugin_definition;
        $values['label'] = t('@label (@type)', [
          '@label' => $bundle_row
            ->getSourceProperty('label'),
          '@type' => $type_row
            ->getSourceProperty('name'),
        ]);
        $values['source']['entity_type'] = $entity_type;
        $values['source']['bundle'] = $bundle;
        $values['destination']['plugin'] = "entity:{$entity_type}";
        $values['destination']['default_bundle'] = $bundle;

        /** @var \Drupal\migrate\Plugin\Migration $migration */
        $migration = \Drupal::service('plugin.manager.migration')
          ->createStubMigration($values);
        $source_plugin = $migration
          ->getSourcePlugin();
        $source_plugin
          ->rewind();

        /** @var \Drupal\migrate\Row $row */
        $row = $source_plugin
          ->current();
        if (!$row) {
          continue;
        }
        $this->fieldDiscovery
          ->addBundleFieldProcesses($migration, $entity_type, $bundle);
        $this->derivatives[$entity_type . ':' . $bundle] = $migration
          ->getPluginDefinition();
      }
    }
  } catch (DatabaseExceptionWrapper $e) {

    // Once we begin iterating the source plugin it is possible that the
    // source tables will not exist. This can happen when the
    // MigrationPluginManager gathers up the migration definitions but we do
    // not actually have a Drupal 7 source database.
  }
  return $this->derivatives;
}