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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

apmsooner created an issue. See original summary.

apmsooner’s picture

Status: Active » Needs review

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.

apmsooner’s picture

Oh, i see there were warnings in the logs. Just warnings so harmless but just the same, the patch should 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: ''
justcaldwell’s picture

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

I also see the new config items after actually editing/saving the formatter settings per your instructions in the other issue.

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

  • apmsooner committed 2bb0b052 on 3.1.x
    Issue #3501250 by apmsooner, justcaldwell: Warning: Undefined array key...
apmsooner’s picture

Assigned: apmsooner » Unassigned
Status: Needs review » Fixed

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.

justcaldwell’s picture

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

apmsooner’s picture

Status: Fixed » Closed (fixed)

Thanks @justcaldwell, glad you're getting use from the module. A new release has been published that includes this fix.