contacts_events-8.x-1.x-dev/modules/teams/src/TeamListBuilder.php

modules/teams/src/TeamListBuilder.php
<?php

namespace Drupal\contacts_events_teams;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines a class to build a listing of Team entities.
 *
 * @ingroup contacts_events_teams
 */
class TeamListBuilder extends EntityListBuilder {

  /**
   * The current route match.
   *
   * @var \Drupal\Core\Routing\CurrentRouteMatch
   */
  protected $routeMatch;

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    $self = parent::createInstance($container, $entity_type);
    $self->routeMatch = $container->get('current_route_match');
    return $self;
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['id'] = $this->t('ID');
    $header['name'] = $this->t('Name');
    $header['category'] = $this->t('Category');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {
    /** @var \Drupal\contacts_events_teams\Entity\Team $entity */
    $row['id'] = $entity->id();
    $row['name'] = $entity->label();
    $row['category'] = $entity->get('category')->entity->label();
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  protected function getDefaultOperations(EntityInterface $entity) {
    $operations = [];

    if ($entity->access('view') && $entity->hasLinkTemplate('canonical')) {
      $operations['view'] = [
        'title' => $this->t('View applications'),
        'weight' => 0,
        'url' => Url::fromRoute('entity.c_events_team.canonical', [
          'c_events_team' => $entity->id(),
          'contacts_event' => $entity->getEvent()->id(),
        ]),
      ];
    }

    $operations = $operations + parent::getDefaultOperations($entity);
    $destination = $this->redirectDestination->getAsArray();
    foreach ($operations as $key => $operation) {
      $operations[$key]['query'] = $destination;
    }
    return $operations;
  }

  /**
   * {@inheritdoc}
   */
  protected function getEntityIds() {
    $query = $this->getStorage()->getQuery()
      ->sort('category.entity.name')
      ->sort('name');

    $query->accessCheck(TRUE);

    $query->condition('event', $this->routeMatch->getRawParameter('contacts_event'));

    // Only add the pager if a limit is specified.
    if ($this->limit) {
      $query->pager($this->limit);
    }
    return $query->execute();
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc