Thank you for your wonderful module.

Since yesterday (drupal update) I am getting the following error on manage display:

Warning: Undefined array key "fences_field_items_wrapper_classes" in fences_field_formatter_settings_summary_alter() (line 212 of modules/contrib/fences/fences.module).

Drupal: 8.3.16
PHP: 8.3.16

Have updated fences to 3.0.6, but error persists.

Issue fork fences-3504624

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

liliplanet created an issue. See original summary.

guilhom’s picture

I can confirm I have the same issue on my side.

It seems to happen only when you set a "Field items Wrapper Tag". The summary presented in the Manage Display page is empty and the error mentionned by liliplanet appears.

Issue is here:

'fences_field_wrapper_tag' => t('Field items wrapper tag: %field_items_wrapper_tag', ['%field_items_wrapper_tag' => $fencesSettings['fences_field_items_wrapper_tag']]),
      'fences_field_wrapper_classes' => t('Field items wrapper classes: %field_items_wrapper_classes', ['%field_items_wrapper_classes' => $fencesSettings['fences_field_items_wrapper_classes']]),

We are missing "items" for items_wrapper_tag and items_wrapper_classes in array keys.

anybody’s picture

Assigned: Unassigned » anybody

Thanks for the report, I'm on it!

anybody’s picture

Status: Active » Needs review

Please check, if this fixes the issue. I assume code-wise that the wrapper attribute is still being set correctly? Otherwise, tests should have failed.

So this was only a notice, nothing really broken...?

anybody’s picture

Assigned: anybody » Unassigned
anybody’s picture

Okay maybe wasn't even a regression, but from another issue where the summary was added recently.

grimreaper’s picture

Status: Needs review » Needs work

Hello,

Encountering the same problem:
- fences_field_items_wrapper_tag
- fences_field_items_wrapper_classes

I checkout the proposed changes and there are still the warnings.

grevil’s picture

Version: 3.0.6 » 3.x-dev

We encounter the exact same issue now. Quite annoying...

I'll have a look later on today!

  • grevil committed 38284f84 on 3.x
    Issue #3504624 by anybody, liliplanet, guilhom: Undefined array key "...
grevil’s picture

Status: Needs work » Fixed

Yea, no idea how that got in there, but there is neither a "fences_field_wrapper_tag", nor a "fences_field_wrapper_classes" key. Instead, they are called "fences_field_items_wrapper_tag" and "fences_field_items_wrapper_classes" (as @guilhom already stated).

This was introduced through #3498432: Show fences settings in field settings summary.

EDIT: Fixed typo in the key names.

grevil’s picture

Released 3.0.7. Sorry for the delay for such an annoying issue.

grimreaper’s picture

Confirming the fix. Thanks!

liliplanet’s picture

Thank you so much @Grevil, fixed 🌷

Status: Fixed » Closed (fixed)

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

abenbow’s picture

Hey, this appears to still be an issue in the 3.0.7 release. I'm using 3.0.7 and still getting this error message. The fix in the issue branch (which appears to be unmerged) did fix it for me, it just isn't in any current release that I can download.

anybody’s picture

@abenbow I think it was was released with 3.0.7 - see https://git.drupalcode.org/project/fences/-/commits/3.x
Still we can tag a new release with latest changes.

abenbow’s picture

Hey, sorry to open this back up, but I think something isn't right here.

The issue is centered on the implementation of the implementation of fences_field_formatter_settings_summary_alter().

In version 3.0.7, where this bug was ostensibly fixed, the implementation of fences.module is as follows:

fences.module, v3.0.7

/**
 * Implements hook_field_formatter_settings_summary_alter().
 */
