TypeError on array_filter()

Created on 7 July 2023, over 1 year ago
Updated 23 July 2024, 5 months ago

Problem/Motivation

Type Error when saving configuration.

The website encountered an unexpected error. Please try again later.
TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 274 of modules/contrib/entity_usage/src/Form/EntityUsageSettingsForm.php).
array_filter(NULL) (Line: 274)
Drupal\entity_usage\Form\EntityUsageSettingsForm->submitForm(Array, Object)

Steps to reproduce

Configuration -> Content Authoring -> Entity Usage Settings
Select a desired Field from the ENABLED LOCAL TASKS
Save Configuration.

Proposed resolution

Apply the uploaded patch.

🐛 Bug report
Status

Needs review

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Assigned to samit.310@gmail.com
  • Status changed to Needs work over 1 year ago
  • Issue was unassigned.
  • Status changed to Postponed: needs info over 1 year ago
  • 🇮🇳India samit.310@gmail.com

    Hi @lucian_pana,

    I tried to reproduce it, but not able to.

    I am not sure why are you getting this error because in the following form field, the default value is array. SO the null given in array_filter() is not possible.

        $form['local_task_enabled_entity_types']['entity_types'] = [
          '#type' => 'checkboxes',
          '#title' => $this->t('Local task entity types'),
          '#options' => $tabs_options,
          '#default_value' => $config->get('local_task_enabled_entity_types') ?: [],
        ];
    

    Please check again.

    Thanks
    Samit K.

  • 🇳🇱Netherlands Drumanuel

    Same problem here

    Entity Usage 8.x-2.0-beta12
    Drupal core 10.2.2

    TypeError: array_filter(): Argument #1 ($array) must be of type array, null given in array_filter() (line 273 of modules/contrib/entity_usage/src/Form/EntityUsageSettingsForm.php).

  • 🇮🇳India dineshkumarbollu

    Hi
    I try to reproduce the issue in Drupal 10.2 with Entity Usage 8.x-2.0-beta12 i am not getting any error. Configurations saved successfully.

  • 🇩🇪Germany stmh

    I am experiencing the same error. The provided snippet fixes it for me.

  • Status changed to Needs review 5 months ago
  • 🇨🇦Canada smulvih2 Canada 🍁

    The issue is with this code on line 273:

    array_filter($config->get('local_task_enabled_entity_types'))

    When you first install the module and go to configure it, $config->get('local_task_enabled_entity_types') will be NULL. So adding a simple ?? [] to ensure array_filter() has an empty array in this case would make sense.

  • 🇨🇦Canada smulvih2 Canada 🍁
Production build 0.71.5 2024