You are here

public function EckEntityTypeListBuilder::buildRow in Entity Construction Kit (ECK) 8

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/Controller/EckEntityTypeListBuilder.php, line 76

Class

EckEntityTypeListBuilder
Provides a listing of ECK entities.

Namespace

Drupal\eck\Controller

Code

public function buildRow(EntityInterface $entity) {
  $row['label'] = $entity
    ->label();
  $row['machine_name'] = $entity
    ->id();
  if (!$this->eckBundleInfo
    ->entityTypeHasBundles($entity
    ->id())) {
    $row['operations']['data']['#links']['add_bundle'] = [
      'title' => $this
        ->t('Add bundle'),
      'url' => new Url('eck.entity.' . $entity
        ->id() . '_type.add'),
    ];
  }
  else {

    // Add link to list operation.
    $row['operations']['data']['#links']['add_content'] = [
      'title' => $this
        ->t('Add content'),
      'url' => new Url('eck.entity.add_page', [
        'eck_entity_type' => $entity
          ->id(),
      ]),
    ];

    // Directly link to the add entity page if there is only one bundle.
    if ($this->eckBundleInfo
      ->entityTypeBundleCount($entity
      ->id()) === 1) {
      $bundle_machine_names = $this->eckBundleInfo
        ->getEntityTypeBundleMachineNames($entity
        ->id());
      $arguments = [
        'eck_entity_type' => $entity
          ->id(),
        'eck_entity_bundle' => reset($bundle_machine_names),
      ];
      $row['operations']['data']['#links']['add_content']['url'] = new Url('eck.entity.add', $arguments);
    }
    $contentExists = (bool) $this->entityTypeManager
      ->getStorage($entity
      ->id())
      ->getQuery()
      ->accessCheck(FALSE)
      ->range(0, 1)
      ->execute();
    if ($contentExists) {

      // Add link to list operation.
      $row['operations']['data']['#links']['content_list'] = [
        'title' => $this
          ->t('Content list'),
        'url' => new Url('eck.entity.' . $entity
          ->id() . '.list'),
      ];
    }
  }
  $row['operations']['data']['#links']['bundle_list'] = [
    'title' => $this
      ->t('Bundle list'),
    'url' => new Url('eck.entity.' . $entity
      ->id() . '_type.list'),
  ];
  return array_merge_recursive($row, parent::buildRow($entity));
}