Commit 5bf89a45 authored by alexpott's avatar alexpott

Issue #2008356 by dawehner, tim.plunkett: Provide a _entity_list() route...

Issue #2008356 by dawehner, tim.plunkett: Provide a _entity_list() route default to replace Controller\EntityListController and mimic _entity_form().
parent ecd19d9a
......@@ -293,8 +293,8 @@ services:
tags:
- { name: route_enhancer, priority: 20 }
- { name: legacy_route_enhancer, priority: 20 }
route_enhancer.entity_form:
class: Drupal\Core\Entity\Enhancer\EntityFormEnhancer
route_enhancer.entity:
class: Drupal\Core\Entity\Enhancer\EntityRouteEnhancer
arguments: ['@content_negotiation']
tags:
- { name: route_enhancer, priority: 15 }
......
......@@ -45,6 +45,9 @@ public static function create(ContainerInterface $container) {
/**
* Provides the listing page for any entity type.
*
* @param string $entity_type
* The entity type to render.
*
* @return array
* A render array as expected by drupal_render().
*/
......@@ -53,3 +56,4 @@ public function listing($entity_type) {
}
}
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\Entity\Enhancer\EntityFormEnhancer.
* Contains \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer.
*/
namespace Drupal\Core\Entity\Enhancer;
......@@ -14,17 +14,17 @@
/**
* Enhances an entity form route with the appropriate controller.
*/
class EntityFormEnhancer implements RouteEnhancerInterface {
class EntityRouteEnhancer implements RouteEnhancerInterface {
/**
* Content negotiation library.
*
* @var \Drupal\CoreContentNegotiation
* @var \Drupal\Core\ContentNegotiation
*/
protected $negotiation;
/**
* Constructs a new \Drupal\Core\Entity\Enhancer\EntityFormEnhancer.
* Constructs a new \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer.
*
* @param \Drupal\Core\ContentNegotiation $negotiation
* The content negotiation library.
......@@ -37,8 +37,16 @@ public function __construct(ContentNegotiation $negotiation) {
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
if (empty($defaults['_controller']) && !empty($defaults['_entity_form']) && $this->negotiation->getContentType($request) === 'html') {
$defaults['_controller'] = '\Drupal\Core\Entity\HtmlEntityFormController::content';
if (empty($defaults['_controller']) && $this->negotiation->getContentType($request) === 'html') {
if (!empty($defaults['_entity_form'])) {
$defaults['_controller'] = '\Drupal\Core\Entity\HtmlEntityFormController::content';
}
elseif (!empty($defaults['_entity_list'])) {
$defaults['_controller'] = 'controller.page:content';
$defaults['_content'] = '\Drupal\Core\Entity\Controller\EntityListController::listing';
$defaults['entity_type'] = $defaults['_entity_list'];
unset($defaults['_entity_list']);
}
}
return $defaults;
}
......
action_admin:
pattern: '/admin/config/system/actions'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'action'
_entity_list: 'action'
requirements:
_permission: 'administer actions'
......
custom_block_type_list:
pattern: '/admin/structure/custom-blocks'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'custom_block_type'
_entity_list: 'custom_block_type'
requirements:
_permission: 'administer blocks'
......
config_test_list_page:
pattern: '/admin/structure/config_test'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'config_test'
_entity_list: 'config_test'
requirements:
_access: 'TRUE'
......
......@@ -8,8 +8,7 @@ contact_category_delete:
contact_category_list:
pattern: '/admin/structure/contact'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'contact_category'
_entity_list: 'contact_category'
requirements:
_permission: 'administer contact forms'
......
picture_mapping_page:
pattern: '/admin/config/media/picturemapping'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'picture_mapping'
_entity_list: 'picture_mapping'
requirements:
_permission: 'administer pictures'
......
taxonomy_vocabulary_list:
pattern: '/admin/structure/taxonomy'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'taxonomy_vocabulary'
_entity_list: 'taxonomy_vocabulary'
requirements:
_permission: 'administer taxonomy'
......@@ -43,8 +43,7 @@ user_admin_create:
user_role_list:
pattern: '/admin/people/roles'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'user_role'
_entity_list: 'user_role'
requirements:
_permission: 'administer permissions'
......
......@@ -75,16 +75,6 @@ public static function create(ContainerInterface $container) {
);
}
/**
* Lists all of the views.
*
* @return array
* The Views listing page.
*/
public function listing() {
return $this->entityManager->getListController('view')->render();
}
/**
* Lists all instances of fields on any views.
*
......
views_ui.list:
pattern: '/admin/structure/views'
defaults:
_controller: '\Drupal\views_ui\Controller\ViewsUIController::listing'
_entity_list: 'view'
requirements:
_permission: 'administer views'
......
<?php
/**
* @file
* Contains \Drupal\Tests\Core\Entity\Enhancer\EntityRouteEnhancerTest.
*/
namespace Drupal\Tests\Core\Entity\Enhancer;
use Drupal\Core\ContentNegotiation;
use Drupal\Core\Entity\Enhancer\EntityRouteEnhancer;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
/**
* Tests the entity route enhancer.
*
* @see \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer
*/
class EntityRouteEnhancerTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => 'Entity route enhancer test',
'description' => 'Tests the entity route enhancer.',
'group' => 'Entity'
);
}
/**
* Tests the enhancer method.
*
* @see \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer::enhancer()
*/
public function testEnhancer() {
$negotation = $this->getMock('Drupal\core\ContentNegotiation', array('getContentType'));
$negotation->expects($this->any())
->method('getContentType')
->will($this->returnValue('html'));
$route_enhancer = new EntityRouteEnhancer($negotation);
// Set a controller to ensure it is not overridden.
$request = new Request();
$defaults = array();
$defaults['_controller'] = 'Drupal\Tests\Core\Controller\TestController::content';
$defaults['_entity_form'] = 'entity_test.default';
$new_defaults = $route_enhancer->enhance($defaults, $request);
$this->assertEquals($defaults, $new_defaults, '_controller got overridden.');
// Set _entity_form and ensure that the form controller is set.
$defaults = array();
$defaults['_entity_form'] = 'entity_test.default';
$defaults = $route_enhancer->enhance($defaults, $request);
$this->assertEquals('\Drupal\Core\Entity\HtmlEntityFormController::content', $defaults['_controller'], 'The entity form controller was not set.');
// Set _entity_list and ensure that the entity list controller is set.
$defaults = array();
$defaults['_entity_list'] = 'entity_test.default';
$defaults = $route_enhancer->enhance($defaults, $request);
$this->assertEquals('controller.page:content', $defaults['_controller']);
$this->assertEquals('\Drupal\Core\Entity\Controller\EntityListController::listing', $defaults['_content'], 'The entity list controller was not set.');
$this->assertEquals('entity_test.default', $defaults['entity_type']);
$this->assertFalse(isset($defaults['_entity_list']));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment