Problem/Motivation

The migration system has no support for migrating node reference fields, with their settings and values, from Drupal 7 to Drupal 8.
The source module is https://www.drupal.org/project/references.

Proposed resolution

Add a field plugin to handle Drupal 7 node reference fields. Currently the patch also adds a field plugin to handle Drupal 7 user reference fields.

Add field plugins, migrate_drupal\Plugin\migrate\field\d7\NodeReference and migrate_drupal\Plugin\migrate\field\d7\NodeReference.
Update Kernel tests d7/MigrateNodeCompleteTest.php and d7/MigrateNodeRevisionTest.php, FieldDiscoveryTest.
Update Functional tests d7/MultilingualReviewPageTest.php, d7/NoMultilingualReviewPageTest.php, and d7/UpgradeTest.php.
Update fixture, add a node and user reference field to the test fixture (added to the article content type). Fixture still works via the D7 UI.
Update migrate_drupal migration state file.

Remaining tasks

  • Review
  • Commit the patch
  • Jump into a ball pit and roll around happily

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#106 2814953-106.patch41.23 KBRalkeon
#105 NodeReferences-2814953-105.patch618 bytesJeya sundhar
#96 2814953-96.patch41.14 KBquietone
#96 interdiff-89-96.txt1.03 KBquietone
#89 2814953-89.patch41.38 KBquietone
#89 interdiff-87-89.txt459 bytesquietone
#87 2814953-87.patch41.4 KBquietone
#87 interdiff-86-87.txt2.56 KBquietone
#86 2814953-86.patch41.42 KBquietone
#86 diff-85-85.txt2.31 KBquietone
#85 2814953-85.patch41.44 KBquietone
#85 diff-70-85.txt3.42 KBquietone
#83 2814953-83.patch42.51 KBquietone
#83 interdiff-70-83.txt2.7 KBquietone
#78 2814953-70.patch41.26 KBbenjifisher
#75 core-8.9.8-references_upgrade_path-2814953-85.patch35.42 KBcosolom
#70 2814953-70.patch41.26 KBquietone
#70 interdiff-67-70.txt972 bytesquietone
#67 interdiff-65-67.txt2.63 KBquietone
#67 2814953-67.patch41.21 KBquietone
#65 2814953-65.patch41.21 KBquietone
#65 interdiff-63-65.txt1.83 KBquietone
#63 2814953-63.patch41.18 KBquietone
#63 diff-57-63.txt3.89 KBquietone
#57 2814953-57.patch40.83 KBquietone
#57 interdiff-55-57.txt2.76 KBquietone
#55 2814953-55.patch41.43 KBquietone
#55 interdiff-52-55.txt886 bytesquietone
#54 2814953-54.patch41.5 KBquietone
#54 interdiff-52-54.txt1.5 KBquietone
#52 2814953-52.patch41.42 KBquietone
#52 interdiff-50-52.txt7.83 KBquietone
#50 2814953-50.patch38.28 KBquietone
#50 interdiff-48-50.txt4.79 KBquietone
#48 2814953-48.patch35.39 KBquietone
#48 interdiff-46-48.txt6.49 KBquietone
#46 2814953-46.patch41.66 KBquietone
#46 interdiff-43-46.txt9.81 KBquietone
#43 2814953-43.patch36.07 KBquietone
#43 interdiff-41-43.txt6.5 KBquietone
#41 2814953-41.patch35.19 KBquietone
#41 diff-33-41.txt10.34 KBquietone
#33 core-references_upgrade_path-2814953-32--complete.patch35.23 KBNixou
#31 core-8.8.5-references_upgrade_path-2814953-31-complete.patch35.36 KBNixou
#30 core-references_upgrade_path-2814953-30--test-only.patch28.66 KBNickDickinsonWilde
#30 core-references_upgrade_path-2814953-30--complete.patch34.78 KBNickDickinsonWilde
#26 interdiff-2814953-25-26.txt1012 byteshuzooka
#26 core-references_upgrade_path-2814953-26--test-update-only.patch28.65 KBhuzooka
#26 core-references_upgrade_path-2814953-26--complete.patch34.76 KBhuzooka
#4 d7_node_reference-2814953-4.patch3.66 KBdavidsickmiller
#13 d7_references-2814953-13.patch5.81 KBNathaniel
#13 interdiff_4-13.txt8.07 KBNathaniel
#16 d7_references-2814953-16.patch6.56 KBNathaniel
#16 interdiff_13-16.txt2.7 KBNathaniel
#20 d7_references-2814953-20.patch6.58 KBNathaniel
#20 interdiff_16-20.txt433 bytesNathaniel
#21 d7_references-2814953-21.patch7.39 KBNathaniel
#21 interdiff_20-21.txt650 bytesNathaniel
#22 d7_references-2814953-22.patch32.85 KBNathaniel
#22 interdiff_21-22.txt25.17 KBNathaniel
#23 d7_references-2814953-23--rebase-of-22.patch32.88 KBhuzooka
#24 core-references_upgrade_path-2814953-24--rebase-of-22.patch32.88 KBhuzooka
#25 core-references_upgrade_path-2814953-25--test-update-only.patch28.61 KBhuzooka
#25 core-references_upgrade_path-2814953-25--fix-only--do-not-test.patch6.12 KBhuzooka
#25 core-references_upgrade_path-2814953-25--complete.patch34.73 KBhuzooka
#25 interdiff-2814953-24-25.txt5.5 KBhuzooka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Postponed

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

