class MenuLinkListBuilder

Same name and namespace in other branches
  1. 11.x core/modules/menu_link_content/src/MenuLinkListBuilder.php \Drupal\menu_link_content\MenuLinkListBuilder

Provides a menu link list builder.

Hierarchy

Expanded class hierarchy of MenuLinkListBuilder

File

core/modules/menu_link_content/src/MenuLinkListBuilder.php, line 15

Namespace

Drupal\menu_link_content
View source
class MenuLinkListBuilder extends EntityListBuilder {
  
  /**
   * The redirect destination.
   *
   * @var \Drupal\Core\Routing\RedirectDestinationInterface
   */
  protected $redirectDestination;
  
  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static($entity_type, $container->get('entity_type.manager')
      ->getStorage($entity_type->id()), $container->get('redirect.destination'));
  }
  
  /**
   * Constructs a new instance.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param \Drupal\Core\Entity\EntityStorageInterface $storage
   *   The entity storage class.
   * @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
   *   The redirect destination.
   */
  public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RedirectDestinationInterface $redirect_destination) {
    parent::__construct($entity_type, $storage);
    $this->redirectDestination = $redirect_destination;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDefaultOperations(EntityInterface $entity) {
    $operations = parent::getDefaultOperations($entity);
    $destination = $this->redirectDestination
      ->get();
    foreach ($operations as $key => $operation) {
      $operations[$key]['query']['destination'] = $destination;
    }
    return $operations;
  }
  
  /**
   * {@inheritdoc}
   */
  public function render() {
    throw new \LogicException('This list builder can only provide operations. It does not build lists.');
  }

}

Members

Title Sort descending Modifiers Object type Summary
MenuLinkListBuilder::$redirectDestination protected property The redirect destination.
MenuLinkListBuilder::createInstance public static function Instantiates a new instance of this entity handler.
MenuLinkListBuilder::getDefaultOperations public function Gets this list's default operations.
MenuLinkListBuilder::render public function Builds the entity listing as renderable array for table.html.twig.
MenuLinkListBuilder::__construct public function Constructs a new instance.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.