12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace Drupal\dr8_zth;
- use Drupal\Core\Entity\EntityInterface;
- use Drupal\Core\Entity\EntityListBuilder;
- use Drupal\dr8_zth\Entity\Blog;
- use Drupal\dr8_zth\Entity\BlogType;
- /**
- * Class BlogListBuilder is the list builder for Blog entities.
- */
- class BlogListBuilder extends EntityListBuilder {
- /**
- * {@inheritdoc}
- */
- public function buildHeader() {
- $parentHeader = parent::buildHeader();
- $header = [
- $this->t('ID'),
- $this->t('Title'),
- $this->t('Type'),
- $this->t('Author'),
- ];
- $ret = array_merge($header, $parentHeader);
- return $ret;
- }
- /**
- * {@inheritdoc}
- */
- public function buildRow(EntityInterface $entity) {
- assert($entity instanceof Blog);
- $author = $entity->getAuthor()->toLink();
- $bundle = $entity->bundle();
- $blogType = BlogType::load($bundle);
- $blogTypeEditLink = $blogType->toLink($bundle, 'edit-form');
- $row = [
- $entity->id(),
- $entity->label(),
- $blogTypeEditLink,
- $author,
- ];
- $ret = array_merge($row, parent::buildRow($entity));
- return $ret;
- }
- }
|