MiconMenuConfigForm.php in Micon 8
File
micon_menu/src/Form/MiconMenuConfigForm.php
View source
<?php
namespace Drupal\micon_menu\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\micon\Entity\Micon;
class MiconMenuConfigForm extends ConfigFormBase {
protected function getEditableConfigNames() {
return [
'micon_menu.config',
];
}
public function getFormId() {
return 'micon_menu_config_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('micon_menu.config');
$form['packages'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Icon Packages'),
'#description' => $this
->t('The icon packages that should be made available to menu items. If no packages are selected, all will be made available.'),
'#options' => Micon::loadActiveLabels(),
'#default_value' => $config
->get('packages'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('micon_menu.config')
->set('packages', $form_state
->getValue('packages'))
->save();
drupal_flush_all_caches();
}
}