You are here

FlaggingCollectionListBuilder.php in Flag Lists 8

Same filename and directory in other branches
  1. 4.0.x src/FlaggingCollectionListBuilder.php

Namespace

Drupal\flag_lists

File

src/FlaggingCollectionListBuilder.php
View source
<?php

namespace Drupal\flag_lists;

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

/**
 * Defines a class to build a listing of Flagging collection entities.
 *
 * @ingroup flag_lists
 */
class FlaggingCollectionListBuilder extends EntityListBuilder {

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {
    $header['name'] = $this
      ->t('Flagging Collection');
    $header['id'] = $this
      ->t('ID');
    $header['bundle']['data'] = $this
      ->t('Bundle');
    $header['templateflag']['data'] = $this
      ->t('Flag for List');
    $header['relatedflag']['data'] = $this
      ->t('The related flag');
    $header['base_flag']['data'] = $this
      ->t('Template Flag');
    $header['owner']['data'] = $this
      ->t('Owner');
    $header['scope']['data'] = $this
      ->t('Scope');
    $header['operations']['data'] = $this
      ->t('Operations');

    // Don't call parent as we add the Operations header ourselves
    // $header[] = parent::buildHeader();
    return $header;
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {

    /* @var $entity \Drupal\flag_lists\Entity\FlaggingCollection */
    $baseflag = $entity
      ->getBaseFlag();
    $relatedflag = $entity
      ->getRelatedFlag();
    $flagListService = \Drupal::service('flaglists');
    $flag = $flagListService
      ->getFlagForListById($baseflag
      ->id());
    $account = \Drupal::currentUser()
      ->getAccount();
    if ($entity
      ->access('view', $account)) {
      $row = [];
      $row['name'] = Link::createFromRoute($entity
        ->label(), 'entity.flagging_collection.edit_form', [
        'flagging_collection' => $entity
          ->id(),
      ]);
      $row['id'] = $entity
        ->id();
      $row['bundle'] = Link::createFromRoute($flagListService
        ->getFlaggingCollectionTypeById($entity
        ->bundle())
        ->label(), 'entity.flagging_collection_type.collection');
      $row['templateflag'] = Link::createFromRoute($flagListService
        ->getFlagForListById($baseflag
        ->id())
        ->label(), 'entity.flag_for_list.collection');
      $row['relatedflag'] = $relatedflag
        ->label();
      $row['base_flag'] = $baseflag
        ->label();
      $row['owner'] = $entity
        ->getOwner()
        ->label();
      $row['scope'] = $baseflag
        ->isGlobal() ? $this
        ->t('Global') : $this
        ->t('Personal');
      return $row + parent::buildRow($entity);
    }
  }

}

Classes

Namesort descending Description
FlaggingCollectionListBuilder Defines a class to build a listing of Flagging collection entities.