Problem:

Notice: Undefined index: #fields in Drupal\photoswipe\Plugin\Field\FieldFormatter\PhotoswipeFieldFormatter->settingsForm()

$form['#fields'] doesn't always have values in the field display form (e.g. admin/structure/types/manage/XXX/display for nodes)

Solution:

Add a !empty() check around $form['#fields']

    // Add the other node fields as options
    if(!empty($form['#fields'])){
      foreach ($form['#fields'] as $node_field) {
        if ($node_field != $this->fieldDefinition->getName()) {
          $caption_options[$node_field] = $node_field;
        }
      }
    }

Comments

Anybody created an issue. See original summary.

anybody’s picture

Status: Active » Needs review
StatusFileSize
new995 bytes

Patch for review attached. We're using this fix in production and tested it functionally.

anybody’s picture

Title: Notice: Undefined index: #fields in Drupal\photoswipe\Plugin\Field\FieldFormatter\PhotoswipeFieldFormatter->settingsForm() » Notice: Undefined index: #fields in Drupal\photoswipe\Plugin\Field\FieldFormatter\PhotoswipeFieldFormatter->settingsForm() in field display settings
anybody’s picture

@sun: Could we perhaps get this commited to get rid of the notices? The patch is very simple.

Furthermore could you enable automatic ci tests here for the D8 branch? That would make it possible to see if the patch applies against the latest dev.

Thank you! :)

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Patch still applies cleanly against the latest dev and fixes the notice. RTBC!

pjbaert’s picture

I can confirm this patch applies perfectly on the latest 8.x-1.0-beta4 branch.

anybody’s picture

Yeah I think this should be commited as soon as possible to get rid of this old message :)

borisson_’s picture

I agree, this patch looks solid.

anybody’s picture

PLANNED for the next dev and stable release.

  • Anybody committed a458a45 on 8.x-1.x
    Issue #2949604 by Anybody, pjbaert, borisson_, thomas.frobieter: Notice...
anybody’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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