TypeError: krsort(): Argument #1 ($array) must be of type array, null given in krsort()

Created on 17 October 2022, almost 2 years ago
Updated 21 January 2024, 8 months ago

Problem/Motivation

Running into this error while placing a block to a page using Layout Builder

TypeError: krsort(): Argument #1 ($array) must be of type array, null given in krsort()

Steps to reproduce

- Use a Drupal node that has Layout Builder enabled
- Go to the Layout Builder configure page
- Try to place a block
- The AJAX response gives out an error reported above

Proposed resolution

- Use the null coalescing operator to replace NULL with an empty array so that PHP 8.1 does not report a Deprecation error

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇳India gauravjeet

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.

  • 🇺🇦Ukraine podarok Ukraine

    tnx

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

  • Status changed to Needs review 10 months ago
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Bulk reopen.

  • Status changed to Needs work 9 months ago
  • 🇺🇸United States dcam

    This needs better steps to reproduce the problem, specifically in regard to the configuration of the entities involved. Does the node have the IEF field or the block? Are you placing the block on the node type's default layout or customizing the layout of a single node? Does the IEF field (whatever entity it's attached to) need to have entities referenced or be empty? I've tried every combination that I can think of and can't reproduce the problem. I'll admit that the code looks like it has this issue. But if it can't be reproduced then that's a problem because if it's a bug then this also needs tests.

  • Status changed to RTBC 9 months ago
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Ohoh, i remember well when i coded that. Context:

        $widget_states =& $form_state->get('inline_entity_form');
        // Widget states can be in an arbitrary order depending on user's form
        // interaction. We sort them lexicographically in reverse order to get inner
        // forms before outer forms, to ensure inside-out saving of entities.
        // @see \Drupal\inline_entity_form\Plugin\Field\FieldWidget\InlineEntityFormBase::makeIefId
        krsort($widget_states, SORT_STRING);
    

    No guarantee that there are widget states at this point. So it's as simple as this one with no regression risk:

     $widget_states =& $form_state->get('inline_entity_form') ?? [];
    
  • 🇩🇪Germany geek-merlin Freiburg, Germany

    Ah, i forgot the

    =&
    

    which makes #9 impossible and mandates the extra line from #3.

    • geek-merlin committed 84fdbdbe on 3.x
      Issue #3315720 by gauravjeet, geek-merlin, podarok, dcam: TypeError:...
  • Status changed to Fixed 9 months ago
  • 🇩🇪Germany geek-merlin Freiburg, Germany
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024