public \Joomla\CMS\Menu\MenuItem|\Joomla\CMS\Menu\MenuItem[]
getItems
(mixed $attributes, mixed $values, mixed $firstonly = false)
/**
* Gets menu items by attribute
*
* @param mixed $attributes The field name(s).
* @param mixed $values The value(s) of the field. If an array, need to match field names
* each attribute may have multiple values to lookup for.
* @param boolean $firstonly If true, only returns the first item found
*
* @return MenuItem|MenuItem[] An array of menu item objects or a single object if the $firstonly parameter is true
*
* @since 1.5
*/
public function getItems($attributes, $values, $firstonly = false)
{
$items = array();
$attributes = (array) $attributes;
$values = (array) $values;
$count = \count($attributes);
foreach ($this->getMenu() as $item) {
if (!\is_object($item)) {
continue;
}
$test = true;
for ($i = 0; $i < $count; $i++) {
if (\is_array($values[$i])) {
if (!\in_array($item->{$attributes[$i]}, $values[$i])) {
$test = false;
break;
}
} else {
if ($item->{$attributes[$i]} != $values[$i]) {
$test = false;
break;
}
}
}
if ($test) {
if ($firstonly) {
return $item;
}
$items[] = $item;
}
}
return $items;
}