You are here

public function ScheduleEmailWebformHandler::getSummary in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_scheduled_email/src/Plugin/WebformHandler/ScheduleEmailWebformHandler.php \Drupal\webform_scheduled_email\Plugin\WebformHandler\ScheduleEmailWebformHandler::getSummary()

Returns a render array summarizing the configuration of the webform handler.

Return value

array A render array.

Overrides EmailWebformHandler::getSummary

File

modules/webform_scheduled_email/src/Plugin/WebformHandler/ScheduleEmailWebformHandler.php, line 46

Class

ScheduleEmailWebformHandler
Schedules a webform submission's email.

Namespace

Drupal\webform_scheduled_email\Plugin\WebformHandler

Code

public function getSummary() {

  /** @var \Drupal\webform_scheduled_email\WebformScheduledEmailManagerInterface $webform_scheduled_email_manager */
  $webform_scheduled_email_manager = \Drupal::service('webform_scheduled_email.manager');
  $status_messages = [
    WebformScheduledEmailManagerInterface::SUBMISSION_WAITING => [
      'message' => $this
        ->t('waiting to be scheduled.'),
      'type' => 'warning',
    ],
    WebformScheduledEmailManagerInterface::SUBMISSION_QUEUED => [
      'message' => $this
        ->t('queued to be sent.'),
      'type' => 'status',
    ],
    WebformScheduledEmailManagerInterface::SUBMISSION_READY => [
      'message' => $this
        ->t('ready to be sent.'),
      'type' => 'warning',
    ],
  ];
  $cron_link = FALSE;
  $build = [];
  $stats = $webform_scheduled_email_manager
    ->stats($this->webform, $this
    ->getHandlerId());
  foreach ($stats as $type => $total) {
    if (empty($total) || !isset($status_messages[$type])) {
      continue;
    }
    $build[$type] = [
      '#type' => 'webform_message',
      '#message_message' => $this
        ->formatPlural($total, '@total email @message', '@total emails @message', [
        '@total' => $total,
        '@message' => $status_messages[$type]['message'],
      ]),
      '#message_type' => $status_messages[$type]['type'],
    ];
    if ($status_messages[$type]['type'] === 'warning') {
      $cron_link = TRUE;
    }
  }

  // Display execute cron link.
  if ($cron_link) {
    $build['link'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Run cron task'),
      '#url' => Url::fromRoute('entity.webform.scheduled_email.cron', [
        'webform' => $this
          ->getWebform()
          ->id(),
        'handler_id' => $this
          ->getHandlerId(),
      ]),
      '#attributes' => [
        'class' => [
          'button',
          'button--small',
        ],
      ],
      '#prefix' => '<p>',
      '#suffix' => '</p>',
    ];
  }
  $summary = parent::getSummary();
  if ($build) {
    $summary['#status'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Scheduled email status (@total)', [
        '@total' => $stats['total'],
      ]),
      '#help' => FALSE,
      '#description' => $build,
    ];
  }
  return $summary;
}