SimpleMobileMenuForm.php in Simple Mobile Menu 8.2
File
src/Form/SimpleMobileMenuForm.php
View source
<?php
namespace Drupal\simple_mobile_menu\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class SimpleMobileMenuForm extends ConfigFormBase {
public function getFormId() {
return 'simple_mobile_menu';
}
protected function getEditableConfigNames() {
return [
'simple_mobile_menu.settings',
];
}
public function buildForm(array $form, FormStateInterface $form_state) {
$simple_mobile_menu_config = $this
->config('simple_mobile_menu.settings');
$simple_menu = \Drupal::service('entity_type.manager')
->getStorage('menu')
->loadMultiple();
$options = [];
foreach ($simple_menu as $menus) {
$options[$menus
->id()] = $menus
->label();
}
$form['menu_name'] = [
'#type' => 'select',
'#options' => $options,
'#description' => t('<br/><em><b>Note:</b> To override the default css of simple mobile menu, please add below classes in your theme styles.css file and assign font, color etc. properties. <br/><b> main_menu, sub_menu </b></em>'),
'#default_value' => $simple_mobile_menu_config
->get('menu_name'),
'#title' => t('List of Available Menus'),
];
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('simple_mobile_menu.settings')
->set('menu_name', $form_state
->getValue('menu_name'))
->save();
parent::submitForm($form, $form_state);
$form['#theme'] = 'system_config_form';
}
}