Warning: Undefined array key "wrappers"

Created on 21 January 2025, 1 day ago

Problem/Motivation

Bugs being reported due to new wrappers field:

Warning: Undefined array key "wrappers" in Drupal\custom_field\Plugin\Field\FieldFormatter\BaseFormatter->getFormattedValues() (line 477 of modules/contrib/custom_field/src/Plugin/Field/FieldFormatter/BaseFormatter.php).

Warning: Trying to access array offset on value of type null in template_preprocess_custom_field_item() (line 119 of modules/contrib/custom_field/custom_field.module).

Steps to reproduce

Updating to 3.1 and saving a node, the rendered template is producing errors.

πŸ› Bug report
Status

Active

Version

3.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States apmsooner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @apmsooner
  • Merge request !90Add fallback for β€˜wrappers’. β†’ (Merged) created by apmsooner
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    I rolled back to 3.03, added custom field and then updated to 3.1, cleared cache and rendered existing node, resaved, etc... but wasn't able to reproduce. Anyhow, i added a default value in case it isn't set for some reason so please try this patch against 3.1 and clear the cache and see if it resolves for you. Please report back so we can merge in or refactor if necessary.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Oh, i see there were warnings in the logs. Just warnings to harmless but just the same, the patch just get rid of those. Ultimately resaving the field settings in manage display will also set the new values to config even if empty.

    You should see something like this in config export for the field after resaving:

      field_custom_field:
        type: custom_formatter
        label: above
        settings:
          fields:
            title:
              format_type: string
              wrappers:
                field_wrapper_tag: ''
                field_wrapper_classes: ''
                field_tag: ''
                field_classes: ''
                label_tag: ''
                label_classes: ''
  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    Okay, the patch did resolve the warnings. Thanks for the fast turnaround!

    I also see the new config item after actually editing/saving the formatter settings per your instructions in the other issue πŸ› Errors when displaying Entity Reference field as a block in block layout Active .

    We also use fences, so I'm curious to see if/how these new wrappers might interact with that module.

  • Pipeline finished with Skipped
    1 day ago
    #402136
    • apmsooner β†’ committed 2bb0b052 on 3.1.x
      Issue #3501250 by apmsooner, justcaldwell: Warning: Undefined array key...
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Cool, thanks for the review. This setting works in conjunction with fences module but has no dependency or interaction with it. It basically does the same thing but at the subfield level so you can have full control over the output if desired.

  • πŸ‡ΊπŸ‡ΈUnited States justcaldwell Austin, Texas

    Thanks for the info on wrappers. And I just wanted to say, Custom Field really is an excellent contribution β€” thanks for your work!

Production build 0.71.5 2024