NodeTypeListBuilder.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Drupal\node;
  3. use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
  4. use Drupal\Core\Url;
  5. use Drupal\Core\Entity\EntityInterface;
  6. /**
  7. * Defines a class to build a listing of node type entities.
  8. *
  9. * @see \Drupal\node\Entity\NodeType
  10. */
  11. class NodeTypeListBuilder extends ConfigEntityListBuilder {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function buildHeader() {
  16. $header['title'] = t('Name');
  17. $header['description'] = [
  18. 'data' => t('Description'),
  19. 'class' => [RESPONSIVE_PRIORITY_MEDIUM],
  20. ];
  21. return $header + parent::buildHeader();
  22. }
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public function buildRow(EntityInterface $entity) {
  27. $row['title'] = [
  28. 'data' => $entity->label(),
  29. 'class' => ['menu-label'],
  30. ];
  31. $row['description']['data'] = ['#markup' => $entity->getDescription()];
  32. return $row + parent::buildRow($entity);
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getDefaultOperations(EntityInterface $entity) {
  38. $operations = parent::getDefaultOperations($entity);
  39. // Place the edit operation after the operations added by field_ui.module
  40. // which have the weights 15, 20, 25.
  41. if (isset($operations['edit'])) {
  42. $operations['edit']['weight'] = 30;
  43. }
  44. return $operations;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function render() {
  50. $build = parent::render();
  51. $build['table']['#empty'] = $this->t('No content types available. <a href=":link">Add content type</a>.', [
  52. ':link' => Url::fromRoute('node.type_add')->toString(),
  53. ]);
  54. return $build;
  55. }
  56. }