note_ct-8.x-1.0/src/Form/ctNoteSettings.php

src/Form/ctNoteSettings.php
<?php

/**
 * This form provide date settings. If date in note >= date in settings batch by date will update status to Actual, else status will be update to Expired.
 */

/**
 * @file
 * Provides settings form to Note entity
 */
namespace Drupal\note_ct\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class note_settings_form
 * @package Drupal\note\Form
 */
class ctNoteSettings extends ConfigFormBase {

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

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'node.note_ct.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL) {
    $config = $this->config('node.note_ct.settings');

    $form['default_date'] = [
      '#type' => 'date',
      '#title' => t('Date'),
      '#default_value' => $config->get('date'),
      '#description' => 'This date is actually for select right status',
    ];


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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValues();
    $this->config('node.note_ct.settings')
      ->set('date', $values['default_date'])
      ->save();
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form, $form_state); // TODO: Change the autogenerated stub
  }
}

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

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