ContactFormListBuilder.php 1.4 KB
Newer Older
1
2
3
<?php

/**
4
 * @file
5
 * Contains \Drupal\contact\ContactFormListBuilder.
6
7
8
9
 */

namespace Drupal\contact;

10
use Drupal\Component\Utility\SafeMarkup;
11
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
12
use Drupal\Core\Entity\EntityInterface;
13
use Drupal\Core\Link;
14
15

/**
16
 * Defines a class to build a listing of contact form entities.
17
 *
18
 * @see \Drupal\contact\Entity\ContactForm
19
 */
20
class ContactFormListBuilder extends ConfigEntityListBuilder {
21
22

  /**
23
   * {@inheritdoc}
24
25
   */
  public function buildHeader() {
26
    $header['form'] = t('Form');
27
28
29
    $header['recipients'] = t('Recipients');
    $header['selected'] = t('Selected');
    return $header + parent::buildHeader();
30
31
32
  }

  /**
33
   * {@inheritdoc}
34
35
   */
  public function buildRow(EntityInterface $entity) {
36
    // Special case the personal form.
37
    if ($entity->id() == 'personal') {
38
      $row['form'] = $this->getLabel($entity);
39
40
41
42
      $row['recipients'] = t('Selected user');
      $row['selected'] = t('No');
    }
    else {
43
      $row['form'] = $entity->link(NULL, 'canonical');
44
45
46
47
48
      $row['recipients']['data'] = [
        '#theme' => 'item_list',
        '#items' => $entity->getRecipients(),
        '#context' => ['list_style' => 'comma-list'],
      ];
49
50
      $default_form = \Drupal::config('contact.settings')->get('default_form');
      $row['selected'] = ($default_form == $entity->id() ? t('Yes') : t('No'));
51
    }
52
    return $row + parent::buildRow($entity);
53
54
55
  }

}