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
Comment #2
flocondetoileThanks for reporting.
Comment #4
flocondetoileComment #5
flocondetoile2.x version fixed