1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-10 16:54:44 +02:00

Add support for $items[] = $item; append syntax to WireArray/PageArray

This commit is contained in:
Ryan Cramer
2022-09-30 12:00:02 -04:00
parent a3e67b299b
commit 127ef175b7

View File

@@ -11,7 +11,7 @@
*
* @todo can we implement next() and prev() like on Page, as alias to getNext() and getPrev()?
*
* ProcessWire 3.x, Copyright 2021 by Ryan Cramer
* ProcessWire 3.x, Copyright 2022 by Ryan Cramer
* https://processwire.com
*
* @method WireArray and($item)
@@ -557,6 +557,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
if(is_array($key)) {
if(ctype_digit(implode('', array_keys($key)))) {
$items = array();
/** @var array $key */
foreach($key as $k) {
$item = $this->get($k);
$items[$k] = $item;
@@ -1839,7 +1840,12 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value) {
$this->set($offset, $value);
if($offset === null) {
// i.e. $wireArray[] = $item;
$this->add($value);
} else {
$this->set($offset, $value);
}
}
/**