comparison core/modules/taxonomy/src/VocabularyListBuilder.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\taxonomy;
4
5 use Drupal\Core\Config\Entity\DraggableListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Url;
9
10 /**
11 * Defines a class to build a listing of taxonomy vocabulary entities.
12 *
13 * @see \Drupal\taxonomy\Entity\Vocabulary
14 */
15 class VocabularyListBuilder extends DraggableListBuilder {
16
17 /**
18 * {@inheritdoc}
19 */
20 protected $entitiesKey = 'vocabularies';
21
22 /**
23 * {@inheritdoc}
24 */
25 public function getFormId() {
26 return 'taxonomy_overview_vocabularies';
27 }
28
29 /**
30 * {@inheritdoc}
31 */
32 public function getDefaultOperations(EntityInterface $entity) {
33 $operations = parent::getDefaultOperations($entity);
34
35 if (isset($operations['edit'])) {
36 $operations['edit']['title'] = t('Edit vocabulary');
37 }
38
39 $operations['list'] = [
40 'title' => t('List terms'),
41 'weight' => 0,
42 'url' => $entity->urlInfo('overview-form'),
43 ];
44 $operations['add'] = [
45 'title' => t('Add terms'),
46 'weight' => 10,
47 'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]),
48 ];
49 unset($operations['delete']);
50
51 return $operations;
52 }
53
54 /**
55 * {@inheritdoc}
56 */
57 public function buildHeader() {
58 $header['label'] = t('Vocabulary name');
59 $header['description'] = t('Description');
60 return $header + parent::buildHeader();
61 }
62
63 /**
64 * {@inheritdoc}
65 */
66 public function buildRow(EntityInterface $entity) {
67 $row['label'] = $entity->label();
68 $row['description']['data'] = ['#markup' => $entity->getDescription()];
69 return $row + parent::buildRow($entity);
70 }
71
72 /**
73 * {@inheritdoc}
74 */
75 public function render() {
76 $entities = $this->load();
77 // If there are not multiple vocabularies, disable dragging by unsetting the
78 // weight key.
79 if (count($entities) <= 1) {
80 unset($this->weightKey);
81 }
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')]);
84 return $build;
85 }
86
87 /**
88 * {@inheritdoc}
89 */
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');
94
95 return $form;
96 }
97
98 /**
99 * {@inheritdoc}
100 */
101 public function submitForm(array &$form, FormStateInterface $form_state) {
102 parent::submitForm($form, $form_state);
103
104 drupal_set_message(t('The configuration options have been saved.'));
105 }
106
107 }