You are here

public function D7FieldablePanelsPaneDeriver::getDerivativeDefinitions in Fieldable Panels Panes (FPP) 1.0.x

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/D7FieldablePanelsPaneDeriver.php, line 73

Class

D7FieldablePanelsPaneDeriver
Deriver for Drupal 7 fieldable panel panes based on pane types.

Namespace

Drupal\fieldable_panels_panes\Plugin\migrate

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  if (in_array('translation', $base_plugin_definition['migration_tags']) && !$this->includeTranslations) {

    // Refuse to generate anything.
    return $this->derivatives;
  }
  $types = static::getSourcePlugin('d7_fieldable_panels_pane_type');
  try {
    $types
      ->checkRequirements();
  } catch (RequirementsException $e) {

    // If the d7_node_type requirements failed, that means we do not have a
    // Drupal source database configured - there is nothing to generate.
    return $this->derivatives;
  }
  try {
    foreach ($types as $row) {
      $bundle = $row
        ->getSourceProperty('name');
      $values = $base_plugin_definition;
      $values['label'] = $this
        ->t('@label (@type)', [
        '@label' => $values['label'],
        '@type' => $row
          ->getSourceProperty('name'),
      ]);
      $values['source']['bundle'] = $bundle;
      $values['destination']['default_bundle'] = $bundle;

      // If this migration is based on the d7_fieldable_panels_pane_revision
      // migration or is for translations of fieldable panel panes, it should
      // explicitly depend on the corresponding d7_fieldable_panels_pane
      // variant.
      if ($base_plugin_definition['id'] == [
        'd7_fieldable_panels_pane_revision',
      ] || in_array('translation', $base_plugin_definition['migration_tags'])) {
        $values['migration_dependencies']['required'][] = 'd7_fieldable_panels_pane:' . $bundle;
      }

      /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
      $migration = \Drupal::service('plugin.manager.migration')
        ->createStubMigration($values);
      $this->fieldDiscovery
        ->addBundleFieldProcesses($migration, 'fieldable_panels_pane', $bundle);
      $this->derivatives[$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;
}