addBundleFieldProcesses example


  }

  /** * {@inheritdoc} */
  public function addEntityFieldProcesses(MigrationInterface $migration$entity_type_id) {
    $core = $this->getCoreVersion($migration);
    $fields = $this->getAllFields($core);
    if (!empty($fields[$entity_type_id])  && is_array($fields[$entity_type_id])) {
      foreach ($fields[$entity_type_id] as $bundle => $fields) {
        $this->addBundleFieldProcesses($migration$entity_type_id$bundle);
      }
    }
  }

  /** * {@inheritdoc} */
  public function addBundleFieldProcesses(MigrationInterface $migration$entity_type_id$bundle) {
    $core = $this->getCoreVersion($migration);
    $fields = $this->getAllFields($core);
    $plugin_definition = $migration->getPluginDefinition();
    
$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;

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

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

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

}

  public function testAddFields() {
    $this->migrateFields();
    $field_discovery = $this->container->get('migrate_drupal.field_discovery');
    $migration_plugin_manager = $this->container->get('plugin.manager.migration');
    $definition = [
      'migration_tags' => ['Drupal 6'],
    ];
    $migration = $migration_plugin_manager->createStubMigration($definition);
    $field_discovery->addBundleFieldProcesses($migration, 'node', 'test_planet');
    $actual_process = $migration->getProcess();
    $expected_process = [
      'field_multivalue' => [
        0 => [
          'plugin' => 'get',
          'source' => 'field_multivalue',
        ],
      ],
      'field_test_text_single_checkbox' => [
        0 => [
          'plugin' => 'sub_process',
          
$values['destination']['default_bundle'] = $node_type;

        // If this migration is based on the d6_node_revision migration or         // is for translations of nodes, it should explicitly depend on the         // corresponding d6_node variant.         if (in_array($base_plugin_definition['id']['d6_node_revision', 'd6_node_translation'])) {
          $values['migration_dependencies']['required'][] = 'd6_node:' . $node_type;
        }

        /** @var \Drupal\migrate\Plugin\Migration $migration */
        $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($values);
        $this->fieldDiscovery->addBundleFieldProcesses($migration, 'node', $node_type);
        $this->derivatives[$node_type] = $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 6 source database.     }

    return $this->derivatives;
  }

  public function assertFieldProcess(FieldDiscoveryInterface $field_discovery, MigrationPluginManagerInterface $migration_plugin_manager$core$field_plugin_method = NULL, array $expected_process = []$entity_type_id = NULL, $bundle = NULL) {
    $definition = [
      'migration_tags' => ['Drupal ' . $core],
      'field_plugin_method' => $field_plugin_method,
    ];
    $migration = $migration_plugin_manager->createStubMigration($definition);
    if ($bundle) {
      $field_discovery->addBundleFieldProcesses($migration$entity_type_id$bundle);
    }
    elseif ($entity_type_id) {
      $field_discovery->addEntityFieldProcesses($migration$entity_type_id);
    }
    else {
      $field_discovery->addAllFieldProcesses($migration);
    }
    $actual_process = $migration->getProcess();
    $this->assertSame($expected_process$actual_process);
  }

  
Home | Imprint | This part of the site doesn't use cookies.