You are here

class D7LocationFieldDeriver in Geolocation Field 8.3

Deriver geolocation field config migrations of Drupal 7 Location CCK fields.

This deriver class derives field storage, field instance and field widget migrations of geolocation fields while the source field is mapped to an address field.

Hierarchy

Expanded class hierarchy of D7LocationFieldDeriver

3 string references to 'D7LocationFieldDeriver'
d7_field_instance_location.yml in modules/geolocation_address/migrations/d7_field_instance_location.yml
modules/geolocation_address/migrations/d7_field_instance_location.yml
d7_field_instance_widget_settings_location.yml in modules/geolocation_address/migrations/d7_field_instance_widget_settings_location.yml
modules/geolocation_address/migrations/d7_field_instance_widget_settings_location.yml
d7_field_location.yml in modules/geolocation_address/migrations/d7_field_location.yml
modules/geolocation_address/migrations/d7_field_location.yml

File

modules/geolocation_address/src/Plugin/migrate/D7LocationFieldDeriver.php, line 19

Namespace

Drupal\geolocation_address\Plugin\migrate
View source
class D7LocationFieldDeriver extends DeriverBase {
  use MigrationDeriverTrait;

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $source = $this
      ->getSourcePlugin($base_plugin_definition['source']['plugin']);
    assert($source instanceof DrupalSqlBase);
    try {
      $source
        ->checkRequirements();
    } catch (RequirementsException $e) {

      // If the source plugin requirements failed, that means we do not have a
      // Drupal source database configured - there is nothing to generate.
      return $this->derivatives;
    }
    $derivatives = [];
    try {
      foreach ($source as $row) {
        assert($row instanceof Row);
        $entity_type = $row
          ->getSourceProperty('entity_type');
        $bundle = $row
          ->getSourceProperty('bundle');
        $values = [
          'entity_type' => $entity_type,
          'bundle' => $bundle,
        ];
        $derivative_id = $bundle !== NULL ? $entity_type . PluginBase::DERIVATIVE_SEPARATOR . $bundle : $entity_type;
        $derivatives[$derivative_id] = $values;
      }
    } catch (\Exception $e) {
      return $this->derivatives;
    }

    // Using the same derivative for field storage and field instance
    // migrations. Field storage migrations are always derived by their parent
    // entity type. Field instance migrations are derived by parent entity type
    // and by bundle. For bundle-less entities (like user), the bundle will be
    // the entity type, like "d7_field_location_instance:user:user".
    foreach ($derivatives as $derivative_id => $values) {
      [
        'entity_type' => $entity_type,
        'bundle' => $bundle,
      ] = $values;
      $derivative_definition = $base_plugin_definition;
      $derivative_definition['source']['entity_type'] = $entity_type;
      if ($bundle !== NULL) {
        $derivative_definition['source']['bundle'] = $bundle;
      }

      // Process dependencies.
      $migration_required_deps = $derivative_definition['migration_dependencies']['required'] ?? [];
      $storage_migration_dep_key = array_search('d7_field_location', $migration_required_deps);
      if ($storage_migration_dep_key !== FALSE) {
        $derivative_definition['migration_dependencies']['required'][$storage_migration_dep_key] .= PluginBase::DERIVATIVE_SEPARATOR . $entity_type;
      }
      $instance_migration_dep_key = array_search('d7_field_instance_location', $migration_required_deps);
      if ($instance_migration_dep_key !== FALSE) {
        $derivative_definition['migration_dependencies']['required'][$instance_migration_dep_key] .= implode(PluginBase::DERIVATIVE_SEPARATOR, array_filter([
          $entity_type,
          $bundle,
        ]));
      }
      $this->derivatives[$derivative_id] = $derivative_definition;
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
D7LocationFieldDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
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.