MenuListBuilder.php 1.6 KB

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