amazon_ses-2.0.x-dev/src/Form/AmazonSesIdentitiesForm.php

src/Form/AmazonSesIdentitiesForm.php
<?php

namespace Drupal\amazon_ses\Form;

use Drupal\Core\Form\FormStateInterface;

/**
 * Amazon SES verified identities form.
 */
class AmazonSesIdentitiesForm extends AmazonSesFormBase {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'amazonses_identities_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    if (!$this->handler->verifyClient()) {
      $this->messenger()->addError($this->t('Unable to initialize the SES
        client. More information may be available in the log.'));

      return $form;
    }

    $form['action'] = [
      '#type' => 'select',
      '#title' => $this->t('Action'),
      '#options' => ['delete' => $this->t('Delete')],
    ];

    $header = [
      'identity' => $this->t('Identity'),
      'type' => $this->t('Type'),
      'dkim' => $this->t('DKIM Signing'),
      'status' => $this->t('Status'),
    ];

    $options = [];
    $identities = $this->handler->getIdentities();

    foreach ($identities as $identity) {
      $options[$identity['identity']] = [
        'identity' => $identity['identity'],
        'type' => $identity['type'],
        'dkim' => $identity['dkim'],
        'status' => $identity['status'],
      ];
    }

    $form['identities'] = [
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#empty' => $this->t('There are no verified identities.'),
    ];

    $form['actions'] = [
      '#type' => 'actions',
      'submit' => [
        '#type' => 'submit',
        '#value' => $this->t('Apply to selected items'),
      ],
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $action = $form_state->getValue('action');

    if ($action == 'delete') {
      $identities = array_filter($form_state->getValue('identities'));

      foreach ($identities as $identity) {
        $this->handler->deleteIdentity($identity);
      }
    }

    $this->messenger()->addMessage($this->t('The identities have been deleted.'));
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc