You are here

VocabularyListBuilder.php in Taxonomy access fix 8.3

Same filename and directory in other branches
  1. 8 src/VocabularyListBuilder.php
  2. 8.2 src/VocabularyListBuilder.php

File

src/VocabularyListBuilder.php
View source
<?php

namespace Drupal\taxonomy_access_fix;

use Drupal\taxonomy\VocabularyListBuilder as VocabularyListBuilderBase;

/**
 * Builds administrative lists of Taxonomy Vocabulary entities.
 */
class VocabularyListBuilder extends VocabularyListBuilderBase {

  /**
   * {@inheritdoc}
   */
  public function load() {
    $entities = parent::load();

    // Remove vocabularies the current user doesn't have any access for.
    foreach ($entities as $id => $entity) {
      if (!$entity
        ->access('view')) {
        unset($entities[$id]);
      }
    }
    return $entities;
  }

  /**
   * {@inheritdoc}
   */
  public function render() {

    // Remove vocabulary sorting for non-admins.
    if (!$this->currentUser
      ->hasPermission('administer taxonomy')) {
      unset($this->weightKey);
    }
    return parent::render();
  }

}

Classes

Namesort descending Description
VocabularyListBuilder Builds administrative lists of Taxonomy Vocabulary entities.