easy_social-8.x-3.x-dev/src/Form/EmailSettingsForm.php

src/Form/EmailSettingsForm.php
<?php

namespace Drupal\easy_social\Form;

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

/**
 * Configure user settings for this site.
 */
final class EmailSettingsForm extends ConfigFormBase {

  /**
   * Config settings.
   *
   * @var string
   */
  private const SETTINGS = 'easy_social.email';

  /**
   * {@inheritdoc}
   */
  public function getFormId(): string {
    return 'easy_social_email';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames(): array {
    return [self::SETTINGS];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, $type = 'new'): array {
    $config = $this->config(self::SETTINGS);

    $form['button_label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Button label'),
      '#default_value' => $config->get('button_label'),
      '#description' => $this->t('The label shown on the page.'),
    ];

    $form['button_title'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Button Title'),
      '#default_value' => $config->get('button_title'),
      '#description' => $this->t('The button title which provides a tooltip.'),
    ];

    $form['subject'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Email Subject'),
      '#default_value' => $config->get('subject'),
      '#description' => $this->t('The subject of the email.'),
    ];

    $form['body'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Email Body'),
      '#default_value' => $config->get('body'),
      '#description' => $this->t('This is how the email will begin. A link to the page will be provided on the next line.'),
    ];

    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    parent::submitForm($form, $form_state);

    $config = $this->config(self::SETTINGS);

    $config->set('button_label', $form_state->getValue('button_label'))
      ->set('button_title', $form_state->getValue('button_title'))
      ->set('subject', $form_state->getValue('subject'))
      ->set('body', $form_state->getValue('body'))
      ->save();
  }

}

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

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