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

CommentFileSizeAuthor
#3 3315720-fix-krsort-deprecation-3.patch630 bytesgauravjeet

Comments

gauravjeet created an issue. See original summary.

gauravjeet’s picture

Issue summary: View changes
gauravjeet’s picture

Status: Active » Needs review
StatusFileSize
new630 bytes

Attaching a patch for the fix. This resolves the PHP 8.1 deprecation notice and allows AJAX request to complete successfully.

  • podarok committed bf8d55b4 on 2.0.x authored by gauravjeet
    Issue #3315720 by gauravjeet: TypeError: krsort(): Argument #1 ($array)...
podarok’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Status: Needs review » Fixed

tnx

Status: Fixed » Closed (fixed)

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

geek-merlin’s picture

Version: 2.0.x-dev » 3.x-dev
Status: Closed (fixed) » Needs review
Related issues: +#3401656: Clean up problematic 2.x branch

Bulk reopen.

dcam’s picture

Status: Needs review » Needs work
Issue tags: +Needs steps to reproduce, +Needs tests

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.

geek-merlin’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs steps to reproduce, -Needs tests

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') ?? [];
geek-merlin’s picture

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:...
geek-merlin’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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