You are here

public function MenuTreeStorage::loadByProperties in Menu Trail By Path 8

Same as parent, but with ordering

Overrides MenuTreeStorage::loadByProperties

File

src/Menu/MenuTreeStorage.php, line 14

Class

MenuTreeStorage

Namespace

Drupal\menu_trail_by_path\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);
  }

  // Make the ordering deterministic.
  $query
    ->orderBy('depth');
  $query
    ->orderBy('weight');
  $query
    ->orderBy('id');
  $loaded = $this
    ->safeExecuteSelect($query)
    ->fetchAllAssoc('id', \PDO::FETCH_ASSOC);
  foreach ($loaded as $id => $link) {
    $loaded[$id] = $this
      ->prepareLink($link);
  }
  return $loaded;
}