AccordionMenusConfigForm.php in Accordion Menus 8
File
src/Form/AccordionMenusConfigForm.php
View source
<?php
namespace Drupal\accordion_menus\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class AccordionMenusConfigForm extends ConfigFormBase {
const SETTINGS = 'accordion_menus.settings';
public function getFormId() {
return 'accordion_menus_config_form';
}
protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config(static::SETTINGS);
$menus = menu_ui_get_menus();
$form['accordion_menus'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Accondion Menus'),
'#options' => $menus,
'#default_value' => $config
->get('accordion_menus'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable(static::SETTINGS)
->set('accordion_menus', $form_state
->getValue('accordion_menus'))
->save();
parent::submitForm($form, $form_state);
drupal_flush_all_caches();
}
}