You are here

function menu_link_load_multiple in Menu Link (Field) 7

Load multiple menu links, access checked and link translated for rendering.

This function should never be called from within node_load() or any other function used as a menu object load function since an infinite recursion may occur.

@todo Remove this function when http://drupal.org/node/1034732 lands.

Parameters

$mlids array: An array of menu link IDs.

$conditions array: An associative array of conditions on the {menu_links} table, where the keys are the database fields and the values are the values those fields must have.

Return value

An array of menu links indexed by mlid.

See also

menu_link_load()

3 calls to menu_link_load_multiple()
menu_link_delete_multiple in ./menu_link.module
Delete multiple menu links.
menu_link_field_formatter_prepare_view in ./menu_link.field.inc
Implements hook_field_formatter_prepare_view().
menu_link_field_validate in ./menu_link.field.inc
Implements hook_field_validate().

File

./menu_link.module, line 57

Code

function menu_link_load_multiple(array $mlids, array $conditions = array()) {
  $query = db_select('menu_links', 'ml', array(
    'fetch' => PDO::FETCH_ASSOC,
  ));
  $query
    ->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
  $query
    ->fields('ml');

  // Weight should be taken from {menu_links}, not {menu_router}.
  $query
    ->addField('ml', 'weight', 'link_weight');
  $query
    ->fields('m');
  if (!empty($mlids)) {
    $query
      ->condition('ml.mlid', $mlids, 'IN');
  }
  if (!empty($conditions)) {
    foreach ($conditions as $field => $value) {
      $query
        ->condition('ml.' . $field, $value);
    }
  }
  $items = array();
  foreach ($query
    ->execute() as $item) {
    $item['weight'] = $item['link_weight'];
    $items[$item['mlid']] = $item;
    _menu_link_translate($items[$item['mlid']]);
  }
  return $items;
}