diff --git a/core/includes/common.inc b/core/includes/common.inc index e4dcd65..42c7706 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -6202,15 +6202,15 @@ function drupal_sort_title($a, $b) { * An integer used by uasort(). */ function drupal_sort_label($a, $b) { - $labelb = $b->label(); - if (empty($labelb)) { + $b_label = $b->label(); + if (empty($b_label)) { return -1; } - $labela = $a->label(); - if (empty($labela)) { + $a_label = $a->label(); + if (empty($a_label)) { return 1; } - return strcasecmp($labela, $labelb); + return strcasecmp($a_label, $b_label); } /** diff --git a/core/includes/menu.inc b/core/includes/menu.inc index f525b25..66df567 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -678,10 +678,9 @@ function _menu_item_localize(&$item, $map) { } // If the title and description are the same, use the translated description // as a localized title. - // @todo Take care of 'localized_options' later. -// if (isset($original_description) && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) { -// $item['localized_options']['attributes']['title'] = $item['description']; -// } + if (isset($original_description) && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) { + $item['localized_options']['attributes']['title'] = $item['description']; + } } /** @@ -1097,8 +1096,9 @@ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) { // p columns and 0 (the top level) with the plid values of other links. $parents = array(0); for ($i = 1; $i < MENU_MAX_DEPTH; $i++) { - if (!empty($link->{"p$i"})) { - $parents[] = $link->{"p$i"}; + $parent_property = "p$i"; + if (!empty($link->$parent_property)) { + $parents[] = $link->$parent_property; } } $tree_parameters['expanded'] = $parents; @@ -1237,8 +1237,9 @@ function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = // Use all the coordinates, except the last one because there // can be no child beyond the last column. for ($i = 1; $i < MENU_MAX_DEPTH; $i++) { - if ($active_link->{"p$i"}) { - $active_trail[$active_link->{"p$i"}] = $active_link->{"p$i"}; + $parent_property = "p$i"; + if ($active_link->$parent_property) { + $active_trail[$active_link->$parent_property] = $active_link->$parent_property; } } // If we are asked to build links for the active trail only, skip diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 9b45730..4c85673 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -481,8 +481,8 @@ function aggregator_save_category($edit) { ->execute(); $op = 'insert'; } - if (isset($op) && module_exists('menu_link')) { - menu_link_maintain('aggregator', $op, $link_path, $edit['title']); + if (isset($op)) { + module_invoke('menu_link', 'maintain', 'aggregator', $op, $link_path, $edit['title']); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php index cf692c4..a8ac6c5 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedItemTest.php @@ -32,8 +32,8 @@ function testCategorizeFeedItem() { $this->assertTrue(!empty($category), 'The category found in database.'); $link_path = 'aggregator/categories/' . $category->cid; - $menu_link = entity_load_multiple_by_properties('menu_link', array('link_path' => $link_path)); - $this->assertTrue(!empty($menu_link), 'The menu link associated with the category found in database.'); + $menu_links = entity_load_multiple_by_properties('menu_link', array('link_path' => $link_path)); + $this->assertTrue(!empty($menu_links), 'The menu link associated with the category found in database.'); $feed = $this->createFeed(); db_insert('aggregator_category_feed') diff --git a/core/modules/help/help.admin.inc b/core/modules/help/help.admin.inc index 0a8e147..b086d9a 100644 --- a/core/modules/help/help.admin.inc +++ b/core/modules/help/help.admin.inc @@ -45,7 +45,7 @@ function help_page($name) { if (!empty($admin_tasks)) { $links = array(); foreach ($admin_tasks as $task) { - $links[] = l($task['title'], $task['link_path'], $task['localized_options']); + $links[] = l($task->label(), $task->link_path, $task->localized_options); } $output .= theme('item_list', array('items' => $links, 'title' => t('@module administration pages', array('@module' => $info[$name]['name'])))); } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLink.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLink.php index 0c3a81a..ab00f13 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLink.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLink.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\Entity; +use Drupal\user\User; /** * Defines the menu link entity class. @@ -110,6 +111,9 @@ class MenuLink extends Entity implements ContentEntityInterface { /** * @var integer + * + * @todo Investigate whether the p1, p2, .. pX properties can be moved to a + * single array property. */ public $p1; @@ -162,15 +166,16 @@ class MenuLink extends Entity implements ContentEntityInterface { /** * Computed property. - * @todo Describe it. + * @todo Make it protected and describe it. * * @var string */ public $href; /** - * Computed property. - * @todo Describe it. + * This computed property holds (actually, will hold) the translated label of + * a menu link. + * @todo Rename to $label perhaps? * * @var string */ @@ -178,7 +183,7 @@ class MenuLink extends Entity implements ContentEntityInterface { /** * Computed property. - * @todo Describe it. + * @todo Make it protected and describe it. * * @var bool */ @@ -186,7 +191,7 @@ class MenuLink extends Entity implements ContentEntityInterface { /** * Computed property. - * @todo Describe it. + * @todo Make it protected and describe it. * * @var array */ @@ -245,7 +250,7 @@ public function createDuplicate() { /** * Overrides Drupal\entity\Entity::access(). */ - public function access(\Drupal\user\User $account = NULL) { + public function access(User $account = NULL) { if ($this->external) { $this->access = TRUE; } diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php index ff0dea4..44d67cd 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -43,6 +43,8 @@ public function form(array $form, array &$form_state, EntityInterface $menu_link // Any item created or edited via this interface is considered "customized". $form['customized'] = array('#type' => 'value', '#value' => 1); + // We are not using url() when constructing this path because it would add + // $base_path. $path = $menu_link->link_path; if (isset($menu_link->options['query'])) { $path .= '?' . drupal_http_build_query($menu_link->options['query']); diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php index 93072fe..b2d18e9 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php @@ -58,6 +58,9 @@ protected function buildQuery($ids, $revision_id = FALSE) { /** * Overrides Drupal\entity\DatabaseStorageController::attachLoad(). + * + * @todo Don't call parent::attachLoad() at all because we want to be able to + * control the entity load hooks. */ protected function attachLoad(&$menu_links, $load_revision = FALSE) { foreach ($menu_links as &$menu_link) { @@ -119,7 +122,7 @@ public function save(EntityInterface $entity) { // array_intersect_key() with the $entity as the first parameter because // $entity may have additional keys left over from building a router entry. // The intersect removes the extra keys, allowing a meaningful comparison. - if ($entity->isNew() || (array_intersect_key((array) $entity, (array) $entity->original) != (array) $entity->original)) { + if ($entity->isNew() || (array_intersect_key(get_object_vars($entity), get_object_vars($entity->original)) != get_object_vars($entity->original))) { $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey); if ($return) { @@ -176,7 +179,8 @@ protected function preSave(EntityInterface $entity) { if ($entity->plid == 0) { $entity->p1 = $entity->id(); for ($i = 2; $i <= MENU_MAX_DEPTH; $i++) { - $entity->p{$i} = 0; + $parent_property = "p$i"; + $entity->$parent_property = 0; } $entity->depth = 1; } @@ -375,22 +379,6 @@ protected function updateParentalStatus(EntityInterface $entity, $exclude = FALS $parent_entity = reset($parent_entity); $parent_entity->has_children = $parent_has_children; $parent_entity->save(); - - -// $query = db_select($this->entityInfo['base table']); -// $query->addField($this->entityInfo['base table'], 'mlid'); -// $query->condition('menu_name', ); -// $query->condition('hidden', 0); -// $query->condition('plid', $entity->plid); -// $query->range(0, 1); -// if ($exclude) { -// $query->condition('mlid', $entity->id(), '<>'); -// } -// $parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0; -// db_update($this->entityInfo['base table']) -// ->fields(array('has_children' => $parent_has_children)) -// ->condition('mlid', $entity->plid) -// ->execute(); } } @@ -431,7 +419,8 @@ protected function findParent(EntityInterface $entity, array $parent_candidates // Else, if we have a link hierarchy try to find a valid parent in there. if (!empty($entity->depth) && $entity->depth > 1) { for ($depth = $entity->depth - 1; $depth >= 1; $depth--) { - $candidates[] = $entity->{"p$depth"}; + $parent_property = "p$depth"; + $candidates[] = $entity->$parent_property; } } @@ -468,9 +457,10 @@ protected function findParent(EntityInterface $entity, array $parent_candidates $parent_path = substr($parent_path, 0, strrpos($parent_path, '/')); $new_query = clone $query; $new_query->propertyCondition('link_path', $parent_path); + + $count_query = clone $new_query; // Only valid if we get a unique result. - if ($new_query->count()->execute() == 1) { - $new_query->count = FALSE; + if ($count_query->count()->execute() == 1) { $result = $new_query->execute(); $parent = $this->load(array(key($result[$this->entityType]))); $parent = reset($parent); diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php index 85aa3f6..627485c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/RouterTest.php @@ -304,8 +304,8 @@ function testMenuName() { $admin_user = $this->drupalCreateUser(array('administer site configuration')); $this->drupalLogin($admin_user); - $menu_link = entity_load_multiple_by_properties('menu_link', array('router_path' => 'menu_name_test')); - $menu_link = reset($menu_link); + $menu_links = entity_load_multiple_by_properties('menu_link', array('router_path' => 'menu_name_test')); + $menu_link = reset($menu_links); $this->assertEqual($menu_link->menu_name, 'original', 'Menu name is "original".'); // Change the menu_name parameter in menu_test.module, then force a menu @@ -313,8 +313,8 @@ function testMenuName() { menu_test_menu_name('changed'); menu_router_rebuild(); - $menu_link = entity_load_multiple_by_properties('menu_link', array('router_path' => 'menu_name_test')); - $menu_link = reset($menu_link); + $menu_links = entity_load_multiple_by_properties('menu_link', array('router_path' => 'menu_name_test')); + $menu_link = reset($menu_links); $this->assertEqual($menu_link->menu_name, 'changed', 'Menu name was successfully changed after rebuild.'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php index 4ccc1f4..c78846c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/TreeOutputTest.php @@ -35,6 +35,7 @@ function setUp() { * Validate the generation of a proper menu tree output. */ function testMenuTreeData() { + // @todo Prettify this tree buildup code, it's very hard to read. $this->tree_data = array( '1'=> array( 'link' => new MenuLink(array('menu_name' => 'main-menu', 'mlid' => 1, 'hidden' => 0, 'has_children' => 1, 'title' => 'Item 1', 'in_active_trail' => 1, 'access' => 1, 'href' => 'a', 'localized_options' => array('attributes' => array('title' =>''))), 'menu_link'), diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index d27dfa8..ab2a1ac 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -42,6 +42,7 @@ function system_admin_config_page() { // } $block = $menu_link->router_item; $block['content'] = ''; + // @todo Convert this to a render array. $block['content'] .= theme('admin_block_content', array('content' => system_admin_menu_block($menu_link->router_item))); if (!empty($block['content'])) { $block['show'] = TRUE; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index b2be0de..085a797 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2598,8 +2598,8 @@ function system_admin_menu_block($item) { } if (!isset($item['mlid'])) { - $menu_link = entity_load_multiple_by_properties('menu_link', array('router_path' => $item['path'], 'module' => 'system')); - $menu_link = reset($menu_link); + $menu_links = entity_load_multiple_by_properties('menu_link', array('router_path' => $item['path'], 'module' => 'system')); + $menu_link = reset($menu_links); $item['mlid'] = $menu_link->id(); $item['menu_name'] = $menu_link->menu_name; }