SmartmenusSettingsForm.php in Smartmenus.js 8
File
src/Form/SmartmenusSettingsForm.php
View source
<?php
namespace Drupal\smartmenus\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\smartmenus\SmartmenusUtil;
class SmartmenusSettingsForm extends ConfigFormBase {
protected $smartmenusUtil;
public function __construct(ConfigFactoryInterface $config_factory, SmartmenusUtil $smartmenusUtil) {
parent::__construct($config_factory);
$this->smartmenusUtil = $smartmenusUtil;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('smartmenus.util'));
}
protected function getEditableConfigNames() {
return [
$this->smartmenusUtil
->getConfigFormSettingsName(),
];
}
public function getFormId() {
return 'smartmenus_settings_form';
}
public function getThemeOptions() {
return $this->smartmenusUtil
->getAvailableMenuThemesList();
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config($this->smartmenusUtil
->getConfigFormSettingsName());
$form['container'] = array(
'#type' => 'fieldset',
'#title' => $this
->t('Smartmenus Settings'),
);
$form['container']['smartmenus_theme'] = array(
'#type' => 'select',
'#title' => $this
->t('Smart menus theme'),
'#options' => $this
->getThemeOptions(),
'#default_value' => $config
->get('smartmenus_theme'),
'#required' => true,
);
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config($this->smartmenusUtil
->getConfigFormSettingsName())
->set('smartmenus_theme', $form_state
->getValue('smartmenus_theme'))
->save();
}
}