AdminForm.php in UIkit Components 8.3
File
src/Form/AdminForm.php
View source
<?php
namespace Drupal\uikit_components\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\uikit_components\UIkitComponents;
class AdminForm extends ConfigFormBase {
public function getFormId() {
return 'uikit_components_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$config = $this
->config('uikit_components.settings');
$uikit_version = UIkitComponents::getUIkitLibraryVersion();
if ($uikit_version) {
$form['uikit_framework_version'] = [
'#type' => 'item',
'#title' => $this
->t('UIkit Framework Version'),
'#markup' => $uikit_version ? $uikit_version : $this
->t('The UIkit base theme is not installed.'),
];
$form['additional_menu_styles'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable configurable menu styles'),
'#description' => $this
->t('Enable selecting menu styles when adding and editing <a href="/admin/structure/menu">menus</a>. This provides three new menu templates: <em class="placeholder">menu--default.html.twig</em> as a default, <em class="placeholder">menu--uk-menu.html.twig</em> for uk-list and uk-subnav menus and <em class="placeholder">menu--uk-nav.html.twig</em> for uk-nav menus. This also ignores the admin toolbar and devel module menus so they can be rendered correctly.'),
'#default_value' => $config
->get('additional_menu_styles'),
];
}
return $form;
}
protected function getEditableConfigNames() {
return [
'uikit_components.settings',
];
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::service('config.factory')
->getEditable('uikit_components.settings');
$config
->set('additional_menu_styles', $form_state
->getValue('additional_menu_styles'))
->save();
drupal_flush_all_caches();
}
}
Classes
Name |
Description |
AdminForm |
Form builder for the UIkit Components administration form. |