Skip to content
Snippets Groups Projects
Commit ce7e21fc authored by catch's avatar catch
Browse files

Issue #2688668 by Berdir, bojanz: Register the new entity revision param...

Issue #2688668 by Berdir, bojanz: Register the new entity revision param enhancer/converter as services

(cherry picked from commit fff38959)
parent cbf6494c
No related branches found
No related tags found
No related merge requests found
......@@ -909,6 +909,11 @@ services:
tags:
- { name: paramconverter }
arguments: ['@entity.manager']
paramconverter.entity_revision:
class: Drupal\Core\ParamConverter\EntityRevisionParamConverter
tags:
- { name: paramconverter }
arguments: ['@entity_type.manager']
paramconverter.configentity_admin:
class: Drupal\Core\ParamConverter\AdminPathConfigEntityConverter
tags:
......@@ -963,6 +968,10 @@ services:
class: Drupal\Core\Entity\Enhancer\EntityRouteEnhancer
tags:
- { name: route_enhancer, priority: 20 }
route_enhancer.entity_revision:
class: Drupal\Core\Routing\Enhancer\EntityRevisionRouteEnhancer
tags:
- { name: route_enhancer }
route_special_attributes_subscriber:
class: Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber
tags:
......
......@@ -104,8 +104,25 @@ public function view(EntityInterface $_entity, $view_mode = 'full') {
$page['#entity_type'] = $_entity->getEntityTypeId();
$page['#' . $page['#entity_type']] = $_entity;
return $page;
}
/**
* Provides a page to render a single entity revision.
*
* @param \Drupal\Core\Entity\EntityInterface $_entity_revision
* The Entity to be rendered. Note this variable is named $_entity_revision
* rather than $entity to prevent collisions with other named placeholders
* in the route.
* @param string $view_mode
* (optional) The view mode that should be used to display the entity.
* Defaults to 'full'.
*
* @return array
* A render array.
*/
public function viewRevision(EntityInterface $_entity_revision, $view_mode = 'full') {
return $this->view($_entity_revision, $view_mode);
}
}
......@@ -68,6 +68,17 @@ function testEntityViewController() {
$this->assertRaw('full');
}
// Test viewing a revisionable entity.
$entity_test_rev = $this->createTestEntity('entity_test_rev');
$entity_test_rev->save();
$entity_test_rev->name->value = 'rev 2';
$entity_test_rev->setNewRevision(TRUE);
$entity_test_rev->isDefaultRevision(TRUE);
$entity_test_rev->save();
$this->drupalGet('entity_test_rev/' . $entity_test_rev->id() . '/revision/' . $entity_test_rev->revision_id->value . '/view');
$this->assertRaw($entity_test_rev->label());
$this->assertRaw($get_label_markup($entity_test_rev->label()));
// As entity_test IDs must be integers, make sure requests for non-integer
// IDs return a page not found error.
$this->drupalGet('entity_test/invalid');
......
......@@ -58,7 +58,13 @@ entity.entity_test.collection:
entity.entity_test_rev.revision:
path: '/entity_test_rev/{entity_test_rev}/revision/{entity_test_rev_revision}/view'
defaults:
_entity_view: 'entity_test_rev'
_controller: '\Drupal\Core\Entity\Controller\EntityViewController::viewRevision'
options:
parameters:
entity_test_rev:
type: entity:entity_test_rev
entity_test_rev_revision:
type: entity_revision:entity_test_rev
requirements:
_access: 'TRUE'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment