tiny_file_manager-1.0.x-dev/src/Form/ConfigForm.php

src/Form/ConfigForm.php
<?php

namespace Drupal\tiny_file_manager\Form;

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


/**
 * Class YourConfigForm.
 *
 * @package Drupal\your_module\Form
 */
class ConfigForm extends ConfigFormBase {

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

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

  /**
   * Form submission handler.
   *
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $values = $form_state->getValues();

    if (isset($values['default_root_path'])) {
      $this->config('tiny_file_manager.settings')->set('default_root_path', $values['default_root_path'])->save();
    }
  }

  /**
   * Defines the form elements for your configuration form.
   *
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\Core\Site\Settings $settings */
    $settings = \Drupal::service("settings");

    $config = $this->config('tiny_file_manager.settings');

    $form['default_root_path'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Root directory'),
      '#default_value' => $config->get('default_root_path'),
      '#description' => $this->t('Set the default root directory for the file manager. It should be a relative path to the Drupal root directory.'),
      '#attributes' => [
        'placeholder' => $settings->get('file_public_path', 'sites/default/files'),
      ]
    ];

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

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

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