diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index e8f7f1b..e0906bf 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -10,11 +10,12 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListController; use Drupal\Core\Entity\EntityStorageControllerInterface; +use Drupal\Core\Form\FormInterface; /** * Defines the default list controller for ConfigEntity objects. */ -class ConfigEntityListController extends EntityListController { +class ConfigEntityListController extends EntityListController implements FormInterface { /** * Name of the entity's weight field or FALSE if no field is provided. @@ -136,25 +137,22 @@ public function render() { return parent::render(); } - $form_state = array(); - $form_state['build_info']['args'] = array(); - $form_state['build_info']['callback'] = array($this, 'form'); + return drupal_get_form($this); + } - return drupal_build_form($this->entityType . '_list_form', $form_state); + /** + * Implements FormInterface::getFormID(). + */ + public function getFormID() { + return $this->entityType . '_admin_list_form'; } /** - * Creates a tabledrag form for manipulating config entity weights. + * Implements \Drupal\Core\Form\FormInterface::buildForm(). * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * A reference to a keyed array containing the current state of the form. - * - * @return array - * The array containing the complete form. + * Form constructor for the main block administration form. */ - public function form($form, &$form_state) { + public function buildForm(array $form, array &$form_state) { $form['entities'] = array( '#type' => 'table', '#header' => $this->buildHeader(), @@ -175,7 +173,7 @@ public function form($form, &$form_state) { $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Save'), + '#value' => t('Save order'), '#submit' => array(array($this, 'submit')), '#button_type' => 'primary', ); @@ -184,19 +182,22 @@ public function form($form, &$form_state) { } /** - * Submit handler for the overview form. - * - * @param array $form - * An associative array containing the structure of the form. - * @param array $form_state - * A reference to a keyed array containing the current state of the form. + * Implements FormInterface::validateForm(). + */ + public function validateForm(array &$form, array &$form_state) { + // No validation. + } + + /** + * Implements FormInterface::submitForm(). */ - public function submit($form, &$form_state) { + public function submitForm(array &$form, array &$form_state) { $values = $form_state['values']['entities']; $entities = entity_load_multiple($this->entityType, array_keys($values)); foreach ($values as $id => $value) { - if (isset($entities[$id])) { + if (isset($entities[$id]) && $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(); }