Commit d27a372a authored by catch's avatar catch

Issue #2920672 by idebr, dpagini, abramm, xjm: OverviewTerms page has invalid...

Issue #2920672 by idebr, dpagini, abramm, xjm: OverviewTerms page has invalid table HTML when the user does not have access to some terms
parent b6242dab
......@@ -241,6 +241,11 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
$form['terms'] = [
'#type' => 'table',
'#empty' => $empty,
'#header' => [
'term' => $this->t('Name'),
'operations' => $this->t('Operations'),
'weight' => $this->t('Weight'),
],
'#attributes' => [
'id' => 'taxonomy',
],
......@@ -251,6 +256,11 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
// all terms.
$change_weight_access = AccessResult::allowed();
foreach ($current_page as $key => $term) {
$form['terms'][$key] = [
'term' => [],
'operations' => [],
'weight' => [],
];
/** @var $term \Drupal\Core\Entity\EntityInterface */
$term = $this->entityManager->getTranslationFromContext($term);
$form['terms'][$key]['#term'] = $term;
......@@ -344,11 +354,8 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
$row_position++;
}
$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',
......@@ -377,8 +384,6 @@ public function buildForm(array $form, FormStateInterface $form_state, Vocabular
];
}
$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'] = [
......
......@@ -123,7 +123,7 @@ public function buildHeader() {
$header['label'] = t('Vocabulary name');
$header['description'] = t('Description');
if ($this->currentUser->hasPermission('administer vocabularies')) {
if ($this->currentUser->hasPermission('administer vocabularies') && !empty($this->weightKey)) {
$header['weight'] = t('Weight');
}
......
......@@ -83,6 +83,7 @@ public function testTaxonomyVocabularyOverviewPermissions() {
$assert_session->linkExists('Add term');
$assert_session->buttonExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldExists('Weight');
$assert_session->pageTextContains($edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should be shown.
......@@ -108,7 +109,8 @@ public function testTaxonomyVocabularyOverviewPermissions() {
$assert_session->linkNotExists('Edit');
$assert_session->linkNotExists('Delete');
$assert_session->buttonNotExists('Save');
$assert_session->pageTextNotContains('Weight');
$assert_session->pageTextContains('Weight');
$assert_session->fieldNotExists('Weight');
$assert_session->linkNotExists('Add term');
$assert_session->pageTextContains($no_edit_help_text);
......@@ -132,6 +134,7 @@ public function testTaxonomyVocabularyOverviewPermissions() {
$assert_session->linkNotExists('Delete');
$assert_session->buttonExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldExists('Weight');
$assert_session->linkNotExists('Add term');
$assert_session->pageTextContains($edit_help_text);
......@@ -154,7 +157,8 @@ public function testTaxonomyVocabularyOverviewPermissions() {
$assert_session->linkExists('Delete');
$assert_session->linkNotExists('Add term');
$assert_session->buttonNotExists('Save');
$assert_session->pageTextNotContains('Weight');
$assert_session->pageTextContains('Weight');
$assert_session->fieldNotExists('Weight');
$assert_session->pageTextContains($no_edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
......@@ -179,6 +183,7 @@ public function testTaxonomyVocabularyOverviewPermissions() {
$assert_session->linkNotExists('Add term');
$assert_session->buttonExists('Save');
$assert_session->pageTextContains('Weight');
$assert_session->fieldExists('Weight');
$assert_session->pageTextContains($edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
......@@ -201,7 +206,8 @@ public function testTaxonomyVocabularyOverviewPermissions() {
$assert_session->linkNotExists('Delete');
$assert_session->linkExists('Add term');
$assert_session->buttonNotExists('Save');
$assert_session->pageTextNotContains('Weight');
$assert_session->pageTextContains('Weight');
$assert_session->fieldNotExists('Weight');
$assert_session->pageTextContains($no_edit_help_text);
// Visit vocabulary overview without terms. 'Add term' should not be shown.
......
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