diff --git a/core/lib/Drupal/Core/Config/Entity/DraggableListController.php b/core/lib/Drupal/Core/Config/Entity/DraggableListController.php index 6f1a0af..5370be5 100644 --- a/core/lib/Drupal/Core/Config/Entity/DraggableListController.php +++ b/core/lib/Drupal/Core/Config/Entity/DraggableListController.php @@ -25,6 +25,13 @@ protected $entitiesKey = 'entities'; /** + * The entities being listed. + * + * @var \Drupal\Core\Entity\EntityInterface[] + */ + protected $entities = array(); + + /** * Name of the entity's weight field or FALSE if no field is provided. * * @var string|bool @@ -98,7 +105,8 @@ public function buildForm(array $form, array &$form_state) { ), ); - foreach ($this->load() as $entity) { + $this->entities = $this->load(); + foreach ($this->entities as $entity) { $row = $this->buildRow($entity); if (isset($row['label'])) { $row['label'] = array('#markup' => $row['label']); @@ -127,13 +135,11 @@ public function validateForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $values = $form_state['values'][$this->entitiesKey]; - $entities = $this->storage->loadMultiple(array_keys($values)); - foreach ($values as $id => $value) { - if (isset($entities[$id]) && $entities[$id]->get($this->weightKey) != $value['weight']) { + foreach ($form_state['values'][$this->entitiesKey] as $id => $value) { + if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value['weight']) { // Save entity only when its weight was changed. - $entities[$id]->set($this->weightKey, $value['weight']); - $entities[$id]->save(); + $this->entities[$id]->set($this->weightKey, $value['weight']); + $this->entities[$id]->save(); } } } diff --git a/core/modules/language/lib/Drupal/language/LanguageListController.php b/core/modules/language/lib/Drupal/language/LanguageListController.php index 17e6b17..d33b9f4 100644 --- a/core/modules/language/lib/Drupal/language/LanguageListController.php +++ b/core/modules/language/lib/Drupal/language/LanguageListController.php @@ -81,6 +81,7 @@ public function buildRow(EntityInterface $entity) { */ public function buildForm(array $form, array &$form_state) { $form = parent::buildForm($form, $form_state); + $form[$this->entitiesKey]['#languages'] = $this->entities; $form['actions']['submit']['#value'] = t('Save configuration'); return $form; }