Issue #2068349 by pcambra, swastik1608: Convert menu link SQL queries to the Entity Query API.

8.0.x
Alex Pott 2014-03-24 11:43:05 +01:00
parent fa51d2e5bd
commit c8cfae7fd7
6 changed files with 30 additions and 21 deletions

View File

@ -1777,7 +1777,17 @@ function _menu_clear_page_cache() {
* Updates a list of menus with expanded items.
*/
function _menu_set_expanded_menus() {
$names = db_query("SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name")->fetchCol();
$names = array();
$result = Drupal::entityQueryAggregate('menu_link')
->condition('expanded', 0, '<>')
->groupBy('menu_name')
->execute();
// Flattern the resulting array.
foreach($result as $k=>$v) {
$names[$k] = $v['menu_name'];
}
\Drupal::state()->set('menu_expanded', $names);
}

View File

@ -105,8 +105,11 @@ class MenuDeleteForm extends EntityConfirmFormBase {
}
// Reset all the menu links defined by the system via hook_menu_link_defaults().
// @todo Convert this to an EFQ.
$result = $this->connection->query("SELECT mlid FROM {menu_links} WHERE menu_name = :menu AND module = 'system' ORDER BY depth ASC", array(':menu' => $this->entity->id()), array('fetch' => \PDO::FETCH_ASSOC))->fetchCol();
$result = \Drupal::entityQuery('menu_link')
->condition('menu_name', $this->entity->id())
->condition('module', 'system')
->sort('depth', 'ASC')
->execute();
$menu_links = $this->storageController->loadMultiple($result);
foreach ($menu_links as $link) {
$link->reset();

View File

@ -88,10 +88,11 @@ class BreadcrumbTest extends MenuTestBase {
);
$this->assertBreadcrumb('admin/structure/menu/manage/tools', $trail);
$mlid_node_add = db_query('SELECT mlid FROM {menu_links} WHERE link_path = :href AND module = :module', array(
':href' => 'node/add',
':module' => 'system',
))->fetchField();
$mlid_node_add = \Drupal::entityQuery('menu_link')
->condition('link_path', 'node/add')
->condition('module', 'system')
->execute();
$mlid_node_add = reset($mlid_node_add);
$trail += array(
'admin/structure/menu/manage/tools' => t('Tools'),
);

View File

@ -155,9 +155,7 @@ class LinksTest extends WebTestBase {
// links.
$links = $this->createLinkHierarchy($module);
// Don't do that at home.
db_delete('menu_links')
->condition('mlid', $links['child-1']['mlid'])
->execute();
entity_delete_multiple('menu_link', array($links['child-1']['mlid']));
$expected_hierarchy = array(
'parent' => FALSE,

View File

@ -133,13 +133,11 @@ class MenuRouterTest extends WebTestBase {
menu_link_maintain('menu_test', 'insert', 'menu_test_maintain/2', 'Menu link #2');
// Move second link to the main-menu, to test caching later on.
db_update('menu_links')
->fields(array('menu_name' => 'main'))
->condition('link_title', 'Menu link #1-main')
->condition('customized', 0)
->condition('module', 'menu_test')
->execute();
menu_cache_clear_all();
$menu_links_to_update = entity_load_multiple_by_properties('menu_link', array('link_title' => 'Menu link #1-main', 'customized' => 0, 'module' => 'menu_test'));
foreach ($menu_links_to_update as $menu_link) {
$menu_link->menu_name = 'main';
$menu_link->save();
}
// Load front page.
$this->drupalGet('');

View File

@ -472,13 +472,12 @@ function toolbar_get_rendered_subtrees() {
$item = $tree_item['link'];
if (!$item['hidden'] && $item['access']) {
if ($item['has_children']) {
$query = db_select('menu_links');
$query->addField('menu_links', 'mlid');
$query->condition('has_children', 1);
$query = \Drupal::entityQuery('menu_link')
->condition('has_children', 1);
for ($i=1; $i <= $item['depth']; $i++) {
$query->condition('p' . $i, $item['p' . $i]);
}
$parents = $query->execute()->fetchCol();
$parents = $query->execute();
$subtree = menu_build_tree($item['menu_name'], array('expanded' => $parents, 'min_depth' => $item['depth']+1));
toolbar_menu_navigation_links($subtree);
$subtree = menu_tree_output($subtree);