davidsickmiller’s picture

Node reference migration from D6 was implemented in https://www.drupal.org/node/2872660 and https://www.drupal.org/node/2814949. I took a look at how it was done and adapted it for D7 in the attached patch. It works for me, though I'm not sure if there are corner cases that will need to be addressed.

Neither the D6 implementation or my code require the patch from https://www.drupal.org/node/2447727.

I'm not interested in working on #2447727, but if you'd like to go ahead with the approach used in my patch, I would be happy to write some tests for it.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Issue summary: View changes

Add source module

nareshrana’s picture

Quick Question:

Do we need to apply these patches to drupal8 site before running any migrations?

kriceiq’s picture

I'm probably glossing over it but is there an 8.7.x patch for this?

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.

Wim Leers’s picture

Priority: Normal » Major

Note that https://git.drupalcode.org/project/references is used on 100K Drupal 7 sites (see https://www.drupal.org/project/usage/references), or about 1 in 7 (see https://www.drupal.org/project/usage/drupal). So increasing priority.

P.S.: Running into this too for wimleers.com!

Wim Leers’s picture

Title: Support Drupal 7 node reference fields » [PP-1] Support Drupal 7 node reference fields

Bumped priority of the blocker that @phenaproxima identified in #2: #2447727: Add base class for migrating reference fields.

Nathaniel’s picture

Related issues: +#2814957: Support Drupal 7 user reference fields
FileSize
6.56 KB
2.7 KB

Fixed user_reference by adding target_type to field settings and setting default filter type to _none. Some cleanup. Role filter settings are incomplete. Tested on a test migration with one node reference and one user reference. They were both migrated as expected.

Wim Leers’s picture

Awesome, thanks @Nathaniel! I will test this on wimleers.com.

Wim Leers’s picture

Just wanted to let y'all know I'm making the discovery of this issue for current users of the Drupal 7 references module easier, by adding this issue to their issue queue: #3096190: FYI: a migration path to Drupal 8 is being worked on in core. It links here :) Hopefully that will also lead to more people testing this patch.

heddn’s picture

Issue tags: +Needs tests

Tagging for needing tests.

Nathaniel’s picture

FileSize
6.58 KB
433 bytes

Missed a break statement. No change in functionality.

Nathaniel’s picture

Updated migrate test to include node_reference and user_reference in testFieldProvidersExist.

Nathaniel’s picture

Updated the migrate_drupal d7/FieldDiscoveryTest and drupal7 fixture. Kudos to anyone who works on those fixtures, what a horrendous task!

If this all goes through the docs will also need to be updated to include the references module:
https://www.drupal.org/docs/8/api/migrate-api/generating-database-fixtur...

huzooka’s picture

Patch #22 no longer applies.

Rebased patch attached.

huzooka’s picture

huzooka’s picture

iancawthorne’s picture

I was wondering if anyone would be able to provide some steps to attempt a migration for node reference fields with the patch on here in place?

I am running "drush migrate:import d7_field"

For every node reference field I get an error output of:
Attempt to create a field storage field_FIELDNAME with no type.

This applies with or without the patch in place. I'm using the patch at #22 as that appears to be the most recent which will roll to Drupal 8.8, being the version I'm testing migrations on.

Are there some other requirements / steps for this patch to work?

Nathaniel’s picture

I'm currently using #20 before any tests were added. Seems to be working on 8.8.2. Remember to clear cache etc. I find myself restarting migrations often with a fresh install (if possible).

