diff --git a/core/core.services.yml b/core/core.services.yml index 4fab422..71ebf4f 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -82,6 +82,11 @@ services: factory_method: get factory_service: config.context.factory arguments: [Drupal\Core\Config\Context\FreeConfigContext] + config.entity.routing: + class: Drupal\Core\Config\EventSubscriber\RouteSubscriber + arguments: ['@entity.manager'] + tags: + - { name: event_subscriber } config.factory: class: Drupal\Core\Config\ConfigFactory tags: diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityEnableDisableController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityEnableDisableController.php new file mode 100644 index 0000000..4a6c7ac --- /dev/null +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityEnableDisableController.php @@ -0,0 +1,56 @@ +enable()->save(); + $info = $config_entity->entityInfo(); + if (!empty($info['admin_path'])) { + return new RedirectResponse($info['admin_path'], array('absolute' => TRUE)); + } + throw new \Exception("Entity types using ConfigEntityEnableDisableController as their enable/disable controller must define the 'admin_path' property."); + } + + /** + * Disables a ConfigEntity object. + * + * @param Drupal\Core\Config\Entity\ConfigEntityInterface $config_entity + * The ConfigEntity object to disable. + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + * A redirect response to the admin listing page. + */ + function disable(ConfigTest $config_entity) { + $config_entity->disable()->save(); + $info = $config_entity->entityInfo(); + if (!empty($info['admin_path'])) { + return new RedirectResponse($info['admin_path'], array('absolute' => TRUE)); + } + throw new \Exception("Entity types using ConfigEntityEnableDisableController as their enable/disable controller must define the 'admin_path' property."); + } + +} diff --git a/core/lib/Drupal/Core/Config/EventSubscriber/RouteSubscriber.php b/core/lib/Drupal/Core/Config/EventSubscriber/RouteSubscriber.php new file mode 100644 index 0000000..e08bf13 --- /dev/null +++ b/core/lib/Drupal/Core/Config/EventSubscriber/RouteSubscriber.php @@ -0,0 +1,127 @@ +manager = $manager; + } + + /** + * Implements EventSubscriberInterface::getSubscribedEvents(). + */ + public static function getSubscribedEvents() { + $events[RoutingEvents::DYNAMIC] = 'createConfigBaseRoutes'; + return $events; + } + + /** + * Adds dynamic system theme routes. + * + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route building event. + */ + public function createConfigBaseRoutes(RouteBuildEvent $event) { + $collection = $event->getRouteCollection(); + foreach ($this->manager->getDefinitions() as $entity_type => $entity_info) { + $defaults = array(); + if (isset($entity_info['admin_path']) && isset($entity_info['admin_permission'])) { + $permission = $entity_info['admin_permission']; + $path = '/' . $entity_info['admin_path']; + $module = $entity_info['module']; + + // Entity list page. + $route = new Route( + "$path", + array( + '_entity_list' => $entity_type, + '_title' => $entity_info['label'] + ), + array('_permission' => $permission) + ); + $collection->add("$module.{$entity_type}_list", $route); + + // Add form. + $route = new Route( + "$path/add", + array('_entity_form' => $entity_type . '.add'), + array('_permission' => $permission) + ); + $collection->add("$module.{$entity_type}_add", $route); + + // Edit form. + $route = new Route( + "$path/manage/{" . $entity_type . "}", + array('_entity_form' => $entity_type . '.edit'), + array('_entity_access' => $entity_type . '.update') + ); + $collection->add("$module.{$entity_type}_edit", $route); + + $route = new Route( + "$path/manage/{" . $entity_type . "}/edit", + array('_entity_form' => $entity_type . '.edit'), + array('_entity_access' => $entity_type . '.update') + ); + $collection->add("$module.{$entity_type}_edit_tab", $route); + + if (!empty($entity_info['entity_keys']['status'])) { + // Enable callback. + $route = new Route( + "$path/manage/{" . $entity_type . "}/enable", + array('_content' => '\Drupal\Core\Config\Entity\ConfigEntityEnableDisableController::enable'), + array('_permission' => $permission) + ); + $collection->add("$module.{$entity_type}_enable", $route); + + // Disable callback. + $route = new Route( + "$path/manage/{" . $entity_type . "}/disable", + array('_content' => '\Drupal\Core\Config\Entity\ConfigEntityEnableDisableController::disable'), + array('_permission' => $permission) + ); + $collection->add("$module.{$entity_type}_disable", $route); + } + + // Delete callback. + $route = new Route( + "$path/manage/{" . $entity_type . "}/delete", + array('_entity_form' => "$entity_type.delete"), + array('_entity_access' => $entity_type . '.delete') + ); + $collection->add("$module.{$entity_type}_delete", $route); + } + } + } + +} diff --git a/core/modules/config/config.module b/core/modules/config/config.module index 450f210..3d8699d 100644 --- a/core/modules/config/config.module +++ b/core/modules/config/config.module @@ -5,6 +5,8 @@ * Allows site administrators to modify configuration. */ +use Drupal\Core\Config\Entity\ConfigEntityInterface; + /** * Implements hook_help(). */ diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 18180f8..8f8679e 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -61,17 +61,17 @@ function contact_menu() { $items['admin/structure/contact'] = array( 'title' => 'Contact form categories', 'description' => 'Create a system contact form and set up categories for the form to use.', - 'route_name' => 'contact.category_list', + 'route_name' => 'contact.contact_category_list', ); $items['admin/structure/contact/add'] = array( 'title' => 'Add category', - 'route_name' => 'contact.category_add', + 'route_name' => 'contact.contact_category_add', 'type' => MENU_LOCAL_ACTION, 'weight' => 1, ); $items['admin/structure/contact/manage/%contact_category'] = array( 'title' => 'Edit contact category', - 'route_name' => 'contact.category_edit', + 'route_name' => 'contact.contact_category_edit', ); $items['admin/structure/contact/manage/%contact_category/edit'] = array( 'title' => 'Edit', @@ -79,7 +79,7 @@ function contact_menu() { ); $items['admin/structure/contact/manage/%contact_category/delete'] = array( 'title' => 'Delete', - 'route_name' => 'contact.category_delete', + 'route_name' => 'contact.contact_category_delete', 'type' => MENU_LOCAL_TASK, 'weight' => 10, ); diff --git a/core/modules/contact/contact.routing.yml b/core/modules/contact/contact.routing.yml deleted file mode 100644 index 8c85b36..0000000 --- a/core/modules/contact/contact.routing.yml +++ /dev/null @@ -1,27 +0,0 @@ -contact.category_delete: - path: 'admin/structure/contact/manage/{contact_category}/delete' - defaults: - _entity_form: contact_category.delete - requirements: - _entity_access: contact_category.delete - -contact.category_list: - path: '/admin/structure/contact' - defaults: - _entity_list: 'contact_category' - requirements: - _permission: 'administer contact forms' - -contact.category_add: - path: '/admin/structure/contact/add' - defaults: - _entity_form: contact_category.add - requirements: - _permission: 'administer contact forms' - -contact.category_edit: - path: '/admin/structure/contact/manage/{contact_category}' - defaults: - _entity_form: contact_category.edit - requirements: - _entity_access: contact_category.update diff --git a/core/modules/contact/lib/Drupal/contact/Entity/Category.php b/core/modules/contact/lib/Drupal/contact/Entity/Category.php index 7f633fc..3bf114c 100644 --- a/core/modules/contact/lib/Drupal/contact/Entity/Category.php +++ b/core/modules/contact/lib/Drupal/contact/Entity/Category.php @@ -31,6 +31,8 @@ * } * }, * uri_callback = "contact_category_uri", + * admin_path = "admin/structure/contact", + * admin_permission = "administer contact forms", * config_prefix = "contact.category", * bundle_of = "contact_message", * entity_keys = { diff --git a/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php b/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php index 9b74947..172b591 100644 --- a/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php +++ b/core/modules/contact/lib/Drupal/contact/Form/CategoryDeleteForm.php @@ -26,7 +26,7 @@ public function getQuestion() { */ public function getCancelRoute() { return array( - 'route_name' => 'contact.category_list', + 'route_name' => 'contact.contact_category_list', ); }