You are here

public function MailListController::listAll in Mail Editor 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/MailListController.php \Drupal\mail_edit\Controller\MailListController::listAll()

List the emails.

Return value

array A render array.

1 string reference to 'MailListController::listAll'
mail_edit.routing.yml in ./mail_edit.routing.yml
mail_edit.routing.yml

File

src/Controller/MailListController.php, line 21

Class

MailListController
List all of the emails that may be edited by the module.

Namespace

Drupal\mail_edit\Controller

Code

public function listAll() {
  $render = [
    '#theme' => 'table',
    '#attributes' => [],
    '#header' => [
      $this
        ->t('Module'),
      $this
        ->t('Description'),
      $this
        ->t('Length (characters)'),
      $this
        ->t('Actions'),
    ],
    '#rows' => [],
  ];

  // Build rows out of the templates.
  foreach ($this
    ->getAllTemplates() as $config_name => $templates) {
    $config_label = $config_name;
    if ($config_name == 'user.mail') {
      $config_label = t('Drupal core');
    }
    foreach ($templates as $name => $data) {
      $body_length = mb_strlen($data['body']);
      if ($body_length === 0) {
        $body_length = $this
          ->t('empty');
      }
      $args = [
        'id' => $config_name . '.' . $name,
      ];
      $render['#rows'][] = [
        $config_label,
        Xss::filter($data['description']),
        $body_length,
        Link::createFromRoute($this
          ->t('Edit'), 'mail_edit.edit', $args),
      ];
    }
  }
  return $render;
}