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