Skip to content

fix(portalblocks): handle null/unset rows in sparse layout arrays#69

Merged
ralflang merged 1 commit intoFRAMEWORK_6_0from
fix/block-layout-null-handling
Mar 17, 2026
Merged

fix(portalblocks): handle null/unset rows in sparse layout arrays#69
ralflang merged 1 commit intoFRAMEWORK_6_0from
fix/block-layout-null-handling

Conversation

@ralflang
Copy link
Member

When block layout arrays have gaps (sparse arrays), count() returns
lastindex+1 ignoring omitted indices and this causes all kinds of errors.
isset() and is_array() checks before calling count() fix this now.

When block layout arrays have gaps (sparse arrays), count() returns
lastindex+1 ignoring omitted indices and this causes all kinds of errors.
isset() and is_array() checks before calling count() fix this now.
@ralflang ralflang requested review from TDannhauer and amulet1 March 17, 2026 20:33
@ralflang ralflang merged commit 60acc46 into FRAMEWORK_6_0 Mar 17, 2026
0 of 4 checks passed
if (!isset($this->_layout[$row]) || !is_array($this->_layout[$row])) {
continue;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is the right thing to do.

If I undestand correctly, the _layout array can have non-consecutive indexes. And we want to go over each one that exists.

But the for loop only goes up to count($this->_layout), which could miss some indexes.

Example:

$this->_layout = [ 0 => $value1, 10 => $value2 ];

in this case $rows = 2 and the for loop would only check row 0 and 1, but not row 10.

Possible solutions:

  • use foreach, need to redesign "if (isset($field['height'])) {" block as it refers to other rows (could they also be non-consecutive?)
  • alternatively, avoid sparse arrays or make it non-sparse in the constructor?

@@ -93,6 +93,11 @@
$emptyrows = [];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop $emptyrows (looks like it is assigned but never used).

if (!isset($this->_layout[$row]) || !is_array($this->_layout[$row])) {
return true;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to rowExists method (it has to be redesigned as it does not work correctly for sparse arrays).

public function rowExists($row)
{
return $row < count($this->_layout);
}
Copy link
Contributor

@amulet1 amulet1 Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly change to this to support sparse _layout array:

return isset($this->_layout[$row]) && is_array($this->_layout[$row]);

And then it can be used in the contructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants