commit f6ab8dfe614759021a326593e68afb0e6e602650 (HEAD, 1588422-contact) Author: Tim Plunkett Date: Mon Oct 8 17:17:48 2012 -0400 Add CategoryListController instead of custom code. diff --git a/core/modules/contact/contact.admin.inc b/core/modules/contact/contact.admin.inc index 24c1d10..802d3ae 100644 --- a/core/modules/contact/contact.admin.inc +++ b/core/modules/contact/contact.admin.inc @@ -13,42 +13,7 @@ * @see contact_menu() */ function contact_category_list() { - $header = array( - t('Category'), - t('Recipients'), - t('Selected'), - array('data' => t('Operations'), 'colspan' => 2), - ); - $rows = array(); - - $categories = entity_load_multiple('contact_category'); - uasort($categories, 'Drupal\Core\Config\Entity\ConfigEntityBase::sort'); - $default_category = config('contact.settings')->get('default_category'); - - // Loop through the categories and add them to the table. - foreach ($categories as $category) { - $rows[] = array( - check_plain($category->label()), - check_plain(implode(', ', $category->recipients)), - ($default_category == $category->id() ? t('Yes') : t('No')), - l(t('Edit'), 'admin/structure/contact/manage/' . $category->id()), - l(t('Delete'), 'admin/structure/contact/delete/' . $category->id()), - ); - } - - if (!$rows) { - $rows[] = array(array( - 'data' => t('No categories available.'), - 'colspan' => 5, - )); - } - - $build['category_table'] = array( - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - ); - return $build; + return entity_list_controller('contact_category')->render(); } /** diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index e61bb56..8d73765 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -72,13 +72,13 @@ function contact_menu() { 'weight' => 1, 'file' => 'contact.admin.inc', ); - $items['admin/structure/contact/manage/%contact_category'] = array( + $items['admin/structure/contact/manage/%contact_category/edit'] = array( 'title' => 'Edit contact category', 'page callback' => 'entity_get_form', 'page arguments' => array(4), 'access arguments' => array('administer contact forms'), ); - $items['admin/structure/contact/delete/%contact_category'] = array( + $items['admin/structure/contact/manage/%contact_category/delete'] = array( 'title' => 'Delete contact category', 'page callback' => 'drupal_get_form', 'page arguments' => array('contact_category_delete_form', 4), @@ -204,9 +204,11 @@ function contact_entity_info() { 'label' => 'Category', 'entity class' => 'Drupal\contact\Category', 'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController', + 'list controller class' => 'Drupal\contact\CategoryListController', 'form controller class' => array( 'default' => 'Drupal\contact\CategoryFormController', ), + 'uri callback' => 'contact_category_uri', 'config prefix' => 'contact.category', 'entity keys' => array( 'id' => 'id', @@ -231,6 +233,21 @@ function contact_category_load($id) { } /** + * Entity URI callback. + * + * @param Drupal\category\Category $category + * A contact category entity. + * + * @return array + * An array with 'path' as the key and the path to the category as the value. + */ +function contact_category_uri(Category $category) { + return array( + 'path' => 'admin/structure/contact/manage/' . $category->id(), + ); +} + +/** * Implements hook_mail(). */ function contact_mail($key, &$message, $params) { diff --git a/core/modules/contact/lib/Drupal/contact/CategoryListController.php b/core/modules/contact/lib/Drupal/contact/CategoryListController.php new file mode 100644 index 0000000..a50db63 --- /dev/null +++ b/core/modules/contact/lib/Drupal/contact/CategoryListController.php @@ -0,0 +1,40 @@ +label()); + $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['operations']['data'] = $this->buildOperations($entity); + return $row; + } + +}