Unverified Commit 16f38cff authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2763637 by Jo Fitzgerald, quietone, hussainweb, timwood, alexpott,...

Issue #2763637 by Jo Fitzgerald, quietone, hussainweb, timwood, alexpott, heddn, mikeryan, phenaproxima, maxocub, BenStallings, catch: D7 taxonomy term fields are not migrated with allowed vocabularies
parent 1dc9a511
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -29,6 +29,15 @@ process:
  description: description
  required: required
  status: 'constants/status'
  allowed_values:
    -
      plugin: sub_process
      source: allowed_vid
      process:
        -
          plugin: migration_lookup
          migration: d7_taxonomy_vocabulary
          source: vid
  settings:
    plugin: d7_field_instance_settings
    source:
+13 −0
Original line number Diff line number Diff line
@@ -23,6 +23,19 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    $field_data = unserialize($field_definition['data']);
    $field_settings = $field_data['settings'];

    // Get taxonomy term reference handler settings from allowed values.
    if ($row->getSourceProperty('type') == 'taxonomy_term_reference') {
      $instance_settings['handler_settings']['sort'] = [
        'field' => '_none',
      ];
      $allowed_values = $row->get('@allowed_values');
      foreach ($allowed_values as $allowed_value) {
        foreach ($allowed_value as $vocabulary) {
          $instance_settings['handler_settings']['target_bundles'][$vocabulary] = $vocabulary;
        }
      }
    }

    // Get entityreference handler settings from source field configuration.
    if ($row->getSourceProperty('type') == "entityreference") {
      $instance_settings['handler'] = 'default:' . $field_settings['target_type'];
+18 −0
Original line number Diff line number Diff line
@@ -128,6 +128,24 @@ public function prepareRow(Row $row) {
    }
    $row->setSourceProperty('translatable', $translatable);

    // Get the vid for each allowed value for taxonomy term reference fields
    // which is used in a migration_lookup in the process pipeline.
    if ($row->getSourceProperty('type') == 'taxonomy_term_reference') {
      $vocabulary = [];
      $data = unserialize($field_definition['data']);
      foreach ($data['settings']['allowed_values'] as $allowed_value) {
        $vocabulary[] = $allowed_value['vocabulary'];
      }
      $query = $this->select('taxonomy_vocabulary', 'v')
        ->fields('v', ['vid'])
        ->condition('machine_name', $vocabulary, 'IN');
      $allowed_vid = $query->execute()->fetchAllAssoc('vid');
      $row->setSourceProperty('allowed_vid', $allowed_vid);
    }

    $field_data = unserialize($row->getSourceProperty('field_data'));
    $row->setSourceProperty('field_settings', $field_data['settings']);

    return parent::prepareRow($row);
  }

+21 −0
Original line number Diff line number Diff line
@@ -79,6 +79,23 @@ protected function assertLinkFields($id, $title_setting) {
    $this->assertSame($title_setting, $field->getSetting('title'));
  }

  /**
   * Asserts the settings of an entity reference field config entity.
   *
   * @param string $id
   *   The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
   * @param string[] $target_bundles
   *   An array of expected target bundles.
   */
  protected function assertEntityReferenceFields($id, array $target_bundles) {
    $field = FieldConfig::load($id);
    $handler_settings = $field->getSetting('handler_settings');
    $this->assertArrayHasKey('target_bundles', $handler_settings);
    foreach ($handler_settings['target_bundles'] as $target_bundle) {
      $this->assertContains($target_bundle, $target_bundles);
    }
  }

  /**
   * Tests migrating D7 field instances to field_config entities.
   */
