updated core from 8.4 to 8.5 : bug with login_destination
This commit is contained in:
+2
@@ -1,7 +1,9 @@
|
||||
id: d6_taxonomy_term
|
||||
label: Taxonomy terms
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
source:
|
||||
plugin: d6_taxonomy_term
|
||||
process:
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_taxonomy_vocabulary
|
||||
label: Taxonomy vocabularies
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_taxonomy_vocabulary
|
||||
process:
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_taxonomy_vocabulary_translation
|
||||
label: Taxonomy vocabularies
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_taxonomy_vocabulary_translation
|
||||
process:
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_term_node
|
||||
label: Term/node relationships
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver
|
||||
source:
|
||||
plugin: d6_term_node
|
||||
+2
@@ -1,7 +1,9 @@
|
||||
id: d6_term_node_revision
|
||||
label: Term/node relationship revisions
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Content
|
||||
deriver: Drupal\taxonomy\Plugin\migrate\D6TermNodeDeriver
|
||||
source:
|
||||
plugin: d6_term_node_revision
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_vocabulary_entity_display
|
||||
label: Vocabulary display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_taxonomy_vocabulary_per_type
|
||||
constants:
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_vocabulary_entity_form_display
|
||||
label: Vocabulary form display configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_taxonomy_vocabulary_per_type
|
||||
constants:
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_vocabulary_field
|
||||
label: Vocabulary field configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_taxonomy_vocabulary
|
||||
constants:
|
||||
+1
@@ -2,6 +2,7 @@ id: d6_vocabulary_field_instance
|
||||
label: Vocabulary field instance configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d6_taxonomy_vocabulary_per_type
|
||||
constants:
|
||||
+2
@@ -1,7 +1,9 @@
|
||||
id: d7_taxonomy_term
|
||||
label: Taxonomy terms
|
||||
audit: true
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Content
|
||||
deriver: Drupal\taxonomy\Plugin\migrate\D7TaxonomyTermDeriver
|
||||
source:
|
||||
plugin: d7_taxonomy_term
|
||||
+1
@@ -2,6 +2,7 @@ id: d7_taxonomy_vocabulary
|
||||
label: Taxonomy vocabularies
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: d7_taxonomy_vocabulary
|
||||
process:
|
||||
+1
@@ -3,6 +3,7 @@ label: Taxonomy configuration
|
||||
migration_tags:
|
||||
- Drupal 6
|
||||
- Drupal 7
|
||||
- Configuration
|
||||
source:
|
||||
plugin: variable
|
||||
variables:
|
||||
@@ -0,0 +1,77 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,7 +19,8 @@ use Drupal\taxonomy\TermInterface;
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\taxonomy\TermStorage",
|
||||
* "storage_schema" = "Drupal\taxonomy\TermStorageSchema",
|
||||
* "view_builder" = "Drupal\taxonomy\TermViewBuilder",
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\Core\Entity\EntityListBuilder",
|
||||
* "access" = "Drupal\taxonomy\TermAccessControlHandler",
|
||||
* "views_data" = "Drupal\taxonomy\TermViewsData",
|
||||
* "form" = {
|
||||
|
||||
@@ -12,13 +12,25 @@ use Drupal\taxonomy\VocabularyInterface;
|
||||
* @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",
|
||||
* "access" = "Drupal\taxonomy\VocabularyAccessControlHandler",
|
||||
* "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",
|
||||
@@ -30,7 +42,7 @@ use Drupal\taxonomy\VocabularyInterface;
|
||||
* "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",
|
||||
|
||||
@@ -2,15 +2,20 @@
|
||||
|
||||
namespace Drupal\taxonomy\Form;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\taxonomy\VocabularyInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides terms overview form for a taxonomy vocabulary.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class OverviewTerms extends FormBase {
|
||||
|
||||
@@ -35,6 +40,20 @@ class OverviewTerms extends FormBase {
|
||||
*/
|
||||
protected $storageController;
|
||||
|
||||
/**
|
||||
* The term list builder.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityListBuilderInterface
|
||||
*/
|
||||
protected $termListBuilder;
|
||||
|
||||
/**
|
||||
* The renderer service.
|
||||
*
|
||||
* @var \Drupal\Core\Render\RendererInterface
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* Constructs an OverviewTerms object.
|
||||
*
|
||||
@@ -42,11 +61,15 @@ class OverviewTerms extends FormBase {
|
||||
* The module handler service.
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager service.
|
||||
* @param \Drupal\Core\Render\RendererInterface $renderer
|
||||
* The renderer service.
|
||||
*/
|
||||
public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) {
|
||||
public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager, RendererInterface $renderer = NULL) {
|
||||
$this->moduleHandler = $module_handler;
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->storageController = $entity_manager->getStorage('taxonomy_term');
|
||||
$this->termListBuilder = $entity_manager->getListBuilder('taxonomy_term');
|
||||
$this->renderer = $renderer ?: \Drupal::service('renderer');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +78,8 @@ class OverviewTerms extends FormBase {
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('module_handler'),
|
||||
$container->get('entity.manager')
|
||||
$container->get('entity.manager'),
|
||||
$container->get('renderer')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -204,17 +228,28 @@ class OverviewTerms extends FormBase {
|
||||
}
|
||||
|
||||
$errors = $form_state->getErrors();
|
||||
$destination = $this->getDestinationArray();
|
||||
$row_position = 0;
|
||||
// Build the actual form.
|
||||
$access_control_handler = $this->entityManager->getAccessControlHandler('taxonomy_term');
|
||||
$create_access = $access_control_handler->createAccess($taxonomy_vocabulary->id(), NULL, [], TRUE);
|
||||
if ($create_access->isAllowed()) {
|
||||
$empty = $this->t('No terms available. <a href=":link">Add term</a>.', [':link' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $taxonomy_vocabulary->id()])->toString()]);
|
||||
}
|
||||
else {
|
||||
$empty = $this->t('No terms available.');
|
||||
}
|
||||
$form['terms'] = [
|
||||
'#type' => 'table',
|
||||
'#header' => [$this->t('Name'), $this->t('Weight'), $this->t('Operations')],
|
||||
'#empty' => $this->t('No terms available. <a href=":link">Add term</a>.', [':link' => $this->url('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $taxonomy_vocabulary->id()])]),
|
||||
'#empty' => $empty,
|
||||
'#attributes' => [
|
||||
'id' => 'taxonomy',
|
||||
],
|
||||
];
|
||||
$this->renderer->addCacheableDependency($form['terms'], $create_access);
|
||||
|
||||
// Only allow access to changing weights if the user has update access for
|
||||
// all terms.
|
||||
$change_weight_access = AccessResult::allowed();
|
||||
foreach ($current_page as $key => $term) {
|
||||
/** @var $term \Drupal\Core\Entity\EntityInterface */
|
||||
$term = $this->entityManager->getTranslationFromContext($term);
|
||||
@@ -260,39 +295,26 @@ class OverviewTerms extends FormBase {
|
||||
],
|
||||
];
|
||||
}
|
||||
$form['terms'][$key]['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#delta' => $delta,
|
||||
'#title' => $this->t('Weight for added term'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $term->getWeight(),
|
||||
'#attributes' => [
|
||||
'class' => ['term-weight'],
|
||||
],
|
||||
];
|
||||
$operations = [
|
||||
'edit' => [
|
||||
'title' => $this->t('Edit'),
|
||||
'query' => $destination,
|
||||
'url' => $term->urlInfo('edit-form'),
|
||||
],
|
||||
'delete' => [
|
||||
'title' => $this->t('Delete'),
|
||||
'query' => $destination,
|
||||
'url' => $term->urlInfo('delete-form'),
|
||||
],
|
||||
];
|
||||
if ($this->moduleHandler->moduleExists('content_translation') && content_translation_translate_access($term)->isAllowed()) {
|
||||
$operations['translate'] = [
|
||||
'title' => $this->t('Translate'),
|
||||
'query' => $destination,
|
||||
'url' => $term->urlInfo('drupal:content-translation-overview'),
|
||||
$update_access = $term->access('update', NULL, TRUE);
|
||||
$change_weight_access = $change_weight_access->andIf($update_access);
|
||||
|
||||
if ($update_access->isAllowed()) {
|
||||
$form['terms'][$key]['weight'] = [
|
||||
'#type' => 'weight',
|
||||
'#delta' => $delta,
|
||||
'#title' => $this->t('Weight for added term'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $term->getWeight(),
|
||||
'#attributes' => ['class' => ['term-weight']],
|
||||
];
|
||||
}
|
||||
|
||||
if ($operations = $this->termListBuilder->getOperations($term)) {
|
||||
$form['terms'][$key]['operations'] = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $operations,
|
||||
];
|
||||
}
|
||||
$form['terms'][$key]['operations'] = [
|
||||
'#type' => 'operations',
|
||||
'#links' => $operations,
|
||||
];
|
||||
|
||||
$form['terms'][$key]['#attributes']['class'] = [];
|
||||
if ($parent_fields) {
|
||||
@@ -322,34 +344,42 @@ class OverviewTerms extends FormBase {
|
||||
$row_position++;
|
||||
}
|
||||
|
||||
if ($parent_fields) {
|
||||
$form['terms']['#header'] = [$this->t('Name')];
|
||||
|
||||
$this->renderer->addCacheableDependency($form['terms'], $change_weight_access);
|
||||
if ($change_weight_access->isAllowed()) {
|
||||
$form['terms']['#header'][] = $this->t('Weight');
|
||||
if ($parent_fields) {
|
||||
$form['terms']['#tabledrag'][] = [
|
||||
'action' => 'match',
|
||||
'relationship' => 'parent',
|
||||
'group' => 'term-parent',
|
||||
'subgroup' => 'term-parent',
|
||||
'source' => 'term-id',
|
||||
'hidden' => FALSE,
|
||||
];
|
||||
$form['terms']['#tabledrag'][] = [
|
||||
'action' => 'depth',
|
||||
'relationship' => 'group',
|
||||
'group' => 'term-depth',
|
||||
'hidden' => FALSE,
|
||||
];
|
||||
$form['terms']['#attached']['library'][] = 'taxonomy/drupal.taxonomy';
|
||||
$form['terms']['#attached']['drupalSettings']['taxonomy'] = [
|
||||
'backStep' => $back_step,
|
||||
'forwardStep' => $forward_step,
|
||||
];
|
||||
}
|
||||
$form['terms']['#tabledrag'][] = [
|
||||
'action' => 'match',
|
||||
'relationship' => 'parent',
|
||||
'group' => 'term-parent',
|
||||
'subgroup' => 'term-parent',
|
||||
'source' => 'term-id',
|
||||
'hidden' => FALSE,
|
||||
];
|
||||
$form['terms']['#tabledrag'][] = [
|
||||
'action' => 'depth',
|
||||
'relationship' => 'group',
|
||||
'group' => 'term-depth',
|
||||
'hidden' => FALSE,
|
||||
];
|
||||
$form['terms']['#attached']['library'][] = 'taxonomy/drupal.taxonomy';
|
||||
$form['terms']['#attached']['drupalSettings']['taxonomy'] = [
|
||||
'backStep' => $back_step,
|
||||
'forwardStep' => $forward_step,
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'term-weight',
|
||||
];
|
||||
}
|
||||
$form['terms']['#tabledrag'][] = [
|
||||
'action' => 'order',
|
||||
'relationship' => 'sibling',
|
||||
'group' => 'term-weight',
|
||||
];
|
||||
|
||||
if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) {
|
||||
$form['terms']['#header'][] = $this->t('Operations');
|
||||
|
||||
if (($taxonomy_vocabulary->getHierarchy() !== VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) && $change_weight_access->isAllowed()) {
|
||||
$form['actions'] = ['#type' => 'actions', '#tree' => FALSE];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
|
||||
@@ -8,6 +8,8 @@ use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Provides a deletion confirmation form for taxonomy term.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class TermDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ use Drupal\Core\Entity\EntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a deletion confirmation form for taxonomy vocabulary.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class VocabularyDeleteForm extends EntityDeleteForm {
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides confirmation form for resetting a vocabulary to alphabetical order.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class VocabularyResetForm extends EntityConfirmFormBase {
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ class TermSelection extends DefaultSelection {
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::buildConfigurationForm($form, $form_state);
|
||||
|
||||
$form['target_bundles']['#title'] = $this->t('Available Vocabularies');
|
||||
|
||||
// Sorting is not possible for taxonomy terms because we use
|
||||
// \Drupal\taxonomy\TermStorageInterface::loadTree() to retrieve matches.
|
||||
$form['sort']['#access'] = FALSE;
|
||||
|
||||
@@ -13,7 +13,9 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
* type_map = {
|
||||
* "taxonomy_term_reference" = "entity_reference"
|
||||
* },
|
||||
* core = {6,7}
|
||||
* core = {6,7},
|
||||
* source_module = "taxonomy",
|
||||
* destination_module = "core",
|
||||
* )
|
||||
*
|
||||
* @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x. Use
|
||||
|
||||
@@ -11,11 +11,22 @@ use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
|
||||
* type_map = {
|
||||
* "taxonomy_term_reference" = "entity_reference"
|
||||
* },
|
||||
* core = {6,7}
|
||||
* core = {6,7},
|
||||
* source_module = "taxonomy",
|
||||
* destination_module = "core",
|
||||
* )
|
||||
*/
|
||||
class TaxonomyTermReference extends FieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return [
|
||||
'taxonomy_term_reference_link' => 'entity_reference_label',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Drupal\taxonomy;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
@@ -48,19 +49,30 @@ class TaxonomyPermissions implements ContainerInjectionInterface {
|
||||
*/
|
||||
public function permissions() {
|
||||
$permissions = [];
|
||||
foreach ($this->entityManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) {
|
||||
$permissions += [
|
||||
'edit terms in ' . $vocabulary->id() => [
|
||||
'title' => $this->t('Edit terms in %vocabulary', ['%vocabulary' => $vocabulary->label()]),
|
||||
],
|
||||
];
|
||||
$permissions += [
|
||||
'delete terms in ' . $vocabulary->id() => [
|
||||
'title' => $this->t('Delete terms from %vocabulary', ['%vocabulary' => $vocabulary->label()]),
|
||||
],
|
||||
];
|
||||
foreach (Vocabulary::loadMultiple() as $vocabulary) {
|
||||
$permissions += $this->buildPermissions($vocabulary);
|
||||
}
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a standard list of taxonomy term permissions for a given vocabulary.
|
||||
*
|
||||
* @param \Drupal\taxonomy\VocabularyInterface $vocabulary
|
||||
* The vocabulary.
|
||||
*
|
||||
* @return array
|
||||
* An array of permission names and descriptions.
|
||||
*/
|
||||
protected function buildPermissions(VocabularyInterface $vocabulary) {
|
||||
$id = $vocabulary->id();
|
||||
$args = ['%vocabulary' => $vocabulary->label()];
|
||||
|
||||
return [
|
||||
"create terms in $id" => ['title' => $this->t('%vocabulary: Create terms', $args)],
|
||||
"delete terms in $id" => ['title' => $this->t('%vocabulary: Delete terms', $args)],
|
||||
"edit terms in $id" => ['title' => $this->t('%vocabulary: Edit terms', $args)],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class TermAccessControlHandler extends EntityAccessControlHandler {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'administer taxonomy');
|
||||
return AccessResult::allowedIfHasPermissions($account, ["create terms in $entity_bundle", 'administer taxonomy'], 'OR');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Base for handler for taxonomy term edit forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class TermForm extends ContentEntityForm {
|
||||
|
||||
@@ -36,14 +38,17 @@ class TermForm extends ContentEntityForm {
|
||||
// before loading the full vocabulary. Contrib modules can then intercept
|
||||
// before hook_form_alter to provide scalable alternatives.
|
||||
if (!$this->config('taxonomy.settings')->get('override_selector')) {
|
||||
$parent = array_keys($taxonomy_storage->loadParents($term->id()));
|
||||
$children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id());
|
||||
$exclude = [];
|
||||
if (!$term->isNew()) {
|
||||
$parent = array_keys($taxonomy_storage->loadParents($term->id()));
|
||||
$children = $taxonomy_storage->loadTree($vocabulary->id(), $term->id());
|
||||
|
||||
// A term can't be the child of itself, nor of its children.
|
||||
foreach ($children as $child) {
|
||||
$exclude[] = $child->tid;
|
||||
// A term can't be the child of itself, nor of its children.
|
||||
foreach ($children as $child) {
|
||||
$exclude[] = $child->tid;
|
||||
}
|
||||
$exclude[] = $term->id();
|
||||
}
|
||||
$exclude[] = $term->id();
|
||||
|
||||
$tree = $taxonomy_storage->loadTree($vocabulary->id());
|
||||
$options = ['<' . $this->t('root') . '>'];
|
||||
|
||||
@@ -2,24 +2,17 @@
|
||||
|
||||
namespace Drupal\taxonomy;
|
||||
|
||||
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
@trigger_error(__NAMESPACE__ . '\TermViewBuilder is deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityViewBuilder instead. See https://www.drupal.org/node/2924233.', E_USER_DEPRECATED);
|
||||
|
||||
use Drupal\Core\Entity\EntityViewBuilder;
|
||||
|
||||
/**
|
||||
* View builder handler for taxonomy terms.
|
||||
*
|
||||
* @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0.
|
||||
* Use \Drupal\Core\Entity\EntityViewBuilder instead.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityViewBuilder
|
||||
* @see https://www.drupal.org/node/2924233
|
||||
*/
|
||||
class TermViewBuilder extends EntityViewBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
|
||||
parent::alterBuild($build, $entity, $display, $view_mode);
|
||||
$build['#contextual_links']['taxonomy_term'] = [
|
||||
'route_parameters' => ['taxonomy_term' => $entity->id()],
|
||||
'metadata' => ['changed' => $entity->getChangedTime()],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
class TermViewBuilder extends EntityViewBuilder {}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\taxonomy;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
* Defines the access control handler for the taxonomy vocabulary entity type.
|
||||
*
|
||||
* @see \Drupal\taxonomy\Entity\Vocabulary
|
||||
*/
|
||||
class VocabularyAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
switch ($operation) {
|
||||
case 'access taxonomy overview':
|
||||
case 'view':
|
||||
return AccessResult::allowedIfHasPermissions($account, ['access taxonomy overview', 'administer taxonomy'], 'OR');
|
||||
|
||||
default:
|
||||
return parent::checkAccess($entity, $operation, $account);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Base form for vocabulary edit forms.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class VocabularyForm extends BundleEntityFormBase {
|
||||
|
||||
|
||||
@@ -4,8 +4,13 @@ namespace Drupal\taxonomy;
|
||||
|
||||
use Drupal\Core\Config\Entity\DraggableListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\RendererInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of taxonomy vocabulary entities.
|
||||
@@ -19,6 +24,59 @@ class VocabularyListBuilder extends DraggableListBuilder {
|
||||
*/
|
||||
protected $entitiesKey = 'vocabularies';
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
* @var \Drupal\Core\Session\AccountInterface
|
||||
*/
|
||||
protected $currentUser;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The renderer service.
|
||||
*
|
||||
* @var \Drupal\Core\Render\RendererInterface
|
||||
*/
|
||||
protected $renderer;
|
||||
|
||||
/**
|
||||
* Constructs a new VocabularyListBuilder object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type definition.
|
||||
* @param \Drupal\Core\Session\AccountInterface $current_user
|
||||
* The current user.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity manager service.
|
||||
* @param \Drupal\Core\Render\RendererInterface $renderer
|
||||
* The renderer service.
|
||||
*/
|
||||
public function __construct(EntityTypeInterface $entity_type, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer = NULL) {
|
||||
parent::__construct($entity_type, $entity_type_manager->getStorage($entity_type->id()));
|
||||
|
||||
$this->currentUser = $current_user;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->renderer = $renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
|
||||
return new static(
|
||||
$entity_type,
|
||||
$container->get('current_user'),
|
||||
$container->get('entity_type.manager'),
|
||||
$container->get('renderer')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@@ -36,16 +94,23 @@ class VocabularyListBuilder extends DraggableListBuilder {
|
||||
$operations['edit']['title'] = t('Edit vocabulary');
|
||||
}
|
||||
|
||||
$operations['list'] = [
|
||||
'title' => t('List terms'),
|
||||
'weight' => 0,
|
||||
'url' => $entity->urlInfo('overview-form'),
|
||||
];
|
||||
$operations['add'] = [
|
||||
'title' => t('Add terms'),
|
||||
'weight' => 10,
|
||||
'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]),
|
||||
];
|
||||
if ($entity->access('access taxonomy overview')) {
|
||||
$operations['list'] = [
|
||||
'title' => t('List terms'),
|
||||
'weight' => 0,
|
||||
'url' => $entity->toUrl('overview-form'),
|
||||
];
|
||||
}
|
||||
|
||||
$taxonomy_term_access_control_handler = $this->entityTypeManager->getAccessControlHandler('taxonomy_term');
|
||||
if ($taxonomy_term_access_control_handler->createAccess($entity->id())) {
|
||||
$operations['add'] = [
|
||||
'title' => t('Add terms'),
|
||||
'weight' => 10,
|
||||
'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]),
|
||||
];
|
||||
}
|
||||
|
||||
unset($operations['delete']);
|
||||
|
||||
return $operations;
|
||||
@@ -57,6 +122,11 @@ class VocabularyListBuilder extends DraggableListBuilder {
|
||||
public function buildHeader() {
|
||||
$header['label'] = t('Vocabulary name');
|
||||
$header['description'] = t('Description');
|
||||
|
||||
if ($this->currentUser->hasPermission('administer vocabularies')) {
|
||||
$header['weight'] = t('Weight');
|
||||
}
|
||||
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
@@ -80,7 +150,25 @@ class VocabularyListBuilder extends DraggableListBuilder {
|
||||
unset($this->weightKey);
|
||||
}
|
||||
$build = parent::render();
|
||||
$build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [':link' => \Drupal::url('entity.taxonomy_vocabulary.add_form')]);
|
||||
|
||||
// If the weight key was unset then the table is in the 'table' key,
|
||||
// otherwise in vocabularies. The empty message is only needed if the table
|
||||
// is possibly empty, so there is no need to support the vocabularies key
|
||||
// here.
|
||||
if (isset($build['table'])) {
|
||||
$access_control_handler = $this->entityTypeManager->getAccessControlHandler('taxonomy_vocabulary');
|
||||
$create_access = $access_control_handler->createAccess(NULL, NULL, [], TRUE);
|
||||
$this->renderer->addCacheableDependency($build['table'], $create_access);
|
||||
if ($create_access->isAllowed()) {
|
||||
$build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [
|
||||
':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString()
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$build['table']['#empty'] = t('No vocabularies available.');
|
||||
}
|
||||
}
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ dependencies:
|
||||
- text
|
||||
configure: entity.taxonomy_vocabulary.collection
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -81,13 +81,25 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) {
|
||||
|
||||
case 'entity.taxonomy_vocabulary.overview_form':
|
||||
$vocabulary = $route_match->getParameter('taxonomy_vocabulary');
|
||||
switch ($vocabulary->getHierarchy()) {
|
||||
case VocabularyInterface::HIERARCHY_DISABLED:
|
||||
return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>';
|
||||
case VocabularyInterface::HIERARCHY_SINGLE:
|
||||
return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>';
|
||||
case VocabularyInterface::HIERARCHY_MULTIPLE:
|
||||
return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
|
||||
if (\Drupal::currentUser()->hasPermission('administer taxonomy') || \Drupal::currentUser()->hasPermission('edit terms in ' . $vocabulary->id())) {
|
||||
switch ($vocabulary->getHierarchy()) {
|
||||
case VocabularyInterface::HIERARCHY_DISABLED:
|
||||
return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>';
|
||||
case VocabularyInterface::HIERARCHY_SINGLE:
|
||||
return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>';
|
||||
case VocabularyInterface::HIERARCHY_MULTIPLE:
|
||||
return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch ($vocabulary->getHierarchy()) {
|
||||
case VocabularyInterface::HIERARCHY_DISABLED:
|
||||
return '<p>' . t('%capital_name contains the following terms.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
|
||||
case VocabularyInterface::HIERARCHY_SINGLE:
|
||||
return '<p>' . t('%capital_name contains terms grouped under parent terms', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
|
||||
case VocabularyInterface::HIERARCHY_MULTIPLE:
|
||||
return '<p>' . t('%capital_name contains terms with multiple parents.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
administer taxonomy:
|
||||
title: 'Administer vocabularies and terms'
|
||||
|
||||
access taxonomy overview:
|
||||
title: 'Access the taxonomy vocabulary overview page'
|
||||
description: 'Get an overview of all taxonomy vocabularies.'
|
||||
|
||||
permission_callbacks:
|
||||
- Drupal\taxonomy\TaxonomyPermissions::permissions
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
entity.taxonomy_vocabulary.collection:
|
||||
path: '/admin/structure/taxonomy'
|
||||
defaults:
|
||||
_entity_list: 'taxonomy_vocabulary'
|
||||
_title: 'Taxonomy'
|
||||
requirements:
|
||||
_permission: '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.view'
|
||||
|
||||
entity.taxonomy_term.canonical:
|
||||
path: '/taxonomy/term/{taxonomy_term}'
|
||||
defaults:
|
||||
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- taxonomy
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ dependencies:
|
||||
- taxonomy
|
||||
- migrate
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
@@ -7,8 +7,8 @@ package: Testing
|
||||
dependencies:
|
||||
- taxonomy
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -8,8 +8,8 @@ dependencies:
|
||||
- taxonomy
|
||||
- views
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+3
-3
@@ -6,8 +6,8 @@ package: Testing
|
||||
dependencies:
|
||||
- taxonomy
|
||||
|
||||
# Information added by Drupal.org packaging script on 2018-01-03
|
||||
version: '8.4.4'
|
||||
# Information added by Drupal.org packaging script on 2018-03-07
|
||||
version: '8.5.0'
|
||||
core: '8.x'
|
||||
project: 'drupal'
|
||||
datestamp: 1515021228
|
||||
datestamp: 1520457825
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class LegacyTest extends TaxonomyTestBase {
|
||||
class EarlyDateTest extends TaxonomyTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
@@ -51,7 +51,7 @@ class LegacyTest extends TaxonomyTestBase {
|
||||
/**
|
||||
* Test taxonomy functionality with nodes prior to 1970.
|
||||
*/
|
||||
public function testTaxonomyLegacyNode() {
|
||||
public function testTaxonomyEarlyDateNode() {
|
||||
// Posts an article with a taxonomy term and a date prior to 1970.
|
||||
$date = new DrupalDateTime('1969-01-01 00:00:00');
|
||||
$edit = [];
|
||||
@@ -80,7 +80,7 @@ class TaxonomyImageTest extends TaxonomyTestBase {
|
||||
$files = $this->drupalGetTestFiles('image');
|
||||
$image = array_pop($files);
|
||||
$edit['name[0][value]'] = $this->randomMachineName();
|
||||
$edit['files[field_test_0]'] = drupal_realpath($image->uri);
|
||||
$edit['files[field_test_0]'] = \Drupal::service('file_system')->realpath($image->uri);
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
|
||||
$this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save'));
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $edit['name[0][value]']]);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
/**
|
||||
* Tests views contextual links on terms.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class TermContextualLinksTest extends TaxonomyTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'contextual',
|
||||
];
|
||||
|
||||
/**
|
||||
* Tests contextual links.
|
||||
*/
|
||||
public function testTermContextualLinks() {
|
||||
$vocabulary = $this->createVocabulary();
|
||||
$term = $this->createTerm($vocabulary);
|
||||
|
||||
$user = $this->drupalCreateUser([
|
||||
'administer taxonomy',
|
||||
'access contextual links',
|
||||
]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$this->drupalGet('taxonomy/term/' . $term->id());
|
||||
$this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'taxonomy_term:taxonomy_term=' . $term->id() . ':');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Drupal\Tests\taxonomy\Functional;
|
||||
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
/**
|
||||
* Tests the taxonomy vocabulary permissions.
|
||||
*
|
||||
@@ -9,10 +11,204 @@ namespace Drupal\Tests\taxonomy\Functional;
|
||||
*/
|
||||
class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['help'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
$this->drupalPlaceBlock('help_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, edit and delete a vocabulary via the user interface.
|
||||
*/
|
||||
public function testVocabularyPermissionsVocabulary() {
|
||||
// VocabularyTest.php already tests for user with "administer taxonomy"
|
||||
// permission.
|
||||
|
||||
// Test as user without proper permissions.
|
||||
$authenticated_user = $this->drupalCreateUser([]);
|
||||
$this->drupalLogin($authenticated_user);
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
// Visit the main taxonomy administration page.
|
||||
$this->drupalGet('admin/structure/taxonomy');
|
||||
$assert_session->statusCodeEquals(403);
|
||||
|
||||
// Test as user with "access taxonomy overview" permissions.
|
||||
$proper_user = $this->drupalCreateUser(['access taxonomy overview']);
|
||||
$this->drupalLogin($proper_user);
|
||||
|
||||
// Visit the main taxonomy administration page.
|
||||
$this->drupalGet('admin/structure/taxonomy');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('Vocabulary name');
|
||||
$assert_session->linkNotExists('Add vocabulary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the vocabulary overview permission.
|
||||
*/
|
||||
public function testTaxonomyVocabularyOverviewPermissions() {
|
||||
// Create two vocabularies, one with two terms, the other without any term.
|
||||
/** @var \Drupal\taxonomy\Entity\Vocabulary $vocabulary1 , $vocabulary2 */
|
||||
$vocabulary1 = $this->createVocabulary();
|
||||
$vocabulary2 = $this->createVocabulary();
|
||||
$vocabulary1_id = $vocabulary1->id();
|
||||
$vocabulary2_id = $vocabulary2->id();
|
||||
$this->createTerm($vocabulary1);
|
||||
$this->createTerm($vocabulary1);
|
||||
|
||||
// Assert expected help texts on first vocabulary.
|
||||
$edit_help_text = t('You can reorganize the terms in @capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['@capital_name' => Unicode::ucfirst($vocabulary1->label())]);
|
||||
$no_edit_help_text = t('@capital_name contains the following terms.', ['@capital_name' => Unicode::ucfirst($vocabulary1->label())]);
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
// Logged in as admin user with 'administer taxonomy' permission.
|
||||
$admin_user = $this->drupalCreateUser(['administer taxonomy']);
|
||||
$this->drupalLogin($admin_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->linkExists('Edit');
|
||||
$assert_session->linkExists('Delete');
|
||||
$assert_session->linkExists('Add term');
|
||||
$assert_session->buttonExists('Save');
|
||||
$assert_session->pageTextContains('Weight');
|
||||
$assert_session->pageTextContains($edit_help_text);
|
||||
|
||||
// Visit vocabulary overview without terms. 'Add term' should be shown.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('No terms available');
|
||||
$assert_session->linkExists('Add term');
|
||||
|
||||
// Login as a user without any of the required permissions.
|
||||
$no_permission_user = $this->drupalCreateUser();
|
||||
$this->drupalLogin($no_permission_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(403);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(403);
|
||||
|
||||
// Log in as a user with only the overview permission, neither edit nor
|
||||
// delete operations must be available and no Save button.
|
||||
$overview_only_user = $this->drupalCreateUser(['access taxonomy overview']);
|
||||
$this->drupalLogin($overview_only_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->linkNotExists('Edit');
|
||||
$assert_session->linkNotExists('Delete');
|
||||
$assert_session->buttonNotExists('Save');
|
||||
$assert_session->pageTextNotContains('Weight');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
$assert_session->pageTextContains($no_edit_help_text);
|
||||
|
||||
// Visit vocabulary overview without terms. 'Add term' should not be shown.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('No terms available');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
|
||||
// Login as a user with permission to edit terms, only edit link should be
|
||||
// visible.
|
||||
$edit_user = $this->createUser([
|
||||
'access taxonomy overview',
|
||||
'edit terms in ' . $vocabulary1_id,
|
||||
'edit terms in ' . $vocabulary2_id,
|
||||
]);
|
||||
$this->drupalLogin($edit_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->linkExists('Edit');
|
||||
$assert_session->linkNotExists('Delete');
|
||||
$assert_session->buttonExists('Save');
|
||||
$assert_session->pageTextContains('Weight');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
$assert_session->pageTextContains($edit_help_text);
|
||||
|
||||
// Visit vocabulary overview without terms. 'Add term' should not be shown.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('No terms available');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
|
||||
// Login as a user with permission only to delete terms.
|
||||
$edit_delete_user = $this->createUser([
|
||||
'access taxonomy overview',
|
||||
'delete terms in ' . $vocabulary1_id,
|
||||
'delete terms in ' . $vocabulary2_id,
|
||||
]);
|
||||
$this->drupalLogin($edit_delete_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->linkNotExists('Edit');
|
||||
$assert_session->linkExists('Delete');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
$assert_session->buttonNotExists('Save');
|
||||
$assert_session->pageTextNotContains('Weight');
|
||||
$assert_session->pageTextContains($no_edit_help_text);
|
||||
|
||||
// Visit vocabulary overview without terms. 'Add term' should not be shown.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('No terms available');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
|
||||
// Login as a user with permission to edit and delete terms.
|
||||
$edit_delete_user = $this->createUser([
|
||||
'access taxonomy overview',
|
||||
'edit terms in ' . $vocabulary1_id,
|
||||
'delete terms in ' . $vocabulary1_id,
|
||||
'edit terms in ' . $vocabulary2_id,
|
||||
'delete terms in ' . $vocabulary2_id,
|
||||
]);
|
||||
$this->drupalLogin($edit_delete_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->linkExists('Edit');
|
||||
$assert_session->linkExists('Delete');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
$assert_session->buttonExists('Save');
|
||||
$assert_session->pageTextContains('Weight');
|
||||
$assert_session->pageTextContains($edit_help_text);
|
||||
|
||||
// Visit vocabulary overview without terms. 'Add term' should not be shown.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('No terms available');
|
||||
$assert_session->linkNotExists('Add term');
|
||||
|
||||
// Login as a user with permission to create new terms, only add new term
|
||||
// link should be visible.
|
||||
$edit_user = $this->createUser([
|
||||
'access taxonomy overview',
|
||||
'create terms in ' . $vocabulary1_id,
|
||||
'create terms in ' . $vocabulary2_id,
|
||||
]);
|
||||
$this->drupalLogin($edit_user);
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary1_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->linkNotExists('Edit');
|
||||
$assert_session->linkNotExists('Delete');
|
||||
$assert_session->linkExists('Add term');
|
||||
$assert_session->buttonNotExists('Save');
|
||||
$assert_session->pageTextNotContains('Weight');
|
||||
$assert_session->pageTextContains($no_edit_help_text);
|
||||
|
||||
// Visit vocabulary overview without terms. 'Add term' should not be shown.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary2_id . '/overview');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->pageTextContains('No terms available');
|
||||
$assert_session->linkExists('Add term');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +238,9 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
|
||||
$this->assert(isset($view_link), 'The message area contains a link to a term');
|
||||
|
||||
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
|
||||
$terms = \Drupal::entityTypeManager()
|
||||
->getStorage('taxonomy_term')
|
||||
->loadByProperties(['name' => $edit['name[0][value]']]);
|
||||
$term = reset($terms);
|
||||
|
||||
// Edit the term.
|
||||
@@ -62,6 +260,35 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
$this->drupalPostForm(NULL, NULL, t('Delete'));
|
||||
$this->assertRaw(t('Deleted term %name.', ['%name' => $edit['name[0][value]']]), 'Term deleted.');
|
||||
|
||||
// Test as user with "create" permissions.
|
||||
$user = $this->drupalCreateUser(["create terms in {$vocabulary->id()}"]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
$assert_session = $this->assertSession();
|
||||
|
||||
// Create a new term.
|
||||
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
|
||||
$assert_session->statusCodeEquals(200);
|
||||
$assert_session->fieldExists('name[0][value]');
|
||||
|
||||
// Submit the term.
|
||||
$edit = [];
|
||||
$edit['name[0][value]'] = $this->randomMachineName();
|
||||
|
||||
$this->drupalPostForm(NULL, $edit, t('Save'));
|
||||
$assert_session->pageTextContains(t('Created new term @name.', ['@name' => $edit['name[0][value]']]));
|
||||
|
||||
$terms = \Drupal::entityTypeManager()
|
||||
->getStorage('taxonomy_term')
|
||||
->loadByProperties(['name' => $edit['name[0][value]']]);
|
||||
$term = reset($terms);
|
||||
|
||||
// Ensure that edit and delete access is denied.
|
||||
$this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
|
||||
$assert_session->statusCodeEquals(403);
|
||||
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
|
||||
$assert_session->statusCodeEquals(403);
|
||||
|
||||
// Test as user with "edit" permissions.
|
||||
$user = $this->drupalCreateUser(["edit terms in {$vocabulary->id()}"]);
|
||||
$this->drupalLogin($user);
|
||||
|
||||
Reference in New Issue
Block a user