Problem/Motivation

Migrate D6 allowed vocabularies.

n Drupal 6, the list of applicable content types for a given vocabulary are defined on vocabulary settings

Proposed resolution

Use a process plugin to create the array of target bundles.
Change

'settings/handler_settings/target_bundles/0': '@field_name'

to

 'settings/handler_settings/target_bundles':
 plugin: target_bundle

Remaining tasks

Patch
Review
commit.

User interface changes

None

API changes

None

Data model changes

None

Comments

quietone created an issue. See original summary.

heddn’s picture

Status: Needs review » Active

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

quietone’s picture

Issue summary: View changes

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Bug Smash Initiative
StatusFileSize
new3.81 KB
new5.66 KB

It looks like there are two problems. 1) The field_name was being used as the name for the target vocabulary and 2) the target bundle was created as an indexed array, when it should be associative with the key and value the same. And that is how the target_bundles are tested in \Drupal\Tests\field\Kernel\EntityReference\EntityReferenceSettingsTest.

Next is to double check what the D7 migration does.

quietone’s picture

The Drupal 7 migration of the allowed vocabularies is correct, it is an associative array. So nothing to do there.

The last submitted patch, 8: 3042533-8-fail.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

danflanagan8’s picture

Status: Needs review » Needs work
StatusFileSize
new62.7 KB
new60.71 KB

I ran upgrades from the drupal6 fixture through the UI without the patch and confirmed the bug was present.

Then I applied the patch and tried again. This time the target bundle got assigned correctly.

So manual testing was great!

As far as the code itself, I have two comments.

1. I think it would be nice to make it clearer that the new plugin is only used for the d6 migration. Maybe just in the comment above the annotation mentioning d6?

2. What would you think about re-naming the new helper function in the tests? When I saw assertEntityReferenceFields() I was surprised that all it checked was the target bundles. Something like assertTargetBundles() would probably read a little smoother.

Neither of these is a big deal though, and I could be convinced that neither is necessary.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new4.69 KB
new5.6 KB

@danflanagan8, Thanks for the testing!

#12.1 An extra line seemed unnecessary so I reworked the summary line to include 'Drupal 6'. What do you think.
#12.2 Yes, that is a better name. Fixed

danflanagan8’s picture

Status: Needs review » Reviewed & tested by the community

@quietone, I think the changes look great. I also want to point out for the record that all of your changes to the test are additive except for this one line:

+++ b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateVocabularyFieldInstanceTest.php
@@ -57,7 +58,7 @@ public function testVocabularyFieldInstance() {
-    $this->assertSame(['field_tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
+    $this->assertTargetBundles($field_id, ['tags' => 'tags']);

That line was actually asserting that the migration is incorrect because we really want the target bundles to be ['tags' => 'tags']. So we're not losing test coverage there!

But...Last night I started wondering if there was a way to reproduce the effect of the new process plug with existing process plugins. (This is my favorite part of migration!) This morning I was able to hack something together. It's miserable though! Here's the relevant bits.

  _vid:
    -
      plugin: migration_lookup
      migration:  d6_taxonomy_vocabulary
      source: vid
    -
      plugin: skip_on_empty
      method: row
  # Make an array with _vid as the only element with json trick.
  _vid_wrapped:
    -
      plugin: concat
      source:
        - 'constants/json_start' # '["'
        - '@_vid'
        - 'constants/json_end'. # '"]'
    -
      plugin: callback
      callable: json_decode
  'settings/handler_settings/target_bundles':
    plugin: callback
    callable: array_combine
    unpack_source: TRUE
    source:
      - '@_vid_wrapped'
      - '@_vid_wrapped'

It could have been cleaner is php's array() was callable but apparently it's not. That's why I had to do that json thing. I think above is our best option other than creating the new process plugin.

Seeing as the above is absolutely unreadable, I think your patch is the way to go. RTBC. Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: 3042533-13.patch, failed testing. View results

quietone’s picture

Status: Needs work » Reviewed & tested by the community

Restoring RTBC because the test failure was due to #3255836: Test fails due to Composer 2.2 which has been fixed.

  • catch committed 6644960 on 10.0.x
    Issue #3042533 by quietone, danflanagan8: D6 taxonomy term fields are...

  • catch committed 88868d8 on 9.4.x
    Issue #3042533 by quietone, danflanagan8: D6 taxonomy term fields are...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.0.x and cherry-picked to 9.4.x, thanks!

The new process plugin makes this minor-ish, please re-open if you think it should be backported to 9.3.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.