component_library-1.0.x-dev/src/ComponentLibraryVariantListBuilder.php

src/ComponentLibraryVariantListBuilder.php
<?php

declare(strict_types=1);

namespace Drupal\component_library;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Url;

/**
 * Provides a list controller for the component library variant entity type.
 */
final class ComponentLibraryVariantListBuilder extends EntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function render(): array {
    $build = [];
    $build['table'] = parent::render();

    $total = $this->getStorage()
      ->getQuery()
      ->accessCheck(FALSE)
      ->count()
      ->execute();

    $build['summary']['#markup'] = $this->t('Total component library variants: @total', ['@total' => $total]);
    return $build;
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader(): array {
    $header = [];
    $header['label'] = $this->t('Label');
    $header['id'] = $this->t('ID');
    $header['status'] = $this->t('Status');
    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity): array {
    $row = [];
    /** @var \Drupal\component_library\ComponentLibraryVariantInterface $entity */
    $row['label'] = $entity->toLink();
    $row['id'] = $entity->get('id');
    $row['status'] = $entity->get('status') === TRUE ? $this->t('Enabled') : $this->t('Disabled');
    return $row + parent::buildRow($entity);
  }

  /**
   * {@inheritdoc}
   */
  protected function getDefaultOperations(EntityInterface $entity): array {
    $operations = parent::getDefaultOperations($entity);
    foreach ($operations as $key => $operation) {
      $operations[$key]['query']['destination'] = Url::fromRoute('<current>')->toString();
    }
    return $operations;
  }

}

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

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