You are here

SocialCommentUploadSettingsForm.php in Open Social 8.5

File

modules/social_features/social_comment_upload/src/Form/SocialCommentUploadSettingsForm.php
View source
<?php

namespace Drupal\social_comment_upload\Form;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class SocialCommentUploadSettingsForm.
 *
 * @package Drupal\social_comment_upload\Form
 */
class SocialCommentUploadSettingsForm extends ConfigFormBase implements ContainerInjectionInterface {

  /**
   * The Module Handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $moduleHandler) {
    parent::__construct($config_factory);
    $this->moduleHandler = $moduleHandler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.factory'), $container
      ->get('module_handler'));
  }

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

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

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

    // Get the configuration file.
    $config = $this
      ->config('social_comment_upload.settings');
    $form['allow_upload_comments'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Allow file uploads in comments.'),
      '#default_value' => $config
        ->get('allow_upload_comments'),
      '#required' => FALSE,
      '#description' => $this
        ->t("Determine wether users can upload documents to comments."),
    ];
    return parent::buildForm($form, $form_state);
  }

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

    // Get the configuration file.
    $config = $this
      ->config('social_comment_upload.settings');
    $config
      ->set('allow_upload_comments', $form_state
      ->getValue('allow_upload_comments'))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
SocialCommentUploadSettingsForm Class SocialCommentUploadSettingsForm.