iancawthorne’s picture

@Nathaniel, you were absolutely right. I started from scratch with a fresh install and the migration of node references worked. Thanks.

NickDickinsonWilde’s picture

mmph. Should've read from the top instead of from the bottom. Didn't notice the POSTPONED aspect. But in the meantime, here are a couple of re-rolled patches. Same as @huzooka's patchs in #26 but re-rolled for latest 8.9.x. Although it looks to me like #2447727: Add base class for migrating reference fields may be covering both node and user reference anyways and this issue will probably get closed as duplicate.

Nixou’s picture

I needed to have this feature for a migration to Drupal 8.8.5.
I reroll the patch for my needs so I attach it for those who need it.

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.

Nixou’s picture

marcoka’s picture

Applied #33, fields are in the node but all are empty. No data at all. Drupal 8.9.1, #33 applies flawlessly.

Wim Leers’s picture

#34: any migration messages?

marcoka’s picture

Migration always throws a gazillion messages here, but i did not see any that i found useful or related to this.
I ended up moving the field tables by hand, exporting the sql of D7, replaced some stuff and imported it that way.

Wim Leers’s picture

Migration always throws a gazillion messages here

That shouldn't happen! 😞 Even though they're often cryptic, they're almost always about problems.

but i did not see any that i found useful or related to this.

Hm, okay. Perhaps there was one for d7_field or d7_field_instance that related to this though! 🤔

mradcliffe’s picture

Issue summary: View changes
Status: Postponed » Needs work
Issue tags: +Needs reroll

#2447727: Add base class for migrating reference fields is done. Changing to Needs work because there is a patch that probably needs a reroll. I added Needs reroll tag.

quietone’s picture

Title: [PP-1] Support Drupal 7 node reference fields » Support Drupal 7 node reference fields
Assigned: Unassigned » quietone

The latest patch has both node and user reference changes. For now, I am keeping them together.

Wim Leers’s picture

For now, I am keeping them together.

+1

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
10.34 KB
35.19 KB

Rerolled. I still need to bring up the new fixture in a real D7 site and I haven't reviewed the patch yet myself because I am keen to see what errors are found.

Status: Needs review » Needs work

The last submitted patch, 41: 2814953-41.patch, failed testing. View results

quietone’s picture

Title: Support Drupal 7 node reference fields » Migrate Drupal 7 node reference fields
Status: Needs work » Needs review
FileSize
6.5 KB
36.07 KB

Nice results, I expected the functional tests to fail.

Now, add some fixes for the functional tests. Also, add migration state information and use the new ReferenceBase.

+++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
@@ -65,6 +65,50 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+            // @todo get new role id.
+            // $instance_settings['handler_settings']['filter']['role'][$type] = $value;

Ah, there is some work here to do.

And the d6 node and user reference field plugins are in migrate_drupal, the d7 added in this patch are in field. Where should they be?

Status: Needs review » Needs work

The last submitted patch, 43: 2814953-43.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mradcliffe’s picture

  1. +++ b/core/modules/field/migrations/state/field.migrate_drupal.yml
    @@ -10,4 +10,9 @@ finished:
    +    node_reference: core
    ...
    +    user_reference: core
    

    If we added 2 migrations, then the failing test in migrate_drupal_ui is a false positive and can be bumped from 76 to 78, right?

  2. +++ b/core/modules/field/src/Plugin/migrate/field/d7/NodeReference.php
    @@ -0,0 +1,57 @@
    +use Drupal\migrate\Plugin\MigrationInterface;
    
    +++ b/core/modules/field/src/Plugin/migrate/field/d7/UserReference.php
    @@ -0,0 +1,57 @@
    +use Drupal\migrate\Plugin\MigrationInterface;
    

    Unused use statements.

  3. +++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
    index b897e54209..46c60b4249 100644
    --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php
    
    --- a/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php
    +++ b/core/modules/migrate_drupal/tests/src/Kernel/d7/FieldDiscoveryTest.php
    

    I think what is happening with the test failure in migrate_drupal is that the test data is too big on a failed assertion, and PHP Unit tries to serialize the trace when there is an object that is too large (the drupal container).

    There's an assertion failure in testAddAllFieldProcessesAlters with one (or more) of the new data sets, but not sure which one it is.

quietone’s picture

Status: Needs work » Needs review
FileSize
9.81 KB
41.66 KB

