Warning: Undefined array key "protected_file" in ProtectedFileWidget::process()

Created on 25 June 2025, 3 days ago

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

🐛 Bug report
Status

Active

Version

1.5

Component

User interface

Created by

🇩🇪Germany forward-media

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

Comments & Activities

Production build 0.71.5 2024