function fences_field_formatter_settings_summary_alter(array &$summary, array $context) {
  $fencesSettings = $context['formatter']->getThirdPartySettings('fences');
  if (count($fencesSettings) > 0) {
    $defaultSettings = FencesConstants::DEFAULT_THIRD_PARTY_SETTINGS;
    $summaryItems = [
      'fences_field_tag' => t('Field tag: %field_tag', ['%field_tag' => $fencesSettings['fences_field_tag']]),
      'fences_field_classes' => t('Field classes: %field_classes', ['%field_classes' => $fencesSettings['fences_field_classes']]),
      'fences_field_items_wrapper_tag' => t('Field items wrapper tag: %field_items_wrapper_tag', ['%field_items_wrapper_tag' => $fencesSettings['fences_field_items_wrapper_tag']]),
      'fences_field_items_wrapper_classes' => t('Field items wrapper classes: %field_items_wrapper_classes', ['%field_items_wrapper_classes' => $fencesSettings['fences_field_items_wrapper_classes']]),
      'fences_field_item_tag' => t('Field item tag: %field_item_tag', ['%field_item_tag' => $fencesSettings['fences_field_item_tag']]),
      'fences_field_item_classes' => t('Field item classes: %field_item_classes', ['%field_item_classes' => $fencesSettings['fences_field_item_classes']]),
      'fences_label_tag' => t('Label tag: %label_tag', ['%label_tag' => $fencesSettings['fences_label_tag']]),
      'fences_label_classes' => t('Label classes: %label_classes', ['%label_classes' => $fencesSettings['fences_label_classes']]),
    ];
    foreach ($fencesSettings as $setting => $value) {
      if ($value != $defaultSettings[$setting]) {
        $summary[] = $summaryItems[$setting];
      }
    }
  }
}

In the newest release, version 3.0.8, which came out yesterday, that implementation is the same. Here it is for reference:

fences.module 3.0.8

/**
 * Implements hook_field_formatter_settings_summary_alter().
 */
function fences_field_formatter_settings_summary_alter(array &$summary, array $context) {
  $fencesSettings = $context['formatter']->getThirdPartySettings('fences');
  if (count($fencesSettings) > 0) {
    $defaultSettings = FencesConstants::DEFAULT_THIRD_PARTY_SETTINGS;
    $summaryItems = [
      'fences_field_tag' => t('Field tag: %field_tag', ['%field_tag' => $fencesSettings['fences_field_tag']]),
      'fences_field_classes' => t('Field classes: %field_classes', ['%field_classes' => $fencesSettings['fences_field_classes']]),
      'fences_field_items_wrapper_tag' => t('Field items wrapper tag: %field_items_wrapper_tag', ['%field_items_wrapper_tag' => $fencesSettings['fences_field_items_wrapper_tag']]),
      'fences_field_items_wrapper_classes' => t('Field items wrapper classes: %field_items_wrapper_classes', ['%field_items_wrapper_classes' => $fencesSettings['fences_field_items_wrapper_classes']]),
      'fences_field_item_tag' => t('Field item tag: %field_item_tag', ['%field_item_tag' => $fencesSettings['fences_field_item_tag']]),
      'fences_field_item_classes' => t('Field item classes: %field_item_classes', ['%field_item_classes' => $fencesSettings['fences_field_item_classes']]),
      'fences_label_tag' => t('Label tag: %label_tag', ['%label_tag' => $fencesSettings['fences_label_tag']]),
      'fences_label_classes' => t('Label classes: %label_classes', ['%label_classes' => $fencesSettings['fences_label_classes']]),
    ];
    foreach ($fencesSettings as $setting => $value) {
      if ($value != $defaultSettings[$setting]) {
        $summary[] = $summaryItems[$setting];
      }
    }
  }
}

