Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / modules / menu_ui / src / MenuListBuilder.php
1 <?php
2
3 namespace Drupal\menu_ui;
4
5 use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
6 use Drupal\Core\Entity\EntityInterface;
7
8 /**
9  * Defines a class to build a listing of menu entities.
10  *
11  * @see \Drupal\system\Entity\Menu
12  * @see menu_entity_info()
13  */
14 class MenuListBuilder extends ConfigEntityListBuilder {
15
16   /**
17    * {@inheritdoc}
18    */
19   public function buildHeader() {
20     $header['title'] = t('Title');
21     $header['description'] = [
22       'data' => t('Description'),
23       'class' => [RESPONSIVE_PRIORITY_MEDIUM],
24     ];
25     return $header + parent::buildHeader();
26   }
27
28   /**
29    * {@inheritdoc}
30    */
31   public function buildRow(EntityInterface $entity) {
32     $row['title'] = [
33       'data' => $entity->label(),
34       'class' => ['menu-label'],
35     ];
36     $row['description']['data'] = ['#markup' => $entity->getDescription()];
37     return $row + parent::buildRow($entity);
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function getDefaultOperations(EntityInterface $entity) {
44     $operations = parent::getDefaultOperations($entity);
45
46     if (isset($operations['edit'])) {
47       $operations['edit']['title'] = t('Edit menu');
48       $operations['add'] = [
49         'title' => t('Add link'),
50         'weight' => 20,
51         'url' => $entity->urlInfo('add-link-form'),
52       ];
53     }
54     if (isset($operations['delete'])) {
55       $operations['delete']['title'] = t('Delete menu');
56     }
57     return $operations;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function render() {
64     $build = parent::render();
65     $build['#attached']['library'][] = "menu_ui/drupal.menu_ui.adminforms";
66     return $build;
67   }
68
69 }