I'm encountering the following warning when saving an entity that uses the Protected File field type:

Warning: Undefined array key "protected_file" in Drupal\protected_file\Plugin\Field\FieldWidget\ProtectedFileWidget::process() (line 88 of modules/contrib/protected_file/src/Plugin/Field/FieldWidget/ProtectedFileWidget.php)

This happens when the widget attempts to access $item['protected_file'], but the key doesn't exist for all items.

Use a safer fallback to avoid the warning:

'#value' => (isset($item['protected_file']) && $item['protected_file']) ? 1 : 0,

This avoids accessing undefined array keys and prevents unnecessary PHP warnings.

Drupal 9.5.11
PHP 8.1.32

Comments

forward-media created an issue. See original summary.

flocondetoile’s picture

Thanks for reporting.

  • 007e84d0 committed on 2.0.x
    Issue #3532248 by forward-media, flocondetoile: Warning: Undefined array...
flocondetoile’s picture

Status: Active » Fixed
flocondetoile’s picture

Version: 8.x-1.5 » 2.0.0

2.x version fixed

Status: Fixed » Closed (fixed)

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