jfu-1.0.x-dev/modules/jfu_usage/src/Form/JfuUsageSettingsForm.php
modules/jfu_usage/src/Form/JfuUsageSettingsForm.php
<?php
namespace Drupal\jfu_usage\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
* @package Drupal\jfu_usage\Form
*/
class JfuUsageSettingsForm extends ConfigFormBase {
/**
* Constructs a JfuUsageSettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}
/**
* {@inheritDoc}
*/
public function getFormId() {
return 'jfu_usage_settings';
}
/**
* {@inheritDoc}
*/
public function getEditableConfigNames() {
return ['jfu_usage.settings'];
}
/**
* {@inheritDoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config_jfu_usage = $this->config('jfu_usage.settings');
$rows_per_page = $config_jfu_usage->get('rows_per_page');
$form['rows_per_page'] = [
'#type' => 'number',
'#title' => $this->t('Rows per page'),
'#min' => 50,
'#max' => 200,
'#default_value' => isset($rows_per_page) ? $rows_per_page : '',
'#description' => $this->t('Sets the number of items for component pagination usage.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->config('jfu_usage.settings')
->set('rows_per_page', $form_state->getValue('rows_per_page'))
->save();
parent::submitForm($form, $form_state);
}
}
