When migrating from Drupal 7 to Drupal 8, Boolean field are created in Drupal 8, except On and Off Label are not same as there Drupal 7 counterpart.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

manojbisht_drupal created an issue. See original summary.

cilefen’s picture

Version: 8.7.4 » 8.7.x-dev
Component: forms system » migration system
Priority: Critical » Normal
manojbisht_drupal’s picture

We have to transform in FieldInstanceSettings, to something like this.

if ($row->getSourceProperty('type') == "list_boolean") {
$instance_settings['on_label'] = $field_settings['allowed_values'][1];
$instance_settings['off_label'] = $field_settings['allowed_values'][0];
}

Ned some thought, after that I can create patch.

quietone’s picture

Status: Active » Needs review
Issue tags: -Migrate critical
FileSize
10.7 KB

And here is a patch with a test.

Not sure why this is migrate critical, so removing the tag. Please let me know if I am wrong about that.

quietone’s picture

Ignore previous patch. I seem to be making quite a few bad patches in the last 24 hours.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Pretty reasonable (and simple) solution here. Test coverage and a quick break/fix.

larowlan’s picture

Version: 8.7.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Needs work

this doesn't apply on 8.8, can we get a patch for 8.8?

Thanks

error: patch failed: core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php:150
error: core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php: patch does not apply
make: *** [patch88] Error 1
quietone’s picture

Status: Needs work » Needs review
FileSize
2.06 KB

Rerolled. The interdiff fails but it is a small patch anyway.

cilefen’s picture

AFAIK interdiffs are impossible by definition on a reroll.

alison’s picture

re: rerolling + interdiff: that's right!

More info: https://www.drupal.org/documentation/git/interdiff#reroll

heddn’s picture

Status: Needs review » Reviewed & tested by the community

And back to RTBC.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php
@@ -65,6 +65,13 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+      $field_data = unserialize($field_definition['data']);

should we be checking that these keys exists first to avoid warnings, we have null coalesce now, saves us triggering a warning?

$instance_settings['on_label'] = $field_data['settings']['allowed_values'][1] ?? 'On';
$instance_settings['off_label'] = $field_data['settings']['allowed_values'][0] ?? 'Off';

quietone’s picture

$field_data = unserialize($field_definition['data']); is actually done earlier and it will exist so it shouldn't be repeated here.

Instead of using coalesce this should really only set $instance_settings if there was an allowed value in the source.. The creation of the field will setup the default on/off labels so there is no need to do that here.

No interdiff since this is small patch.

mikelutz’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

  • larowlan committed 11c62ac on 8.8.x
    Issue #3067889 by quietone: Boolean Field On and Off Label not Migrating
    
larowlan’s picture

Version: 8.8.x-dev » 8.7.x-dev
Status: Reviewed & tested by the community » Needs work

Committed 11c62ac and pushed to 8.8.x. Thanks!

Needs re-roll for 8.7.x

quietone’s picture

Status: Needs work » Needs review
FileSize
1.93 KB

Reroll for 8.7

quietone’s picture

Status: Needs review » Reviewed & tested by the community

Simple reroll for 8.7.x and tests are passing. So setting back to RTBC.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

  • Gábor Hojtsy committed 7c8934d on 8.7.x
    Issue #3067889 by quietone: Boolean Field On and Off Label not Migrating
    

Status: Fixed » Closed (fixed)

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