Skip to content

Commit 8226fe8

Browse files
committed
Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave: Deprecated function: array_slice(): Passing null to parameter #2 ($offset) of type int is deprecated in Drupal\Core\Config\Entity\Query\Query->execute()
1 parent 1c32ca8 commit 8226fe8

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

core/lib/Drupal/Core/Entity/Query/QueryBase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ public function notExists($property, $langcode = NULL) {
193193
* {@inheritdoc}
194194
*/
195195
public function range($start = NULL, $length = NULL) {
196-
$this->range = [
197-
'start' => $start,
196+
$this->range = $start || $length ? [
197+
'start' => $start ?? 0,
198198
'length' => $length,
199-
];
199+
] : [];
200200
return $this;
201201
}
202202

core/tests/Drupal/KernelTests/Core/Entity/ConfigEntityQueryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,27 @@ public function testSortRange() {
499499
->execute();
500500
$this->assertSame(['1', '2', '3'], array_values($this->queryResults));
501501

502+
// Omit optional parameters for the range and sort.
503+
$this->queryResults = $this->entityStorage->getQuery()
504+
->range()
505+
->sort('id')
506+
->execute();
507+
$this->assertSame(['1', '2', '3', '4', '5', '6', '7'], array_values($this->queryResults));
508+
509+
// Omit the optional start parameter for the range.
510+
$this->queryResults = $this->entityStorage->getQuery()
511+
->range(NULL, 1)
512+
->sort('id')
513+
->execute();
514+
$this->assertSame(['1'], array_values($this->queryResults));
515+
516+
// Omit the optional length parameter for the range.
517+
$this->queryResults = $this->entityStorage->getQuery()
518+
->range(4)
519+
->sort('id')
520+
->execute();
521+
$this->assertSame(['5', '6', '7'], array_values($this->queryResults));
522+
502523
// Apply a pager with limit 4.
503524
$this->queryResults = $this->entityStorage->getQuery()
504525
->pager('4', 0)

0 commit comments

Comments
 (0)