mailjet-8.x-2.7/src/Form/DomainSettingsForm.php

src/Form/DomainSettingsForm.php
<?php

namespace Drupal\mailjet\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * @package Drupal\mailjet\Form
 */
class DomainSettingsForm extends ConfigFormBase
{

  /**
   * @return string
   */
  public function getFormId() {
    return 'trusted_domain_form';
  }

  /**
   * @return mixed
   */
  protected function getEditableConfigNames() {
    return ['config.trusted_domains'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = [];
    $header = [
      'domain' => [
      'data' => t('Domain'),
      ],
      'enabled' => [
      'data' => t('Enabled'),
      ],
      'file_name' => [
      'data' => t('File Name'),
      ],
      ];

    $options = [];

    if ($domains = mailjet_user_domain_list()) {
      foreach ($domains as $domain) {
        if (is_object($domain['Email'])) {
          $email = $domain['Email']['Email'];
        }
        elseif (is_array($domain['Email'])) {
          $email = $domain['Email']['Email'];
        }
        if (empty($email)) {
          continue;
        }
        $email = str_replace('*@', '', $email);
        $options[$email] = [
          'domain' => $email,
          'enabled' => $domain['Status'],
          'file_name' => $domain['Filename'],
          ];
      }
    }

    $form['domains'] = [
      '#type' => 'tableselect',
      '#header' => $header,
      '#options' => $options,
      '#empty' => t('There are no authorized domains.'),
      ];

    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Check Status'),
      '#button_type' => 'primary',
      ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    foreach ($form_state->getValue('domains') as $domain) {
      if ($domain) {
        mailjet_user_domain_status($domain);
      }
    }
  }

}

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

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