Commit 596837b6 authored by catch's avatar catch
Browse files

Issue #2919891 by Darvanen, tstoeckler: Make Vocabulary use a route provider...

Issue #2919891 by Darvanen, tstoeckler: Make Vocabulary use a route provider instead of hard-coded routes
parent 08d676a2
......@@ -79,7 +79,7 @@ public function testBreadCrumbs() {
];
$this->assertBreadcrumb('admin/structure/taxonomy/manage/tags', $trail);
$trail += [
'admin/structure/taxonomy/manage/tags' => t('Tags'),
'admin/structure/taxonomy/manage/tags' => t('Edit Tags'),
];
$this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/overview', $trail);
$this->assertBreadcrumb('admin/structure/taxonomy/manage/tags/add', $trail);
......
<?php
namespace Drupal\taxonomy\Entity\Routing;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
class VocabularyRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
if ($reset_page_route = $this->getResetPageRoute($entity_type)) {
$collection->add("entity.taxonomy_vocabulary.reset_form", $reset_page_route);
}
if ($overview_page_route = $this->getOverviewPageRoute($entity_type)) {
$collection->add("entity.taxonomy_vocabulary.overview_form", $overview_page_route);
}
return $collection;
}
/**
* {@inheritdoc}
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type) {
if ($route = parent::getCollectionRoute($entity_type)) {
$route->setRequirement('_permission', 'access taxonomy overview+administer taxonomy');
return $route;
}
}
/**
* Gets the reset page route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getResetPageRoute(EntityTypeInterface $entity_type) {
$route = new Route('/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset');
$route->setDefault('_entity_form', 'taxonomy_vocabulary.reset');
$route->setDefault('_title', 'Reset');
$route->setRequirement('_permission', $entity_type->getAdminPermission());
$route->setOption('_admin_route', TRUE);
return $route;
}
/**
* Gets the overview page route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getOverviewPageRoute(EntityTypeInterface $entity_type) {
$route = new Route('/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview');
$route->setDefault('_title_callback', 'Drupal\taxonomy\Controller\TaxonomyController::vocabularyTitle');
$route->setDefault('_form', 'Drupal\taxonomy\Form\OverviewTerms');
$route->setRequirement('_entity_access', 'taxonomy_vocabulary.access taxonomy overview');
$route->setOption('_admin_route', TRUE);
return $route;
}
}
......@@ -12,6 +12,13 @@
* @ConfigEntityType(
* id = "taxonomy_vocabulary",
* label = @Translation("Taxonomy vocabulary"),
* label_singular = @Translation("vocabulary"),
* label_plural = @Translation("vocabularies"),
* label_collection = @Translation("Taxonomy"),
* label_count = @PluralTranslation(
* singular = "@count vocabulary",
* plural = "@count vocabularies"
* ),
* handlers = {
* "storage" = "Drupal\taxonomy\VocabularyStorage",
* "list_builder" = "Drupal\taxonomy\VocabularyListBuilder",
......@@ -19,7 +26,11 @@
* "form" = {
* "default" = "Drupal\taxonomy\VocabularyForm",
* "reset" = "Drupal\taxonomy\Form\VocabularyResetForm",
* "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm"
* "delete" = "Drupal\taxonomy\Form\VocabularyDeleteForm",
* "overview" = "Drupal\taxonomy\Form\OverviewTerms"
* },
* "route_provider" = {
* "html" = "Drupal\taxonomy\Entity\Routing\VocabularyRouteProvider",
* }
* },
* admin_permission = "administer taxonomy",
......@@ -31,7 +42,7 @@
* "weight" = "weight"
* },
* links = {
* "add-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/add",
* "add-form" = "/admin/structure/taxonomy/add",
* "delete-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/delete",
* "reset-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset",
* "overview-form" = "/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview",
......
entity.taxonomy_vocabulary.collection:
path: '/admin/structure/taxonomy'
defaults:
_entity_list: 'taxonomy_vocabulary'
_title: 'Taxonomy'
requirements:
_permission: 'access taxonomy overview+administer taxonomy'
entity.taxonomy_term.add_form:
path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/add'
defaults:
......@@ -36,46 +28,6 @@ entity.taxonomy_term.delete_form:
_entity_access: 'taxonomy_term.delete'
taxonomy_term: \d+
entity.taxonomy_vocabulary.add_form:
path: '/admin/structure/taxonomy/add'
defaults:
_entity_form: 'taxonomy_vocabulary'
_title: 'Add vocabulary'
requirements:
_entity_create_access: 'taxonomy_vocabulary'
entity.taxonomy_vocabulary.edit_form:
path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}'
defaults:
_entity_form: 'taxonomy_vocabulary.default'
_title_callback: '\Drupal\taxonomy\Controller\TaxonomyController::vocabularyTitle'
requirements:
_entity_access: 'taxonomy_vocabulary.update'
entity.taxonomy_vocabulary.delete_form:
path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/delete'
defaults:
_entity_form: 'taxonomy_vocabulary.delete'
_title: 'Delete vocabulary'
requirements:
_entity_access: 'taxonomy_vocabulary.delete'
entity.taxonomy_vocabulary.reset_form:
path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/reset'
defaults:
_entity_form: 'taxonomy_vocabulary.reset'
_title: 'Reset'
requirements:
_permission: 'administer taxonomy'
entity.taxonomy_vocabulary.overview_form:
path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview'
defaults:
_form: 'Drupal\taxonomy\Form\OverviewTerms'
_title_callback: 'Drupal\taxonomy\Controller\TaxonomyController::vocabularyTitle'
requirements:
_entity_access: 'taxonomy_vocabulary.access taxonomy overview'
entity.taxonomy_term.canonical:
path: '/taxonomy/term/{taxonomy_term}'
defaults:
......
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