You are here

ContentMenuListController.php in Content Menu 8

File

lib/Drupal/content_menu/ContentMenuListController.php
View source
<?php

/**
 * Contains \Drupal\content_menu\ContentMenuListController.
 */
namespace Drupal\content_menu;

use Drupal\menu\MenuListController;
use Drupal\Core\Entity\EntityInterface;

/**
 * Provides a simplified listing of Menus
 */
class ContentMenuListController extends MenuListController {

  /**
   * Override \Drupal\menu\MenuListController::buildHeader()
   */
  public function buildHeader() {
    $row = parent::buildHeader();
    unset($row['description']);
    return $row;
  }

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

  /**
   * Overrides \Drupal\menu\MenuListController::getOperations().
   */
  public function getOperations(EntityInterface $entity) {
    $operations = parent::getOperations($entity);
    unset($operations['add']);
    unset($operations['delete']);
    return $operations;
  }

  /**
   *  Overrides \Drupal\Core\Entity\EntityListController::render().
   */
  public function render() {
    $build = array(
      '#theme' => 'table',
      '#header' => $this
        ->buildHeader(),
      '#rows' => array(),
      '#empty' => t('There is no @label yet.', array(
        '@label' => $this->entityInfo['label'],
      )),
    );
    foreach ($this
      ->load() as $entity) {
      if (content_menu_is_menu_considered($entity
        ->id()) || user_access('administer system menus')) {
        $build['#rows'][$entity
          ->id()] = $this
          ->buildRow($entity);
      }
    }
    return $build;
  }

}

Classes

Namesort descending Description
ContentMenuListController Provides a simplified listing of Menus