You are here

public function FlaggingCollectionListBuilder::buildRow in Flag Lists 4.0.x

Same name and namespace in other branches
  1. 8 src/FlaggingCollectionListBuilder.php \Drupal\flag_lists\FlaggingCollectionListBuilder::buildRow()

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListBuilder::render()

File

src/FlaggingCollectionListBuilder.php, line 38

Class

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

Namespace

Drupal\flag_lists

Code

public function buildRow(EntityInterface $entity) {

  /**  @var \Drupal\flag_lists\Entity\FlaggingCollectioni $entity */
  $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();
    $bundle = Link::createFromRoute($flagListService
      ->getFlaggingCollectionTypeById($entity
      ->bundle())
      ->label(), 'entity.flagging_collection_type.collection');
    if ($bundle
      ->getUrl()
      ->access($account)) {
      $row['bundle'] = $bundle;
    }
    else {
      $row['bundle'] = $flagListService
        ->getFlaggingCollectionTypeById($entity
        ->bundle())
        ->label();
    }
    $templateFlag = Link::createFromRoute($flagListService
      ->getFlagForListById($baseflag
      ->id())
      ->label(), 'entity.flag_for_list.collection');
    if ($templateFlag
      ->getUrl()
      ->access($account)) {
      $row['templateflag'] = $templateFlag;
    }
    else {
      $row['templateFlag'] = $flagListService
        ->getFlagForListById($baseflag
        ->id())
        ->label();
    }
    $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);
  }
}