BlogListBuilder.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Drupal\dr8_zth;
  3. use Drupal\Core\Entity\EntityInterface;
  4. use Drupal\Core\Entity\EntityListBuilder;
  5. use Drupal\dr8_zth\Entity\Blog;
  6. use Drupal\dr8_zth\Entity\BlogType;
  7. /**
  8. * Class BlogListBuilder is the list builder for Blog entities.
  9. */
  10. class BlogListBuilder extends EntityListBuilder {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function buildHeader() {
  15. $parentHeader = parent::buildHeader();
  16. $header = [
  17. $this->t('ID'),
  18. $this->t('Title'),
  19. $this->t('Type'),
  20. $this->t('Author'),
  21. ];
  22. $ret = array_merge($header, $parentHeader);
  23. return $ret;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function buildRow(EntityInterface $entity) {
  29. assert($entity instanceof Blog);
  30. $author = $entity->getAuthor()->toLink();
  31. $bundle = $entity->bundle();
  32. $blogType = BlogType::load($bundle);
  33. $blogTypeEditLink = $blogType->toLink($bundle, 'edit-form');
  34. $row = [
  35. $entity->id(),
  36. $entity->label(),
  37. $blogTypeEditLink,
  38. $author,
  39. ];
  40. $ret = array_merge($row, parent::buildRow($entity));
  41. return $ret;
  42. }
  43. }