ContactFormListBuilder.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Drupal\contact;
  3. use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
  4. use Drupal\Core\Entity\EntityInterface;
  5. /**
  6. * Defines a class to build a listing of contact form entities.
  7. *
  8. * @see \Drupal\contact\Entity\ContactForm
  9. */
  10. class ContactFormListBuilder extends ConfigEntityListBuilder {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function buildHeader() {
  15. $header['form'] = t('Form');
  16. $header['recipients'] = t('Recipients');
  17. $header['selected'] = t('Selected');
  18. return $header + parent::buildHeader();
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function buildRow(EntityInterface $entity) {
  24. // Special case the personal form.
  25. if ($entity->id() == 'personal') {
  26. $row['form'] = $entity->label();
  27. $row['recipients'] = t('Selected user');
  28. $row['selected'] = t('No');
  29. }
  30. else {
  31. $row['form'] = $entity->link(NULL, 'canonical');
  32. $row['recipients']['data'] = [
  33. '#theme' => 'item_list',
  34. '#items' => $entity->getRecipients(),
  35. '#context' => ['list_style' => 'comma-list'],
  36. ];
  37. $default_form = \Drupal::config('contact.settings')->get('default_form');
  38. $row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No'));
  39. }
  40. return $row + parent::buildRow($entity);
  41. }
  42. }