You are here

AdminSettings.php in jEditable inline content editing 8

File

src/Form/AdminSettings.php
View source
<?php

namespace Drupal\jeditable\Form;

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

/**
 * Class AdminSettings.
 *
 * @package Drupal\jeditable\Form
 */
class AdminSettings extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['jeditable_empty_placeholder'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Empty field placeholder'),
      '#default_value' => $this
        ->config('jeditable.settings')
        ->get('jeditable_empty_placeholder'),
      '#description' => $this
        ->t('Text, that will be shown if field is empty'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('jeditable.settings');
    foreach (Element::children($form) as $variable) {
      $config
        ->set($variable, $form_state
        ->getValue($form[$variable]['#parents']));
    }
    $config
      ->save();
    if (method_exists($this, '_submitForm')) {
      $this
        ->_submitForm($form, $form_state);
    }
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
AdminSettings Class AdminSettings.