However, in the issue branch linked to this issue (link for reference: #3504624), there is a change that, for whatever reason is not in either of these releases.

Here is what the module file looks like in this feature branch.

fences.module, issue branch fences-3504624

/**
 * Implements hook_field_formatter_settings_summary_alter().
 */
function fences_field_formatter_settings_summary_alter(array &$summary, array $context) {
  $fencesSettings = $context['formatter']->getThirdPartySettings('fences');
  if (count($fencesSettings) > 0) {
    $defaultSettings = FencesConstants::DEFAULT_THIRD_PARTY_SETTINGS;
    $summaryItems = [
      'fences_field_tag' => t('Field tag: %field_tag', ['%field_tag' => $fencesSettings['fences_field_tag'] ?? '']),
      'fences_field_classes' => t('Field classes: %field_classes', ['%field_classes' => $fencesSettings['fences_field_classes'] ?? '']),
      'fences_field_wrapper_tag' => t('Field items wrapper tag: %field_items_wrapper_tag', ['%field_items_wrapper_tag' => $fencesSettings['fences_field_items_wrapper_tag'] ?? '']),
      'fences_field_wrapper_classes' => t('Field items wrapper classes: %field_items_wrapper_classes', ['%field_items_wrapper_classes' => $fencesSettings['fences_field_items_wrapper_classes'] ?? '']),
      'fences_field_item_tag' => t('Field item tag: %field_item_tag', ['%field_item_tag' => $fencesSettings['fences_field_item_tag'] ?? '']),
      'fences_field_item_classes' => t('Field item classes: %field_item_classes', ['%field_item_classes' => $fencesSettings['fences_field_item_classes'] ?? '']),
      'fences_label_tag' => t('Label tag: %label_tag', ['%label_tag' => $fencesSettings['fences_label_tag'] ?? '']),
      'fences_label_classes' => t('Label classes: %label_classes', ['%label_classes' => $fencesSettings['fences_label_classes'] ?? '']),
    ];
    foreach ($fencesSettings as $setting => $value) {
      if ($value != $defaultSettings[$setting]) {
        $summary[] = $summaryItems[$setting];
      }
    }
  }
}

The key difference here is that at the end of each line in the array, there is a null coalescing operator assigning each value to the empty string.

When I manually paste the above block into my fences.module file, the error I've been receiving stops.

That error output, for reference:

Warning: Undefined array key "fences_field_items_wrapper_tag" in /var/www/html/web/modules/contrib/fences/fences.module on line 203
Warning: Undefined array key "fences_field_items_wrapper_classes" in /var/www/html/web/modules/contrib/fences/fences.module on line 204

This change is, as yet, unmerged. The GitLab page for this issue branch reads: "5 commits behind, 1 commit ahead of the upstream repository".

grevil’s picture

Status: Closed (fixed) » Needs work

grevil changed the visibility of the branch 3504624-undefined-array-key to hidden.

anybody changed the visibility of the branch 3504624-undefined-array-key to active.

anybody changed the visibility of the branch 3504624-undefined-array-key to hidden.

anybody’s picture

@abenbow this is the change committed here:
https://git.drupalcode.org/project/fences/-/commit/38284f8404bd59000d982...

Please read #11.

@grevil will add a MR with an isset check nevertheless to hide the warning.

anybody’s picture

PS: Maybe re-saving your fences settings on that page could also solve it.

grevil’s picture

Status: Needs work » Needs review

I created an MR, which should fix the issue for you: https://git.drupalcode.org/project/fences/-/merge_requests/47

Although, the only cases, you're warnings can happen is if $fencesSettings['fences_field_items_wrapper_tag'] and $fencesSettings['fences_field_items_wrapper_classes'] do not exist for you.

  • So you either did not run "drush updb", meaining "fences_update_8301" did not introduce those third party settings for all existing "entity_view_displays" for you.
  • "fences_update_8301" doesn't apply for your specific case.
  • Or you altered the third party settings, to remove these keys.

@anybody what do you think? Should we merge this? In theory third party settings can be altered and removed, which would cause an error here. We are using the fallback everywhere else, so I guess it makes sense!

grevil’s picture

@anybody, background:

You can always pass a fallback when using getThirdPartySetting (which we do), but you can't do that for getThirdPartySettings, so merging this only makes sense to conform with the rest of the code.

Note, that this is the only part in the code we explicitly use "getThirdPartySettingS".

anybody’s picture

@abenbow please first try re-saving your fences settings where the issue appears. If it solves that, that would be much better. Also agree with #28.

  • anybody committed e4354653 on 3.x authored by grevil
    follow-up fix to #3504624: Use fallback values for summary items
    
grevil’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

anybody’s picture

MR is safe enough now, so let's merge it. #27 makes sense.

Status: Fixed » Closed (fixed)

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