Notice: Undefined index: label in Drupal\field\Plugin\migrate\source\d6\FieldInstancePerViewMode->initializeIterator()

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
StatusFileSize
new966 bytes

Just need to check the value exists before trying to use it.

joelpittet’s picture

Title: FieldInstancePerViewMode has a default viewmode with no settings » D6 FieldInstancePerViewMode has a default viewmode with no settings
mikeryan’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Looks good, but let's see a test triggering the notice.

joelpittet’s picture

No idea how to test this case, it just happened on an inherited site.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.06 KB
new2 KB
new2.17 KB

I've added a (rather convoluted) test to trigger the notice, but I'm not familiar enough with D6 to know how this situation could occur.

@joelpittet's solution would not solve this particular problem so I have added an attempt of my own. The notice occurs when $field_row['display_settings']['label'] is not set, checking !empty($field_row['display_settings'][$view_mode]) will not confirm this.

I would be interested in your feedback on my interpretation.

The last submitted patch, 6: 2854314-6-test_only.patch, failed testing.

The last submitted patch, 6: 2854314-6-joel.patch, failed testing.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Ah thanks @Jo Fitzgerald, the test case proves it and the new solution fixes it. (FYI, re RTBC, not my patch/solution)

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php
@@ -37,7 +37,13 @@ protected function initializeIterator() {
+            $label = 'hidden';

I checked to see if we had a constant for this value. We don't - see \Drupal\Core\Entity\EntityDisplayBase

+++ b/core/modules/field/src/Plugin/migrate/source/d6/FieldInstancePerViewMode.php
@@ -37,7 +37,13 @@ protected function initializeIterator() {
+          if (!empty($field_row['display_settings']['label']['format'])) {
+            $label = $field_row['display_settings']['label']['format'];
+          }
+          else {
+            $label = 'hidden';
+          }

I guess one question here is should we put this logic here or should it go into the migration using \Drupal\migrate\Plugin\migrate\process\DefaultValue?

jofitz’s picture

@alexpott I think it simplest to leave it here because display_settings needs unserialising before checking whether ['label']['format'] is not empty (and I for one don't know whether that's even possible without a custom process plugin).

quietone’s picture

Status: Needs review » Needs work

What type of field causes the view mode to have no settings? I was unable to reproduce it on a D6 site. At least, lets add a comment.

Since this is just setting a value for label why can't we add a default value in the pipeline at "options/label": label ?

mikeryan’s picture

Status: Needs work » Postponed (maintainer needs more info)

Could we get steps to reproduce here?

Thanks.

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.

heddn’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

If steps are available to reproduce this, please reopen.