class ResponsiveMenusAdminForm in Responsive Menus 8
Class ResponsiveMenusAdminForm.
@package Drupal\responsive_menus\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\responsive_menus\Form\ResponsiveMenusAdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ResponsiveMenusAdminForm
1 string reference to 'ResponsiveMenusAdminForm'
File
- src/
Form/ ResponsiveMenusAdminForm.php, line 16
Namespace
Drupal\responsive_menus\FormView source
class ResponsiveMenusAdminForm extends ConfigFormBase {
/**
* The Responsive Menus plugin manager.
*
* @var \Drupal\responsive_menus\ResponsiveMenusPluginManager
*/
protected $pluginManager;
/**
* {@inheritdoc}
*/
public function __construct(ConfigFactoryInterface $config_factory, ResponsiveMenusPluginManager $plugin_manager) {
parent::__construct($config_factory);
$this->pluginManager = $plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('plugin.manager.responsive_menus'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'responsive_menus_admin_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'responsive_menus.configuration',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('responsive_menus.configuration');
// Gather enabled styles.
$styles = $this->pluginManager
->getDefinitions();
$style_options = [];
foreach ($styles as $style => $values) {
$style_options[$style] = $values['label'];
}
// Get style settings form elements from ajax or the currently enabled
// style.
$current_style = $config
->get('style');
if (!empty($form_state
->getValue('responsive_menus_style'))) {
$current_style = $form_state
->getValue('responsive_menus_style');
}
// Reminders about jQuery requirements if applicable.
// $form['responsive_menus_no_jquery_update'] = [
// '#type' => 'checkbox',
// '#title' => t('I will provide my own jQuery library.'),
// '#description' => t("If the style you want requires newer jQuery version and you don't want to use jquery_update module."),
// '#default_value' => $config->get('no_jquery_update'),
// ];
// Ignore admin pages option.
$form['responsive_menus_ignore_admin'] = [
'#type' => 'checkbox',
'#title' => 'Ignore admin pages?',
'#default_value' => $config
->get('ignore_admin'),
];
// $jq_update_ignore = $form['responsive_menus_no_jquery_update']['#default_value'];
// $style_info = responsive_menus_style_load($current_style, $jq_update_ignore);
$style_plugin = $this->pluginManager
->createInstance($current_style, [
'settings' => $config
->get('style_settings'),
]);
$form['responsive_menus_style'] = [
'#type' => 'select',
'#title' => $this
->t('Responsive menu style'),
'#options' => $style_options,
'#default_value' => $current_style,
'#ajax' => [
'callback' => '::ajax',
'wrapper' => 'rm-style-options',
'method' => 'replace',
'effect' => 'fade',
],
];
$form['responsive_menus_style_settings'] = [
'#title' => $this
->t('Style settings'),
'#description' => $this
->t('Settings for chosen menu style.'),
'#prefix' => '<div id="rm-style-options">',
'#suffix' => '</div>',
'#type' => 'detail',
'#tree' => TRUE,
];
// Which selector to use info.
if (!empty($style_plugin
->getSelectorInfo())) {
$form['responsive_menus_style_settings']['selector_info'] = [
'#type' => 'item',
'#title' => $this
->t('Selector(s) to use for this style:'),
'#markup' => '<div class="messages status">' . $style_plugin
->getSelectorInfo() . '</div>',
];
}
// Build additional style settings from style plugins.
foreach ($style_plugin
->settingsForm([], $form_state) as $name => $element) {
$form['responsive_menus_style_settings'][$name] = $element;
}
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save configuration'),
];
// if (!empty($_POST) && form_get_errors()) {
// drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
// }
return parent::buildForm($form, $form_state);
}
/**
* Ajax callback.
*
* @param array $form
* The settings form array.
* @param FormStateInterface $form_state
* The settings form state object.
*/
public function ajax(array &$form, FormStateInterface $form_state) {
return $form['responsive_menus_style_settings'];
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$this
->config('responsive_menus.configuration')
->set('style', $values['responsive_menus_style'])
->set('ignore_admin', $values['responsive_menus_ignore_admin'])
->set('style_settings', $values['responsive_menus_style_settings'])
->save();
// // Clear libraries cache if Sidr style in use to allow theme to be updated.
// if ($form_state['values']['responsive_menus_style'] == 'sidr') {
// cache_clear_all('*', 'cache_libraries', TRUE);
// }
$this
->messenger()
->addMessage($this
->t('The configuration options have been saved.'));
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
ResponsiveMenusAdminForm:: |
protected | property | The Responsive Menus plugin manager. | |
ResponsiveMenusAdminForm:: |
public | function | Ajax callback. | |
ResponsiveMenusAdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ResponsiveMenusAdminForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
ResponsiveMenusAdminForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ResponsiveMenusAdminForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ResponsiveMenusAdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ResponsiveMenusAdminForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |