TrashSettingsForm crash if deleted field does not exist

Created on 21 August 2023, over 1 year ago
Updated 4 October 2023, about 1 year ago

Problem/Motivation

TrashSettingsForm does not properly check if the "deleted" field exists when setting the default "trashable" value for an entity type.

Steps to reproduce

If one has an entity type which does not have a "deleted" field and visits /admin/config/content/trash the page will crash with an exception.


TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 112 of modules/contrib/trash/src/Form/TrashSettingsForm.php).
Drupal\trash\Form\TrashSettingsForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('trash_settings_form', Object) (Line: 283)
...

Proposed resolution

The problematic line is '#default_value' => isset($field_definitions['deleted']) || in_array($entity_type_id, $config->get('enabled_entity_types')),.
Fix the condition to be '#default_value' => isset($field_definitions['deleted']) && in_array($entity_type_id, $config->get('enabled_entity_types')),.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ΈπŸ‡ͺSweden twod Sweden

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

Comments & Activities

Production build 0.71.5 2024