45.1. This is a count of the missing or available modules on the Review page. I missed adding node and user reference in that test.
45.2. Fixed.
45.3. Yes, that is a really unhelpful message. Test fixed.

quietone’s picture

Assigned: quietone » Unassigned
Status: Needs review » Needs work

Good passing tests, let's keep it that way.

Still need to do the @todo in the patch, See #43.

quietone’s picture

Sort of a bad patch, I commented out part of the dataprovider and left that in the patch.

Status: Needs review » Needs work

The last submitted patch, 48: 2814953-48.patch, failed testing. View results

quietone’s picture

Status: Needs work » Needs review
FileSize
4.79 KB
38.28 KB

Fix the test that I messed up again in #48.

But mostly addressing the @todo to get the field settings for the user_reference field.

mradcliffe’s picture

Title: Migrate Drupal 7 node reference fields » Migrate Drupal 7 node/user reference fields
Issue summary: View changes
Status: Needs review » Needs work

Nice work. There's a small nit in this review to fix that I missed previously so shifting to needs work. The rest are questions to answer.

  1. +++ b/core/modules/field/src/Plugin/migrate/field/d7/NodeReference.php
    @@ -0,0 +1,56 @@
    +namespace Drupal\field\Plugin\migrate\field\d7;
    
    +++ b/core/modules/field/src/Plugin/migrate/field/d7/UserReference.php
    @@ -0,0 +1,56 @@
    +namespace Drupal\field\Plugin\migrate\field\d7;
    

    Following-up on the question of what module to put these in. If we're considering removing/deprecating migrate_drupal, would it make it easier to remove if these were in migrate_drupal rather than a non-migrate module? I think for consistency with d6 moving these to migrate_drupal makes sense. The d6 ones haven't hit a release yet so I guess there's time to move those instead.

  2. +++ b/core/modules/field/src/Plugin/migrate/field/d7/UserReference.php
    @@ -0,0 +1,56 @@
    +class UserReference extends ReferenceBase {
    

    @todo override defineValueProcessPipeline similar to the d6 plugin to do a migration lookup.

  3. +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
    @@ -65,6 +65,55 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +    if ($row->getSourceProperty('type') == 'node_reference') {
    ...
    +    if ($row->getSourceProperty('type') == 'user_reference') {
    

    The other similar comparisons in this file use === except for the preexisting line 39 containing == "entityreference" (double quotes).

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
7.83 KB
41.42 KB

#51.1 Yes, lets keep the node/user references together in migrate drupal. Moved field plugins and migration state data.
#51.2 yes, was planning to that in this round. done now.
#51.3 Of the 3 existing tests only 1 uses '==='. So, no change here. Although I can be convinced to change it.

$grep -r "('type')" core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php 
    if ($row->getSourceProperty('type') == 'taxonomy_term_reference') {
    if ($row->getSourceProperty('type') == "entityreference") {
    if ($row->getSourceProperty('type') == 'node_reference') {
    if ($row->getSourceProperty('type') == 'user_reference') {
    if ($row->getSourceProperty('type') === 'list_boolean') {

Changed prepareRow in FieldInstance to get only the roles referenced.

Status: Needs review » Needs work

The last submitted patch, 52: 2814953-52.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Status: Needs work » Needs review
FileSize
1.5 KB
41.5 KB

Forgot to fix MigrateNodeRevisionTest

quietone’s picture

Ignore previous patch.

Status: Needs review » Needs work

The last submitted patch, 55: 2814953-55.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Fix the test, again. And some other cleanup and coding standard fixes.

quietone’s picture

Closed #2814957: Support Drupal 7 user reference fields as a duplicate since this has both the node and user reference migrations. The patch isn't too big and the migrations are so similar it was easier to work on them both in the same issue.

mikelutz’s picture

Status: Needs review » Reviewed & tested by the community

Yea! I am so happy this is finally getting in. All feedback has been addresses as far as I can tell, and I looked through the code and it looks good to me. I'm going to kick off a few more tests against the other databases, but as long as they are green I'm excited to RTBC this one.

pyxio’s picture

so if i understand correctly this patch will not work for Drupal 8.9 and i must change to 9.1x dev in order to migrate node reference fields from a D7 site? Thanks

quietone’s picture

@pyxio, Yes. Also, this relies on #2447727: Add base class for migrating reference fields which was only committed to 9.1.x.

benjifisher’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll, +Novice

The patch in #57 no longer applies. I hope it is a simple reroll.

quietone’s picture

And a reroll.

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.

quietone’s picture

Needed a reroll

benjifisher’s picture

Status: Needs review » Needs work

I compared the patches in #63 and #65. Here is one hunk from #65:

+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/MultilingualReviewPageTest.php
@@ - + @@ protected function getAvailablePaths() {
       'Locale',
       'Menu',
       'Menu translation',
+      'Node Reference',
       'Node',
       'Number',
       'OpenID',

The patch in #63 added 'Node Reference' after 'Node', keeping the list sorted (alphabetized). Can we keep it that way?

This is just one of several examples.

quietone’s picture

Status: Needs work » Needs review
FileSize
41.21 KB
2.63 KB

66. Sorting fixed. This is a real nuisance. The sort tool in PhpStorm sorts it as in patch #65, as does the String Manipulation plugin, and I just decided to not fight it.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community

@quietone:

Thanks for the update. I compared the patches in #63 and #67. Now that the sorting is consistent, the only differences between the two are metadata (commit hashes and line numbers) and context lines.

Then I realized that #63 was already a reroll, and had not been reviewed. I should really compare the patches in #57 and #67. In addition to the differences above, I see several other changes:

  1. Entity IDs in the fixtures. The IDs have to be changed because other issues have added two entries each to the field-storage and field tables. No, I should say field and field instance, since these are D7 fixtures. And then the field-instance table refers to the IDs in the field table, so those are updated, too.
  2. Some of the changes in context lines are confusing, because the patch in #57 adds lines to the end of a test method, but the patch in #67 adds them in the middle of a test method, before a few comment lines. That is because of the changes in #3165763: Combine two tests to one in d7 MigrateFieldTest and MigrateFieldInstance.
  3. I will not set it back to NW for this, but a comment here would be welcome:
    +++ b/core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php
    @@ -168,6 +168,26 @@ public function testFieldInstances() {
         $this->assertEntity('node.article.field_vocab_localize', 'vocab_localize', 'entity_reference', FALSE, FALSE);
         $this->assertEntity('node.article.field_vocab_translate', 'vocab_translate', 'entity_reference', FALSE, TRUE);
     
    +    $this->assertEntity('node.article.field_node_reference', 'Node Reference', 'entity_reference', FALSE, TRUE);
    +    $this->assertEntity('node.article.field_user_reference', 'User Reference', 'entity_reference', FALSE, TRUE);
    
  4. There are some changes to getEntityCounts() in some of the tests. Since we added two items each to the field and field-instamce config tables, this looks reasonable. Since the tests pass, it must be right.

These differences all look reasonable, so based on the review in #59 I am setting the status back to RTBC.

mradcliffe’s picture

+1 RTBC.

I ran a migration on a drupalcamp site I maintain that used references in drupal 7 for session speakers using the patch in #67 (applied to 9.1.0-alpha1). It successfully migrated user references for 1...N items into a multi-value entity reference field.

quietone’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
972 bytes
41.26 KB

@benjifisher, thanks for noticing the missing comment. Adding a comment as per #68.3 which keeps the file consistency with the commenting of the tests.

quietone’s picture

Status: Needs review » Reviewed & tested by the community

I've spellchecked the one line comment fix in patch #70. Since it is a one line addition of a comment in a test file and no code changes, I'm setting back to RTBC.

quietone’s picture

Just noticed this should be on the D7 meta.

benjifisher’s picture

+1 for the update in #70. (edited)

quietone’s picture

@benjifisher, thanks !

cosolom’s picture

Status: Reviewed & tested by the community » Needs work
quietone’s picture

Status: Needs work » Reviewed & tested by the community

Restoring RTBC for the patch in #70.

benjifisher’s picture

It looks as though the testbot is looking at the wrong patch, so I am re-uploading the one from #70.

quietone’s picture

@benjifisher, of course! thanks.

chipway’s picture

Patch still applies on 9.1.0.

catch’s picture

One very minor question:

  1. +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/d7/NodeReference.php
    @@ -0,0 +1,56 @@
    +
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getFieldFormatterMap() {
    +    return [
    +      'node_reference_default' => 'entity_reference_label',
    +      'node_reference_plain' => 'entity_reference_label',
    +      'node_reference_nid' => 'entity_reference_entity_id',
    +      'node_reference_node' => 'entity_reference_entity_view',
    +      'node_reference_path' => 'entity_reference_entity_id',
    +    ];
    +  }
    

    Should the path formatter map to the label instead of the ID? Or do we always map to ID if there's no matching formatter?

  2. +++ b/core/modules/migrate_drupal/src/Plugin/migrate/field/d7/UserReference.php
    @@ -0,0 +1,76 @@
    +  }
    

    Same question here.

catch’s picture

Status: Reviewed & tested by the community » Needs review
quietone’s picture

@catch, thanks. I agree.

This makes the changes suggested in #81 and add assertions for the two new components.

benjifisher’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll, +Novice

The patch in #83 needs a reroll. I think it conflicts with #2565931: Handle long comment bundle names. That is a Novice task.

quietone’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll, -Novice
FileSize
3.42 KB
41.44 KB

Yes, it does need a reroll and here it is.

quietone’s picture

Another reroll

quietone’s picture

I reviewed the comments since the last RTBC and see that I did not make the change for #81.1. This patch addresses that.

benjifisher’s picture

Issue summary: View changes
Status: Needs review » Needs work

We might have fewer rerolls if we used the MR workflow instead of patches.

I compared the patches from #70 and #87. The changes look appropriate:

  • Change _entity_id to _entity_label for both nodereference and userreference fields, as suggested in #81. Corresponding changes in the tests.
  • Context lines have changed in several places.
  • Entity counts have changed in UpgradeD7Test. In both patches, the effect is to increase the counts by 2.
  • Both patches add items to the end of the database fixture. Because of unrelated changes, the IDs of the new items are updated.

There is one little problem. Because of the way PHP arrays work, it makes no difference, but it is a little sloppy:

+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -5357,6 +5387,25 @@
...
+->values(array(
+  'id' => '88',
+  'field_id' => '2',
+  'field_id' => '56',
quietone’s picture

Status: Needs work » Needs review
FileSize
459 bytes
41.38 KB

@benjifisher, Nice find. Thanks.

And here is a fix.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community

@quietone, thanks for the fix! RTBC

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 89: 2814953-89.patch, failed testing. View results

benjifisher’s picture

Status: Needs work » Reviewed & tested by the community

That looks like a random fail.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 89: 2814953-89.patch, failed testing. View results

quietone’s picture

Status: Needs work » Reviewed & tested by the community
larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Just one question, and one suggestion (feel free to ignore), fine to put back to RTBC with answer to the question

  1. +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
    @@ -65,6 +65,51 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +      if (!empty($field_data['settings']['referenceable_types'])) {
    +        foreach ($field_data['settings']['referenceable_types'] as $type => $value) {
    +          if ($value) {
    +            $instance_settings['handler_settings']['target_bundles'][$type] = $value;
    +          }
    +        }
    

    we could replace this with a one-liner$instance_settings['handler_settings']['target_bundles'] = array_filter($field_data['settings']['referenceable_types'] ?? []), in fact it could go straight into the 'target_bundles' in the original array too

  2. +++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
    @@ -65,6 +65,51 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
    +        foreach ($row->get('roles') as $role) {
    +          $instance_settings['handler_settings']['filter']['role'] = [
    

    does this need the check for empty options like above?

quietone’s picture

95.1 Nice. and fixed.

95.2 Good question. There is not check for empty here because that work has already been done in prepareRow. Why? Because a query on the source database needs to be done to get the roles, and the must be done in the source plugin.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community

I compared the patch in #96 to the one in #87. The changes are as expected. +1

larowlan’s picture

Adding review credits

  • larowlan committed 2a2f2de on 9.2.x
    Issue #2814953 by quietone, huzooka, Nathaniel, Nixou,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2a2f2de and pushed to 9.2.x. Thanks!

Status: Fixed » Closed (fixed)

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

Wim Leers’s picture

Wim Leers’s picture

Discovered another

+++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
@@ -65,6 +65,43 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+      if ($row->hasSourceProperty('roles')) {
+        $instance_settings['handler_settings']['filter']['type'] = 'role';
+        foreach ($row->get('roles') as $role) {
+          $instance_settings['handler_settings']['filter']['role'] = [
+            $role['name'] => $role['name'],
+          ];
+        }
+      }

This contains another bug, fix at #3198732-19: Migrating reference fields: target_bundles may never be empty array.

Gábor Hojtsy’s picture

Jeya sundhar’s picture

Patch for node reference fieldsettings

Ralkeon’s picture

FileSize
41.23 KB

Rerolled patch #96 including #105 update

Ralkeon’s picture

Sorry, removed my last added patch cause I was using an old drupal version. The #105 works fine!