SplashifyEntityListBuilder.php in Splashify 8.2
File
src/SplashifyEntityListBuilder.php
View source
<?php
namespace Drupal\splashify;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Url;
use Drupal\splashify\Entity\SplashifyGroupEntity;
class SplashifyEntityListBuilder extends EntityListBuilder {
use LinkGeneratorTrait;
public function buildHeader() {
$header['id'] = $this
->t('ID');
$header['name'] = $this
->t('Name');
$header['group'] = $this
->t('Group');
$header['weight'] = $this
->t('Weight');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['name'] = $this
->l($entity
->label(), new Url('entity.splashify_entity.edit_form', array(
'splashify_entity' => $entity
->id(),
)));
$entity_id = $entity->field_group
->getValue();
$entity_id = $entity_id[0]['target_id'];
$entity_group = SplashifyGroupEntity::load($entity_id);
if (!empty($entity_group)) {
$row['group'] = $this
->l($entity_group
->label(), new Url('entity.splashify_group_entity.edit_form', array(
'splashify_group_entity' => $entity_id,
)));
}
else {
$row['group'] = $this
->t('None');
}
$row['weight'] = $entity->field_weight->value;
return $row + parent::buildRow($entity);
}
protected function getEntityIds() {
$query = \Drupal::entityQuery('splashify_entity')
->sort('field_weight', 'DESC')
->sort('id', 'DESC');
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
}