update drupal

This commit is contained in:
Tessier
2020-10-15 11:59:37 +02:00
parent ebb5db14b5
commit d8b9162932
558 changed files with 5954 additions and 4475 deletions
@@ -60,7 +60,6 @@ class TaxonomyTermHierarchyConstraintValidator extends ConstraintValidator imple
$new_parents = array_column($entity->parent->getValue(), 'target_id');
$original_parents = array_keys($term_storage->loadParents($entity->id())) ?: [0];
if (($is_pending_revision || $ancestor_is_pending_revision) && $new_parents != $original_parents) {
$a = 1;
$this->context->buildViolation($constraint->message)
->atPath('parent')
->addViolation();
@@ -24,6 +24,8 @@ class TaxonomyTermReference extends FieldPluginBase {
public function getFieldFormatterMap() {
return [
'taxonomy_term_reference_link' => 'entity_reference_label',
'taxonomy_term_reference_plain' => 'entity_reference_label',
'taxonomy_term_reference_rss_category' => 'entity_reference_label',
'i18n_taxonomy_term_reference_link' => 'entity_reference_label',
'entityreference_entity_view' => 'entity_reference_entity_view',
];
@@ -4,6 +4,7 @@ namespace Drupal\taxonomy\Plugin\views\filter;
use Drupal\Core\Entity\Element\EntityAutocomplete;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\TermStorageInterface;
use Drupal\taxonomy\VocabularyStorageInterface;
@@ -38,6 +39,13 @@ class TaxonomyIndexTid extends ManyToOne {
*/
protected $termStorage;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* Constructs a TaxonomyIndexTid object.
*
@@ -51,11 +59,18 @@ class TaxonomyIndexTid extends ManyToOne {
* The vocabulary storage.
* @param \Drupal\taxonomy\TermStorageInterface $term_storage
* The term storage.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage, TermStorageInterface $term_storage) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, VocabularyStorageInterface $vocabulary_storage, TermStorageInterface $term_storage, AccountInterface $current_user = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->vocabularyStorage = $vocabulary_storage;
$this->termStorage = $term_storage;
if (!$current_user) {
@trigger_error('The current_user service must be passed to ' . __NAMESPACE__ . '\TaxonomyIndexTid::__construct(). It was added in drupal:8.9.0 and will be required before drupal:10.0.0.', E_USER_DEPRECATED);
$current_user = \Drupal::service('current_user');
}
$this->currentUser = $current_user;
}
/**
@@ -67,7 +82,8 @@ class TaxonomyIndexTid extends ManyToOne {
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager')->getStorage('taxonomy_vocabulary'),
$container->get('entity_type.manager')->getStorage('taxonomy_term')
$container->get('entity_type.manager')->getStorage('taxonomy_term'),
$container->get('current_user')
);
}
@@ -181,6 +197,9 @@ class TaxonomyIndexTid extends ManyToOne {
if ($tree) {
foreach ($tree as $term) {
if (!$term->isPublished() && !$this->currentUser->hasPermission('administer taxonomy')) {
continue;
}
$choice = new \stdClass();
$choice->option = [$term->id() => str_repeat('-', $term->depth) . \Drupal::service('entity.repository')->getTranslationFromContext($term)->label()];
$options[] = $choice;
@@ -195,6 +214,9 @@ class TaxonomyIndexTid extends ManyToOne {
->sort('weight')
->sort('name')
->addTag('taxonomy_term_access');
if (!$this->currentUser->hasPermission('administer taxonomy')) {
$query->condition('status', 1);
}
if ($this->options['limit']) {
$query->condition('vid', $vocabulary->id());
}
@@ -133,7 +133,9 @@ class NodeTermData extends RelationshipPluginBase {
$query = Database::getConnection()->select('taxonomy_term_field_data', 'td');
$query->addJoin($def['type'], 'taxonomy_index', 'tn', 'tn.tid = td.tid');
$query->condition('td.vid', array_filter($this->options['vids']), 'IN');
$query->addTag('taxonomy_term_access');
if (empty($this->query->options['disable_sql_rewrite'])) {
$query->addTag('taxonomy_term_access');
}
$query->fields('td');
$query->fields('tn', ['nid']);
$def['table formula'] = $query;
@@ -63,13 +63,13 @@ class TaxonomyTermPagerTest extends TaxonomyTestBase {
$this->createTerm($this->vocabulary);
}
// Get Page 1.
// Ensure that pager is visible on page 1.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertPattern('|<nav class="pager" [^>]*>|', 'Pager is visible on page 1');
$this->assertPattern('|<nav class="pager" [^>]*>|');
// Get Page 2.
// Ensure that pager is visible on page 2.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
$this->assertPattern('|<nav class="pager" [^>]*>|', 'Pager is visible on page 2');
$this->assertPattern('|<nav class="pager" [^>]*>|');
}
}
@@ -117,10 +117,12 @@ class TermIndexTest extends TaxonomyTestBase {
// Check that the term is indexed, and only once.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$connection = Database::getConnection();
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_1->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
// Update the article to change one term.
@@ -128,15 +130,19 @@ class TermIndexTest extends TaxonomyTestBase {
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Check that both terms are indexed.
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_1->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed.');
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_2->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term.
@@ -144,15 +150,19 @@ class TermIndexTest extends TaxonomyTestBase {
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Check that only one term is indexed.
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_1->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_2->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Redo the above tests without interface.
@@ -164,15 +174,19 @@ class TermIndexTest extends TaxonomyTestBase {
$node->save();
// Check that the index was not changed.
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_1->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_2->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Update the article to change one term.
@@ -180,15 +194,19 @@ class TermIndexTest extends TaxonomyTestBase {
$node->save();
// Check that both terms are indexed.
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_1->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed.');
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_2->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term.
@@ -196,15 +214,19 @@ class TermIndexTest extends TaxonomyTestBase {
$node->save();
// Check that only one term is indexed.
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_1->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
$index_count = $connection->query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
])->fetchField();
$index_count = $connection->select('taxonomy_index')
->condition('nid', $node->id())
->condition('tid', $term_2->id())
->countQuery()
->execute()
->fetchField();
$this->assertEqual(0, $index_count, 'Term 2 is not indexed.');
}
@@ -142,7 +142,7 @@ class TermLanguageTest extends TaxonomyTestBase {
// Overview page in the other language shows the translated term
$this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertPattern('|<a[^>]*>' . $translated_title . '</a>|', 'The term language is correct');
$this->assertPattern('|<a[^>]*>' . $translated_title . '</a>|');
}
}
@@ -3,6 +3,7 @@
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
use Drupal\views\ViewExecutable;
/**
* Tests the taxonomy term on node relationship handler.
@@ -60,4 +61,52 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}
/**
* Tests that the 'taxonomy_term_access' tag is added to the Views query.
*/
public function testTag() {
// Change the view to test relation limited by vocabulary.
$this->config('views.view.test_taxonomy_node_term_data')
->set('display.default.display_options.relationships.term_node_tid.vids', ['views_testing_tags'])
->save();
$view = Views::getView('test_taxonomy_node_term_data');
$this->executeView($view, [$this->term1->id()]);
// By default, view has taxonomy_term_access tag.
$this->assertQueriesTermAccessTag($view, TRUE);
// The term_access tag is not set if disable_sql_rewrite is set.
$view = Views::getView('test_taxonomy_node_term_data');
$display = $view->getDisplay();
$display_options = $display->getOption('query');
$display_options['options']['disable_sql_rewrite'] = TRUE;
$display->setOption('query', $display_options);
$view->save();
$this->executeView($view, [$this->term1->id()]);
$this->assertQueriesTermAccessTag($view, FALSE);
}
/**
* Assert views queries have taxonomy_term_access tag.
*
* @param \Drupal\views\ViewExecutable $view
* The View to check for the term access tag.
* @param bool $hasTag
* The expected existence of taxonomy_term_access tag.
*/
protected function assertQueriesTermAccessTag(ViewExecutable $view, $hasTag) {
$main_query = $view->build_info['query'];
$count_query = $view->build_info['count_query'];
foreach ([$main_query, $count_query] as $query) {
$tables = $query->getTables();
foreach ($tables as $join_table) {
if (is_object($join_table['table'])) {
$this->assertSame($join_table['table']->hasTag('taxonomy_term_access'), $hasTag);
}
}
}
}
}
@@ -231,4 +231,41 @@ class TaxonomyIndexTidUiTest extends UITestBase {
$this->assertTrue(empty($preview), 'No results.');
}
/**
* Tests that an exposed taxonomy filter doesn't show unpublished terms.
*/
public function testExposedUnpublishedFilterOptions() {
$this->terms[1][0]->setUnpublished()->save();
// Expose the filter.
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', [], 'Expose filter');
$edit = ['options[expose_button][checkbox][checkbox]' => TRUE];
$this->drupalPostForm(NULL, $edit, 'Apply');
$this->drupalPostForm(NULL, [], 'Save');
// Make sure the unpublished term is shown to the admin user.
$this->drupalGet('test-filter-taxonomy-index-tid');
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[0][0]->id() . '"]'));
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
$this->drupalLogout();
$this->drupalGet('test-filter-taxonomy-index-tid');
// Make sure the unpublished term isn't shown to the anonymous user.
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[0][0]->id() . '"]'));
$this->assertEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
// Tests that the term also isn't shown when not showing hierarchy.
$this->drupalLogin($this->adminUser);
$edit = [
'options[hierarchy]' => FALSE,
];
$this->drupalPostForm('admin/structure/views/nojs/handler-extra/test_filter_taxonomy_index_tid/default/filter/tid', $edit, 'Apply');
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalGet('test-filter-taxonomy-index-tid');
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[0][0]->id() . '"]'));
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
$this->drupalLogout();
$this->drupalGet('test-filter-taxonomy-index-tid');
// Make sure the unpublished term isn't shown to the anonymous user.
$this->assertNotEmpty($this->cssSelect('option[value="' . $this->terms[0][0]->id() . '"]'));
$this->assertEmpty($this->cssSelect('option[value="' . $this->terms[1][0]->id() . '"]'));
}
}