@@ -120,6 +137,10 @@ public function testFieldInstances() {
    $this->assertLinkFields('node.article.field_link', DRUPAL_DISABLED);
    $this->assertLinkFields('node.blog.field_link', DRUPAL_REQUIRED);

    $this->assertEntityReferenceFields('node.article.field_tags', ['tags']);
    $this->assertEntityReferenceFields('node.forum.taxonomy_forums', ['forums']);
    $this->assertEntityReferenceFields('node.test_content_type.field_term_reference', ['tags', 'test_vocabulary']);

    // Tests that fields created by the Title module are not migrated.
    $title_field = FieldConfig::load('node.test_content_type.title_field');
    $this->assertNull($title_field);
+2 −2
Original line number Diff line number Diff line
@@ -3631,7 +3631,7 @@
  'storage_module' => 'field_sql_storage',
  'storage_active' => '1',
  'locked' => '0',
  'data' => 'a:7:{s:8:"settings";a:3:{s:14:"allowed_values";a:1:{i:0;a:2:{s:10:"vocabulary";s:6:"forums";s:6:"parent";i:0;}}s:21:"options_list_callback";s:28:"i18n_taxonomy_allowed_values";s:23:"entity_translation_sync";b:0;}s:12:"entity_types";a:0:{}s:12:"translatable";s:1:"0";s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:26:"field_data_taxonomy_forums";a:1:{s:3:"tid";s:19:"taxonomy_forums_tid";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:30:"field_revision_taxonomy_forums";a:1:{s:3:"tid";s:19:"taxonomy_forums_tid";}}}}}s:12:"foreign keys";a:1:{s:3:"tid";a:2:{s:5:"table";s:18:"taxonomy_term_data";s:7:"columns";a:1:{s:3:"tid";s:3:"tid";}}}s:7:"indexes";a:1:{s:3:"tid";a:1:{i:0;s:3:"tid";}}s:2:"id";s:1:"5";}',
  'data' => 'a:7:{s:8:"settings";a:3:{s:14:"allowed_values";a:1:{i:0;a:2:{s:10:"vocabulary";s:19:"sujet_de_discussion";s:6:"parent";i:0;}}s:21:"options_list_callback";s:28:"i18n_taxonomy_allowed_values";s:23:"entity_translation_sync";b:0;}s:12:"entity_types";a:0:{}s:12:"translatable";s:1:"0";s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:26:"field_data_taxonomy_forums";a:1:{s:3:"tid";s:19:"taxonomy_forums_tid";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:30:"field_revision_taxonomy_forums";a:1:{s:3:"tid";s:19:"taxonomy_forums_tid";}}}}}s:12:"foreign keys";a:1:{s:3:"tid";a:2:{s:5:"table";s:18:"taxonomy_term_data";s:7:"columns";a:1:{s:3:"tid";s:3:"tid";}}}s:7:"indexes";a:1:{s:3:"tid";a:1:{i:0;s:3:"tid";}}s:2:"id";s:1:"5";}',
  'cardinality' => '1',
  'translatable' => '0',
  'deleted' => '0',
@@ -3841,7 +3841,7 @@
  'storage_module' => 'field_sql_storage',
  'storage_active' => '1',
  'locked' => '0',
  'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:14:"allowed_values";a:1:{i:0;a:2:{s:10:"vocabulary";s:15:"test_vocabulary";s:6:"parent";s:1:"0";}}s:21:"options_list_callback";s:28:"i18n_taxonomy_allowed_values";s:23:"entity_translation_sync";b:0;}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:31:"field_data_field_term_reference";a:1:{s:3:"tid";s:24:"field_term_reference_tid";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:35:"field_revision_field_term_reference";a:1:{s:3:"tid";s:24:"field_term_reference_tid";}}}}}s:12:"foreign keys";a:1:{s:3:"tid";a:2:{s:5:"table";s:18:"taxonomy_term_data";s:7:"columns";a:1:{s:3:"tid";s:3:"tid";}}}s:7:"indexes";a:1:{s:3:"tid";a:1:{i:0;s:3:"tid";}}s:2:"id";s:2:"20";}',
  'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:14:"allowed_values";a:2:{i:0;a:2:{s:10:"vocabulary";s:15:"test_vocabulary";s:6:"parent";s:1:"0";}i:1;a:2:{s:10:"vocabulary";s:4:"tags";s:6:"parent";s:1:"0";}}s:21:"options_list_callback";s:28:"i18n_taxonomy_allowed_values";s:23:"entity_translation_sync";b:0;}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:31:"field_data_field_term_reference";a:1:{s:3:"tid";s:24:"field_term_reference_tid";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:35:"field_revision_field_term_reference";a:1:{s:3:"tid";s:24:"field_term_reference_tid";}}}}}s:12:"foreign keys";a:1:{s:3:"tid";a:2:{s:5:"table";s:18:"taxonomy_term_data";s:7:"columns";a:1:{s:3:"tid";s:3:"tid";}}}s:7:"indexes";a:1:{s:3:"tid";a:1:{i:0;s:3:"tid";}}s:2:"id";s:2:"20";}',
  'cardinality' => '1',
  'translatable' => '0',
  'deleted' => '0',