1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 16:26:59 +02:00
This commit is contained in:
Ryan Cramer
2023-01-06 08:50:10 -05:00
parent 834f3507d5
commit d45a6be4df

View File

@@ -1409,12 +1409,33 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
}
foreach($data as $item) {
/** @var Wire $item */
$key = $this->getItemPropertyValue($item, $property);
if($item instanceof Wire) {
$key = $this->getItemPropertyValue($item, $property);
} else if(is_object($item)) {
if($property === '') {
$key = method_exists($item, '__toString') ? "$item" : wireClassName($item);
} else {
$key = $item->$property;
}
} else if(is_array($item)) {
$key = isset($item[$property]) ? $item[$property] : null;
} else {
// $property does not apply to non-object/non-array items
$key = $item;
}
// if item->property resolves to another Wire, then try to get the subProperty from that Wire (if it exists)
if($key instanceof Wire && $subProperty) {
$key = $this->getItemPropertyValue($key, $subProperty);
// if theres a $subProperty and $key resolves to a containing type, then try to get it
if($subProperty && $key) {
if($key instanceof Wire) {
$key = $this->getItemPropertyValue($key, $subProperty);
} else if(is_object($key)) {
$key = $key->$subProperty;
} else if(is_array($key)) {
$key = isset($key[$subProperty]) ? $key[$subProperty] : null;
} else {
// no containing type, $subProperty ignored
}
}
if($key === null) {