diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Access/TaxonomyTermCreateAccess.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Access/TaxonomyTermCreateAccess.php new file mode 100644 index 0000000..a0daf3f --- /dev/null +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Access/TaxonomyTermCreateAccess.php @@ -0,0 +1,35 @@ +getRequirements()); + } + + /** + * {@inheritdoc} + */ + public function access(Route $route, Request $request) { + if ($vocabulary = $request->attributes->get('taxonomy_vocabulary')) { + return entity_page_create_access('taxonomy_term', $vocabulary->id()); + } + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php index a82f93d..74c3d12 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php @@ -10,6 +10,7 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\taxonomy\TermStorageControllerInterface; use Drupal\taxonomy\VocabularyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -19,25 +20,51 @@ class TaxonomyController implements ControllerInterface { /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + + /** + * The entity manager. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** + * The taxonomy term storage. + * + * @var \Drupal\taxonomy\TermStorageControllerInterface + */ + protected $termStorage; + + /** * Constructs a new TaxonomyController. * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The entity manager. + * @param \Drupal\taxonomy\TermStorageControllerInterface $term_storage + * The taxonomy term storage. */ - public function __construct(ModuleHandlerInterface $module_handler, EntityManager $entity_manager) { + public function __construct(ModuleHandlerInterface $module_handler, EntityManager $entity_manager, TermStorageControllerInterface $term_storage) { $this->moduleHandler = $module_handler; $this->entityManager = $entity_manager; + $this->termStorage = $term_storage; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { + $entity_manager = $container->get('plugin.manager.entity'); return new static( $container->get('module_handler'), - $container->get('plugin.manager.entity') + $entity_manager, + $entity_manager->getStorageController('taxonomy_term') ); } @@ -46,9 +73,12 @@ public static function create(ContainerInterface $container) { * * @param \Drupal\taxonomy\VocabularyInterface $taxonomy_vocabulary * The vocabulary this term will be added to. + * + * @return array + * The taxonomy term add form. */ public function addForm(VocabularyInterface $taxonomy_vocabulary) { - $term = $this->entityManager->getStorageController('taxonomy_term')->create(array('vid' => $taxonomy_vocabulary->id())); + $term = $this->termStorage->create(array('vid' => $taxonomy_vocabulary->id())); if ($this->moduleHandler->moduleExists('language')) { $term->langcode = language_get_default_langcode('taxonomy_term', $taxonomy_vocabulary->id()); } diff --git a/core/modules/taxonomy/taxonomy.routing.yml b/core/modules/taxonomy/taxonomy.routing.yml index c85d341..603c0c7 100644 --- a/core/modules/taxonomy/taxonomy.routing.yml +++ b/core/modules/taxonomy/taxonomy.routing.yml @@ -10,4 +10,4 @@ taxonomy_term_add: defaults: _content: '\Drupal\taxonomy\Controller\TaxonomyController::addForm' requirements: - _access: 'TRUE' + _access_taxonomy_term_create: 'TRUE' diff --git a/core/modules/taxonomy/taxonomy.services.yml b/core/modules/taxonomy/taxonomy.services.yml new file mode 100644 index 0000000..cdabe8c --- /dev/null +++ b/core/modules/taxonomy/taxonomy.services.yml @@ -0,0 +1,5 @@ +services: + access_check.taxonomy_term.create: + class: Drupal\taxonomy\Access\TaxonomyTermCreateAccess + tags: + - { name: access_check }