You are here

public function MenuTreeStorage::loadByProperties in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::loadByProperties()

Loads multiple plugin definitions from the storage based on properties.

Parameters

array $properties: The properties to filter by.

Return value

array An array of menu link definition arrays.

Throws

\InvalidArgumentException Thrown if an invalid property name is specified in $properties.

Overrides MenuTreeStorageInterface::loadByProperties

2 calls to MenuTreeStorage::loadByProperties()
MenuTreeStorage::delete in core/lib/Drupal/Core/Menu/MenuTreeStorage.php
Deletes a menu link definition from the storage.
MenuTreeStorage::purgeMultiple in core/lib/Drupal/Core/Menu/MenuTreeStorage.php
Purges multiple menu links that no longer exist.

File

core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 660

Class

MenuTreeStorage
Provides a menu tree storage using the database.

Namespace

Drupal\Core\Menu

Code

public function loadByProperties(array $properties) {
  $query = $this->connection
    ->select($this->table, $this->options);
  $query
    ->fields($this->table, $this
    ->definitionFields());
  foreach ($properties as $name => $value) {
    if (!in_array($name, $this
      ->definitionFields(), TRUE)) {
      $fields = implode(', ', $this
        ->definitionFields());
      throw new \InvalidArgumentException("An invalid property name, {$name} was specified. Allowed property names are: {$fields}.");
    }
    $query
      ->condition($name, $value);
  }
  $loaded = $this
    ->safeExecuteSelect($query)
    ->fetchAllAssoc('id', \PDO::FETCH_ASSOC);
  foreach ($loaded as $id => $link) {
    $loaded[$id] = $this
      ->prepareLink($link);
  }
  return $loaded;
}