You are here

class D7EckDeriver in Entity Construction Kit (ECK) 8

Deriver for Drupal 7 ECK.

Hierarchy

Expanded class hierarchy of D7EckDeriver

See also

\Drupal\eck\Plugin\migrate\source\d7\EckEntity::query

\Drupal\eck\Plugin\migrate\source\d7\EckEntityTranslation::query

\Drupal\node\Plugin\migrate\D7NodeDeriver

2 string references to 'D7EckDeriver'
d7_eck.yml in migrations/d7_eck.yml
migrations/d7_eck.yml
d7_eck_translation.yml in migrations/d7_eck_translation.yml
migrations/d7_eck_translation.yml

File

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

Namespace

Drupal\eck\Plugin\migrate
View source
class D7EckDeriver extends DeriverBase implements ContainerDeriverInterface {
  use MigrationDeriverTrait;

  /**
   * The base plugin ID this derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * The migration field discovery service.
   *
   * @var \Drupal\migrate_drupal\FieldDiscoveryInterface
   */
  protected $fieldDiscovery;

  /**
   * D7EckDeriver constructor.
   *
   * @param string $base_plugin_id
   *   The base plugin ID for the plugin ID.
   * @param bool $translations
   *   Whether or not to include translations.
   * @param \Drupal\migrate_drupal\FieldDiscoveryInterface $field_discovery
   *   The migration field discovery service.
   */
  public function __construct($base_plugin_id, $translations, FieldDiscoveryInterface $field_discovery) {
    $this->basePluginId = $base_plugin_id;
    $this->includeTranslations = $translations;
    $this->fieldDiscovery = $field_discovery;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {

    // Translations don't make sense unless we have content_translation.
    return new static($base_plugin_id, $container
      ->get('module_handler')
      ->moduleExists('content_translation'), $container
      ->get('migrate_drupal.field_discovery'));
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
D7EckDeriver::$basePluginId protected property The base plugin ID this derivative is for.
D7EckDeriver::$fieldDiscovery protected property The migration field discovery service.
D7EckDeriver::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
D7EckDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
D7EckDeriver::__construct public function D7EckDeriver constructor.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
MigrationDeriverTrait::getSourcePlugin public static function Returns a fully initialized instance of a source plugin.