You are here

protected function FieldDiscovery::getFieldPlugin in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/src/FieldDiscovery.php \Drupal\migrate_drupal\FieldDiscovery::getFieldPlugin()
  2. 10 core/modules/migrate_drupal/src/FieldDiscovery.php \Drupal\migrate_drupal\FieldDiscovery::getFieldPlugin()

Returns the appropriate field plugin for a given field type.

Parameters

string $field_type: The field type.

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration to retrieve the plugin for.

Return value

\Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface|\Drupal\migrate_drupal\Plugin\MigrateFieldInterface|bool The appropriate field or cck plugin to process this field type.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\InvalidArgumentException

2 calls to FieldDiscovery::getFieldPlugin()
FieldDiscovery::addBundleFieldProcesses in core/modules/migrate_drupal/src/FieldDiscovery.php
Adds the field processes for a bundle to a migration.
FieldDiscoveryTestClass::getFieldPlugin in core/modules/migrate_drupal/tests/modules/field_discovery_test/src/FieldDiscoveryTestClass.php
Returns the appropriate field plugin for a given field type.
1 method overrides FieldDiscovery::getFieldPlugin()
FieldDiscoveryTestClass::getFieldPlugin in core/modules/migrate_drupal/tests/modules/field_discovery_test/src/FieldDiscoveryTestClass.php
Returns the appropriate field plugin for a given field type.

File

core/modules/migrate_drupal/src/FieldDiscovery.php, line 194

Class

FieldDiscovery
Provides field discovery for Drupal 6 & 7 migrations.

Namespace

Drupal\migrate_drupal

Code

protected function getFieldPlugin($field_type, MigrationInterface $migration) {
  $core = $this
    ->getCoreVersion($migration);
  if (!isset($this->fieldPluginCache[$core][$field_type])) {
    try {
      $plugin_id = $this->fieldPluginManager
        ->getPluginIdFromFieldType($field_type, [
        'core' => $core,
      ], $migration);
      $plugin = $this->fieldPluginManager
        ->createInstance($plugin_id, [
        'core' => $core,
      ], $migration);
    } catch (PluginNotFoundException $ex) {

      // @todo Replace try/catch block with $plugin = FALSE for Drupal 9.
      // https://www.drupal.org/project/drupal/issues/3033733
      try {

        /** @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManager $cck_plugin_manager */
        $cck_plugin_manager = $this
          ->getCckPluginManager();
        $plugin_id = $cck_plugin_manager
          ->getPluginIdFromFieldType($field_type, [
          'core' => $core,
        ], $migration);
        $plugin = $cck_plugin_manager
          ->createInstance($plugin_id, [
          'core' => $core,
        ], $migration);
      } catch (PluginNotFoundException $ex) {
        $plugin = FALSE;
      }
    }
    $this->fieldPluginCache[$core][$field_type] = $plugin;
  }
  return $this->fieldPluginCache[$core][$field_type];
}