You are here

public function DirectoryListBuilder::buildRow in Private files download permission 8.2

Same name and namespace in other branches
  1. 3.x src/DirectoryListBuilder.php \Drupal\pfdp\DirectoryListBuilder::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/DirectoryListBuilder.php, line 71

Class

DirectoryListBuilder
Defines a class to build a list of Private files download permission directory entities.

Namespace

Drupal\pfdp

Code

public function buildRow(EntityInterface $entity) {
  $pfdp_directory = $entity;

  // Prepare the table row for the directory.
  $row = [];
  $row['id'] = $pfdp_directory
    ->id();
  $row['path'] = $pfdp_directory->path;
  $row['bypass'] = $pfdp_directory->bypass ? $this
    ->t('Yes') : '';
  $row['users'] = implode(', ', array_map(function ($uid) {
    $user = User::load($uid);
    return $user ? $user
      ->label() : NULL;
  }, pfdp_get_proper_user_array($pfdp_directory->users)));
  if ($pfdp_directory->grant_file_owners) {
    $row['users'] = $this
      ->t('File owners') . ', ' . $row['users'];
  }
  if (', ' == mb_substr($row['users'], -2, 2)) {
    $row['users'] = mb_substr($row['users'], 0, -2);
  }
  $row['roles'] = implode(', ', array_map(function ($rid) {
    $role = Role::load($rid);
    return $role ? $role
      ->label() : NULL;
  }, $pfdp_directory->roles));
  if (', ' == mb_substr($row['roles'], -2, 2)) {
    $row['roles'] = mb_substr($row['roles'], 0, -2);
  }

  // Return the table row.
  return $row + parent::buildRow($pfdp_directory);
}