diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php
index 0ae93d4..41bbcae 100644
--- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php
+++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php
@@ -323,7 +323,7 @@ function doMenuTests($menu_name) {
     ));
 
     // Add 102 menu links with increasing weights, then make sure the last-added
-    // item's weight doesn't get changed because of the old hardcoded delta=50
+    // item's weight doesn't change because of the old hardcoded delta = 50.
     $items = array();
     for ($i = -50; $i <= 51; $i++) {
       $items[$i] = $this->addMenuLink(0, 'node/' . $node1->id(), $menu_name, TRUE, strval($i));
diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module
index 6e208c3..f461fba 100644
--- a/core/modules/menu/menu.module
+++ b/core/modules/menu/menu.module
@@ -598,8 +598,8 @@ function menu_form_node_form_alter(&$form, $form_state) {
     '#attributes' => array('class' => array('menu-parent-select')),
   );
 
-  // Get number of items in menu so the weight selector is sized appropriately.
-  $delta = entity_get_controller('menu_link')->countMenuLinks($link->menu_name);
+  // Get the needed range in menu so the weight selector is sized appropriately.
+  $delta = entity_get_controller('menu_link')->menuLinksSize($link->menu_name) + 1;
   if ($delta < 50) {
     // Old hardcoded value
     $delta = 50;
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 43d54ce..76cc14f 100644
--- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
+++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageController.php
@@ -11,6 +11,7 @@
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityStorageException;
 use Drupal\Core\Database\Connection;
+use Drupal\Core\Entity\Query\QueryFactory;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Cmf\Component\Routing\RouteProviderInterface;
 
@@ -44,6 +45,13 @@ class MenuLinkStorageController extends DatabaseStorageController implements Men
   protected $routeProvider;
 
   /**
+   * The entity query factory.
+   *
+   * @var \Drupal\Core\Entity\Query\QueryFactory
+   */
+  protected $entityQueryFactory;
+
+  /**
    * Overrides DatabaseStorageController::__construct().
    *
    * @param string $entity_type
@@ -54,11 +62,14 @@ class MenuLinkStorageController extends DatabaseStorageController implements Men
    *   The database connection to be used.
    * @param \Symfony\Cmf\Component\Routing\RouteProviderInterface $route_provider
    *   The route provider service.
+   * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory
+   *   The entity query factory.l
    */
-  public function __construct($entity_type, array $entity_info, Connection $database, RouteProviderInterface $route_provider) {
+  public function __construct($entity_type, array $entity_info, Connection $database, RouteProviderInterface $route_provider, QueryFactory $entity_query_factory) {
     parent::__construct($entity_type, $entity_info, $database);
 
     $this->routeProvider = $route_provider;
+    $this->entityQueryFactory = $entity_query_factory;
 
     if (empty(static::$routerItemFields)) {
       static::$routerItemFields = array_diff(drupal_schema_fields_sql('menu_router'), array('weight'));
@@ -85,7 +96,8 @@ public static function createInstance(ContainerInterface $container, $entity_typ
       $entity_type,
       $entity_info,
       $container->get('database'),
-      $container->get('router.route_provider')
+      $container->get('router.route_provider'),
+      $container->get('entity.query')
     );
   }
 
@@ -400,4 +412,19 @@ public function getParentFromHierarchy(EntityInterface $entity) {
     return $parent;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function menuLinksSize($menu_name) {
+    $query = $this->entityQueryFactory->getAggregate($this->entityType)
+      ->aggregate('weight', 'MAX')
+      ->aggregate('weight', 'MIN')
+      ->condition('menu_name', $menu_name);
+    $result = $query->execute();
+    $item = reset($result);
+    // Menu links can have both positive and negative weights, so to find out
+    // the biggest value in total, first get the absolute value.
+    return max(abs($item['weight_min']), abs($item['weight_max']));
+  }
+
 }
diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php
index 3fb408f..6869f66 100644
--- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php
+++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkStorageControllerInterface.php
@@ -107,4 +107,18 @@ public function countMenuLinks($menu_name);
    */
   public function getParentFromHierarchy(EntityInterface $entity);
 
+  /**
+   * Returns the maximum size in weights for a given menu.
+   *
+   * So for example there is a menu with a link with weight -5 and one with 4,
+   * it should return "5".
+   *
+   * @param string $menu_name
+   *   The unique name of a menu.
+   *
+   * @return int
+   *   Returns the size of the menu links weight.
+   */
+  public function menuLinksSize($menu_name);
+
 }
diff --git a/core/modules/menu_link/lib/Drupal/menu_link/Tests/MenuLinkStorageControllerTest.php b/core/modules/menu_link/lib/Drupal/menu_link/Tests/MenuLinkStorageControllerTest.php
new file mode 100644
index 0000000..5dd5bfb
--- /dev/null
+++ b/core/modules/menu_link/lib/Drupal/menu_link/Tests/MenuLinkStorageControllerTest.php
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\menu_link\Tests\MenuLinkStorageController.
+ */
+
+namespace Drupal\menu_link\Tests;
+
+use Drupal\simpletest\DrupalUnitTestBase;
+
+/**
+ * Tests the menu link entity storage controller.
+ *
+ * @see \Drupal\menu_link\MenuLinkStorageController
+ */
+class MenuLinkStorageControllerTest extends DrupalUnitTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('menu_link', 'system', 'field_sql_storage', 'field');
+
+  /**
+   * The menu links storage controller used in the test.
+   *
+   * @var \Drupal\menu_link\MenuLinkStorageController
+   */
+  protected $storageController;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Menu link storage controller',
+      'description' => 'Tests the menu link entity storage controller.',
+      'group' => 'Menu',
+    );
+  }
+
+  protected function setUp() {
+    parent::setUp();
+
+    $this->installSchema('menu_link', 'menu_links');
+    $this->installSchema('system', 'menu_router');
+    $this->installSchema('field', array('field_config', 'field_config_instance'));
+
+    $this->storageController = $this->container->get('plugin.manager.entity')->getStorageController('menu_link');
+  }
+
+  /**
+   * Tests the link size method.
+   *
+   * @see \Drupal\menu_link\Tests\MenuLinkStorageController::menuLinksSize()
+   */
+  public function testMenuLinksSize() {
+    $menu_links = array();
+    $menu_links[] = $menu_link = $this->storageController->create(array('weight' => -5, 'menu_name' => 'tools'));
+    $menu_link->save();
+    $menu_links[] = $menu_link = $this->storageController->create(array('weight' => 6, 'menu_name' => 'tools'));
+    $menu_link->save();
+
+    $this->assertEqual($this->storageController->menuLinksSize('tools'), 6);
+    $this->assertEqual($this->storageController->menuLinksSize('non_existing_menu'), 0);
+  }
+
+}
