3 namespace Drupal\taxonomy;
5 use Drupal\Core\Config\Entity\DraggableListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Form\FormStateInterface;
11 * Defines a class to build a listing of taxonomy vocabulary entities.
13 * @see \Drupal\taxonomy\Entity\Vocabulary
15 class VocabularyListBuilder extends DraggableListBuilder {
20 protected $entitiesKey = 'vocabularies';
25 public function getFormId() {
26 return 'taxonomy_overview_vocabularies';
32 public function getDefaultOperations(EntityInterface $entity) {
33 $operations = parent::getDefaultOperations($entity);
35 if (isset($operations['edit'])) {
36 $operations['edit']['title'] = t('Edit vocabulary');
39 $operations['list'] = [
40 'title' => t('List terms'),
42 'url' => $entity->urlInfo('overview-form'),
44 $operations['add'] = [
45 'title' => t('Add terms'),
47 'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]),
49 unset($operations['delete']);
57 public function buildHeader() {
58 $header['label'] = t('Vocabulary name');
59 $header['description'] = t('Description');
60 return $header + parent::buildHeader();
66 public function buildRow(EntityInterface $entity) {
67 $row['label'] = $entity->label();
68 $row['description']['data'] = ['#markup' => $entity->getDescription()];
69 return $row + parent::buildRow($entity);
75 public function render() {
76 $entities = $this->load();
77 // If there are not multiple vocabularies, disable dragging by unsetting the
79 if (count($entities) <= 1) {
80 unset($this->weightKey);
82 $build = parent::render();
83 $build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [':link' => \Drupal::url('entity.taxonomy_vocabulary.add_form')]);
90 public function buildForm(array $form, FormStateInterface $form_state) {
91 $form = parent::buildForm($form, $form_state);
92 $form['vocabularies']['#attributes'] = ['id' => 'taxonomy'];
93 $form['actions']['submit']['#value'] = t('Save');
101 public function submitForm(array &$form, FormStateInterface $form_state) {
102 parent::submitForm($form, $form_state);
104 drupal_set_message(t('The configuration options have been saved.'));