diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index e1242c6..4d59117 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -237,13 +237,20 @@ public function createDuplicate() {
    * Helper callback for uasort() to sort configuration entities by weight and label.
    */
   public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
-    $a_weight = isset($a->weight) ? $a->weight : 0;
-    $b_weight = isset($b->weight) ? $b->weight : 0;
-    if ($a_weight == $b_weight) {
-      $a_label = $a->label();
-      $b_label = $b->label();
-      return strnatcasecmp($a_label, $b_label);
+    $entity_type = $a->getEntityType();
+    if ($entity_type->hasKey('weight')) {
+      $weight_key = $entity_type->getKey('weight');
+      $a_weight = isset($a->$weight_key) ? $a->$weight_key : 0;
+      $b_weight = isset($b->$weight_key) ? $b->$weight_key : 0;
     }
+    else {
+      $a_weight = $b_weight = 0;
+    }
+
+    if ($a_weight == $b_weight) {
+      return strnatcasecmp($a->label(), $b->label());
+    }
+
     return ($a_weight < $b_weight) ? -1 : 1;
   }
 
diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php
index e1eb60e..73774ed 100644
--- a/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php
+++ b/core/lib/Drupal/Core/Config/Entity/DraggableListBuilder.php
@@ -40,6 +40,13 @@
   protected $weightKey = FALSE;
 
   /**
+   * HTML class to identify the weight input elements.
+   *
+   * @var string|bool
+   */
+  protected $weightClass = FALSE;
+
+  /**
    * The form builder.
    *
    * @var \Drupal\Core\Form\FormBuilderInterface
@@ -55,6 +62,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter
     // Check if the entity type supports weighting.
     if ($this->entityType->hasKey('weight')) {
       $this->weightKey = $this->entityType->getKey('weight');
+      $this->weightClass = \Drupal\Component\Utility\Html::getClass($this->weightKey);
     }
   }
 
@@ -64,7 +72,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter
   public function buildHeader() {
     $header = array();
     if (!empty($this->weightKey)) {
-      $header['weight'] = t('Weight');
+      $header[$this->weightKey] = t('Weight');
     }
     return $header + parent::buildHeader();
   }
@@ -79,12 +87,12 @@ public function buildRow(EntityInterface $entity) {
       $row['#attributes']['class'][] = 'draggable';
       $row['#weight'] = $entity->get($this->weightKey);
       // Add weight column.
-      $row['weight'] = array(
+      $row[$this->weightKey] = array(
         '#type' => 'weight',
         '#title' => t('Weight for @title', array('@title' => $entity->label())),
         '#title_display' => 'invisible',
         '#default_value' => $entity->get($this->weightKey),
-        '#attributes' => array('class' => array('weight')),
+        '#attributes' => array('class' => array($this->weightClass)),
       );
     }
     return $row + parent::buildRow($entity);
@@ -112,7 +120,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
         array(
           'action' => 'order',
           'relationship' => 'sibling',
-          'group' => 'weight',
+          'group' => $this->weightClass,
         ),
       ),
     );
@@ -131,8 +139,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       if (isset($row['label'])) {
         $row['label'] = array('#markup' => $row['label']);
       }
-      if (isset($row['weight'])) {
-        $row['weight']['#delta'] = $delta;
+      if (isset($row[$this->weightKey])) {
+        $row[$this->weightKey]['#delta'] = $delta;
       }
       $form[$this->entitiesKey][$entity->id()] = $row;
     }
@@ -159,9 +167,9 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     foreach ($form_state->getValue($this->entitiesKey) as $id => $value) {
-      if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value['weight']) {
+      if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value[$this->weightKey]) {
         // Save entity only when its weight was changed.
-        $this->entities[$id]->set($this->weightKey, $value['weight']);
+        $this->entities[$id]->set($this->weightKey, $value[$this->weightKey]);
         $this->entities[$id]->save();
       }
     }
diff --git a/core/modules/config/src/Tests/ConfigEntityListTest.php b/core/modules/config/src/Tests/ConfigEntityListTest.php
index 275136d..ef7d88b 100644
--- a/core/modules/config/src/Tests/ConfigEntityListTest.php
+++ b/core/modules/config/src/Tests/ConfigEntityListTest.php
@@ -108,7 +108,10 @@ function testList() {
     ));
     $entity->save();
     $list = $controller->load();
-    $this->assertIdentical(array_keys($list), array('beta', 'dotted.default', 'alpha', 'omega'));
+    // The config_test config entity type has no defined weight key, so the
+    // sorting only uses the label however the "weight" property is exists.
+    // The labels after the sorting are: Alpha, Beta, Default and Omega.
+    $this->assertIdentical(array_keys($list), array('alpha', 'beta', 'dotted.default', 'omega'));
 
     // Test that config entities that do not support status, do not have
     // enable/disable operations.
@@ -198,7 +201,7 @@ function testListUI() {
 
     // Edit the entity using the operations link.
     $this->assertLinkByHref('admin/structure/config_test/manage/antelope');
-    $this->clickLink('Edit', 1);
+    $this->clickLink('Edit', 0);
     $this->assertResponse(200);
     $this->assertTitle('Edit Antelope | Drupal');
     $edit = array('label' => 'Albatross', 'id' => 'albatross');
@@ -212,7 +215,7 @@ function testListUI() {
 
     // Delete the added entity using the operations link.
     $this->assertLinkByHref('admin/structure/config_test/manage/albatross/delete');
-    $this->clickLink('Delete', 1);
+    $this->clickLink('Delete', 0);
     $this->assertResponse(200);
     $this->assertTitle('Are you sure you want to delete the test configuration Albatross? | Drupal');
     $this->drupalPostForm(NULL, array(), t('Delete'));
diff --git a/core/modules/search/src/SearchPageRepository.php b/core/modules/search/src/SearchPageRepository.php
index 66f7bda..17dd363 100644
--- a/core/modules/search/src/SearchPageRepository.php
+++ b/core/modules/search/src/SearchPageRepository.php
@@ -110,7 +110,9 @@ public function setDefaultSearchPage(SearchPageInterface $search_page) {
    */
   public function sortSearchPages($search_pages) {
     $entity_type = $this->storage->getEntityType();
-    uasort($search_pages, array($entity_type->getClass(), 'sort'));
+    // Suppress errors because PHPUnit will indirectly modify the contents,
+    // triggering https://bugs.php.net/bug.php?id=50688.
+    @uasort($search_pages, array($entity_type->getClass(), 'sort'));
     return $search_pages;
   }
 
diff --git a/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php b/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
index 767a81b..eaef7c0 100644
--- a/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
+++ b/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Tests\search\Unit;
 
+use Drupal\Core\DependencyInjection\ContainerBuilder;
 use Drupal\search\Entity\SearchPage;
 use Drupal\search\SearchPageRepository;
 use Drupal\Tests\UnitTestCase;
@@ -255,6 +256,15 @@ public function testSortSearchPages() {
     $this->storage->expects($this->once())
       ->method('getEntityType')
       ->will($this->returnValue($entity_type));
+    $entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
+    $entity_manager->expects($this->atLeastOnce())
+      ->method('getDefinition')
+      ->with('search_page')
+      ->willReturn($entity_type);
+
+    $container = new ContainerBuilder();
+    $container->set('entity.manager', $entity_manager);
+    \Drupal::setContainer($container);
 
     // Declare entities out of their expected order so we can be sure they were
     // sorted. We cannot mock these because of uasort(), see
@@ -277,6 +287,7 @@ public function __construct(array $values) {
     foreach ($values as $key => $value) {
       $this->$key = $value;
     }
+    $this->entityTypeId = 'search_page';
   }
   public function label($langcode = NULL) {
     return $this->label;
