reverted: --- b/core/modules/contact/lib/Drupal/contact/CategoryListController.php +++ a/core/modules/contact/lib/Drupal/contact/CategoryListController.php @@ -1,81 +1,21 @@ configFactory = $config_factory; - $this->defaultCategory = $config_factory->get('contact.settings')->get('default_category'); - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) { - return new static( - $entity_type, - $entity_info, - $container->get('plugin.manager.entity')->getStorageController($entity_type), - $container->get('module_handler'), - $container->get('config.factory') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormID() { - return 'contact_category_list_form'; - } - - /** - * {@inheritdoc} */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); @@ -104,134 +44,33 @@ } /** + * Overrides Drupal\Core\Entity\EntityListController::buildHeader(). - * {@inheritdoc} */ public function buildHeader() { $row['category'] = t('Category'); $row['recipients'] = t('Recipients'); + $row['selected'] = t('Selected'); - $row['default'] = t('Default'); $row['operations'] = t('Operations'); return $row; } /** + * Overrides Drupal\Core\Entity\EntityListController::buildRow(). - * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { + $row['category'] = check_plain($entity->label()); - $row['category'] = String::checkPlain($entity->label()); // Special case the personal category. if ($entity->id() == 'personal') { $row['recipients'] = t('Selected user'); + $row['selected'] = t('No'); - $row['default'] = t('No'); } else { $row['recipients'] = check_plain(implode(', ', $entity->recipients)); + $default_category = config('contact.settings')->get('default_category'); + $row['selected'] = ($default_category == $entity->id() ? t('Yes') : t('No')); - $row['default'] = ($this->defaultCategory == $entity->id() ? t('Yes') : t('No')); } $row['operations']['data'] = $this->buildOperations($entity); return $row; } - /** - * {@inheritdoc} - */ - public function render() { - $entities = $this->load(); - if (count($entities) > 1) { - // Creates a form for manipulating contact category form weights. - return drupal_get_form($this); - } - - return parent::render(); - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state) { - $form['entities'] = array( - '#type' => 'table', - '#header' => $this->buildHeader() + array('weight' => t('Weight')), - '#empty' => t('There is no @label yet.', array('@label' => $this->entityInfo['label'])), - '#tabledrag' => array( - array('order', 'sibling', 'weight'), - ), - ); - foreach ($this->load() as $entity) { - $row = $this->buildRow($entity); - // Override default values to markup elements. - $row['category'] = array( - '#markup' => $row['category'], - ); - $row['recipients'] = array( - '#markup' => $row['recipients'], - ); - // Allow to change default contact category. - $row['default'] = array( - '#type' => 'radio', - '#title' => t('Set @title as default', array('@title' => $entity->label())), - '#title_display' => 'invisible', - '#return_value' => $entity->id(), - '#default_value' => ($this->defaultCategory == $entity->id() ? $entity->id() : NULL), - '#parents' => array('default_category'), - '#id' => 'edit-entities-default', - // Personal category could not be set default. - '#access' => $entity->id() != 'personal', - ); - // Add weight column and ordering. - $row['#weight'] = $entity->get('weight'); - $row['#attributes']['class'][] = 'draggable'; - $row['weight'] = array( - '#type' => 'weight', - '#title' => t('Weight for @title', array('@title' => $entity->label())), - '#title_display' => 'invisible', - '#default_value' => $entity->get('weight'), - '#attributes' => array('class' => array('weight')), - ); - - $form['entities'][$entity->id()] = $row; - } - - $form['actions']['#type'] = 'actions'; - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Save changes'), - '#button_type' => 'primary', - ); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, array &$form_state) { - // No validation. - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, array &$form_state) { - $values = $form_state['values']['entities']; - - $entities = $this->storage->loadMultiple(array_keys($values)); - foreach ($values as $id => $value) { - if (isset($entities[$id]) && $value['weight'] != $entities[$id]->get('weight')) { - // Update changed weight. - $entities[$id]->set('weight', $value['weight']); - $entities[$id]->save(); - } - } - // Update the site's default contact category. - $default_category = $form_state['values']['default_category']; - if (isset($entities[$default_category]) && $default_category != $this->defaultCategory) { - $this->configFactory->get('contact.settings') - ->set('default_category', $default_category) - ->save(); - } - - drupal_set_message(t('Changes have been saved.')); - } - } reverted: --- b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php +++ a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php @@ -222,7 +222,15 @@ $this->drupalGet('admin/structure/contact'); // Find out in which row the category we want to add a field to is. + $i = 0; + foreach($this->xpath('//table/tbody/tr') as $row) { + if (((string)$row->td[0]) == $label) { + break; + } + $i++; + } + + $this->clickLink(t('Manage fields'), $i); - $this->drupalGet('admin/structure/contact/manage/' . $category . '/fields'); $this->assertResponse(200); // Create a simple textfield. only in patch2: unchanged: --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -238,15 +238,7 @@ function testSiteWideContact() { $this->drupalGet('admin/structure/contact'); // Find out in which row the category we want to add a field to is. - $i = 0; - foreach($this->xpath('//table/tbody/tr') as $row) { - if (((string)$row->td[0]) == $label) { - break; - } - $i++; - } - - $this->clickLink(t('Manage fields'), $i); + $this->drupalGet('admin/structure/contact/manage/' . $category . '/fields'); $this->assertResponse(200); // Create a simple textfield.