MenuListController.php 2.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
<?php

/**
 * Contains \Drupal\menu\MenuListController.
 */

namespace Drupal\menu;

use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityInterface;

/**
13
 * Provides a listing of menus.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 */
class MenuListController extends ConfigEntityListController {

  /**
   * Overrides \Drupal\Core\Entity\EntityListController::buildHeader().
   */
  public function buildHeader() {
    $row['title'] = t('Title');
    $row['description'] = array(
      'data' => t('Description'),
      'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
    );
    $row['operations'] = t('Operations');
    return $row;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityListController::buildRow().
   */
  public function buildRow(EntityInterface $entity) {
    $row['title'] = array(
      'data' => check_plain($entity->label()),
      'class' => array('menu-label'),
    );
    $row['description'] = filter_xss_admin($entity->description);
    $row['operations']['data'] = $this->buildOperations($entity);
    return $row;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityListController::getOperations();
   */
  public function getOperations(EntityInterface $entity) {
    $operations = parent::getOperations($entity);
    $uri = $entity->uri();

50
    $operations['edit']['title'] = t('Edit menu');
51
    $operatuins['edit']['href'] = $uri['path'];
52
    $operations['add'] = array(
53
      'title' => t('Add link'),
54
55
56
57
      'href' => $uri['path'] . '/add',
      'options' => $uri['options'],
      'weight' => 20,
    );
58
59
60
61
    // System menus could not be deleted.
    $system_menus = menu_list_system_menus();
    if (isset($system_menus[$entity->id()])) {
      unset($operations['delete']);
62
63
    }
    else {
64
      $operations['delete']['title'] = t('Delete menu');
65
66
67
68
69
70
71
72
73
    }
    return $operations;
  }

  /**
   * Overrides \Drupal\Core\Entity\EntityListController::render();
   */
  public function render() {
    $build = parent::render();
74
    $build['#attached']['css'][] = drupal_get_path('module', 'menu') . '/css/menu.admin.css';
75
76
77
78
    return $build;
  }

}