MemcacheAdminSettingsForm.php in Memcache API and Integration 8.2
File
memcache_admin/src/Form/MemcacheAdminSettingsForm.php
View source
<?php
namespace Drupal\memcache_admin\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MemcacheAdminSettingsForm extends ConfigFormBase {
public function __construct(ConfigFactoryInterface $config_factory) {
parent::__construct($config_factory);
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'));
}
public function getFormId() {
return 'memcache_admin_admin_settings';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form['show_memcache_statistics'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show memcache statistics at the bottom of each page'),
'#default_value' => $this
->config('memcache_admin.settings')
->get('show_memcache_statistics'),
'#description' => $this
->t("These statistics will be visible to users with the 'access memcache statistics' permission."),
];
return parent::buildForm($form, $form_state);
}
public function getEditableConfigNames() {
return [
'memcache_admin.settings',
];
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('memcache_admin.settings')
->set('show_memcache_statistics', $form_state
->getValue('show_memcache_statistics'))
->save();
parent::submitForm($form, $form_state);
}
}