class IgnoredModulesForm in Nagios Monitoring 8
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\nagios\Form\IgnoredModulesForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of IgnoredModulesForm
1 string reference to 'IgnoredModulesForm'
File
- src/
Form/ IgnoredModulesForm.php, line 13
Namespace
Drupal\nagios\FormView source
class IgnoredModulesForm extends ConfigFormBase {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a ModulesListForm object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
*/
public function __construct(ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
$this->moduleHandler = $module_handler;
parent::__construct($config_factory);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
/** @noinspection PhpParamsInspection */
return new static($container
->get('module_handler'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'nagios_ignored_modules';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'nagios.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('nagios.settings');
$enabled = TRUE;
$settings_url = Url::fromRoute('nagios.settings')
->toString();
// Is the nagios module itself disabled?
$nagios_hooks_enabled = $config
->get('nagios.enable.nagios') ?? TRUE;
if (!$nagios_hooks_enabled) {
\Drupal::messenger()
->addMessage($this
->t('These settings are not available, because the nagios module is not enabled within the <a href="@nagios-settings">nagios settings</a>.', [
'@nagios-settings' => $settings_url,
]), 'warning');
$enabled = FALSE;
}
// Is "Checking of hook_requirements." disabled?
if (!$config
->get('nagios.function.requirements')) {
\Drupal::messenger()
->addMessage($this
->t('These settings are not available, because the requirements check is not enabled within the <a href="@nagios-settings">nagios settings</a>.', [
'@nagios-settings' => $settings_url,
]), 'warning');
$enabled = FALSE;
}
$this
->addDescription($form);
$this
->buildTable($form, $enabled);
$form = parent::buildForm($form, $form_state);
if (!$enabled) {
$form['actions']['submit']['#disabled'] = TRUE;
}
return $form;
}
/**
* Build the list of modules
*
* @param array $form
* An associative array containing the structure of the form.
*/
protected function addDescription(array &$form) {
$form['intro'] = [
'#markup' => $this
->t('Select those modules that should be ignored for requirement checks.'),
];
}
/**
* Build the list of modules
*
* @param array $form
* An associative array containing the structure of the form.
* @param boolean $enabled
* Enable the check boxes
*/
protected function buildTable(array &$form, $enabled) {
$config = $this
->config('nagios.settings');
$header = [
'title' => $this
->t('Title'),
'description' => $this
->t('Description'),
];
$options = [];
// Include system.admin.inc so we can use the sort callbacks.
$this->moduleHandler
->loadInclude('system', 'inc', 'system.admin');
// Sort all modules by their names.
$modules = \Drupal::service('extension.list.module')
->getList();
uasort($modules, 'system_sort_modules_by_info_name');
// Build the rows
foreach ($modules as $filename => $module) {
if (empty($module->info['hidden'])) {
$options[$filename] = $this
->buildRow($module);
$options[$filename]['#disabled'] = TRUE;
}
}
// Set up the check boxes
$defaults = [];
$nagios_ignored_modules = $config
->get('nagios.ignored_modules') ?: [];
foreach ($nagios_ignored_modules as $ignored_module) {
$defaults[$ignored_module] = 1;
}
$form['modules'] = [
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => $this
->t('No modules available.'),
'#default_value' => $defaults,
];
if (!$enabled) {
foreach ($form['modules']['#options'] as $key => $value) {
$form['modules']['#options']['#disabled'] = TRUE;
}
}
}
/**
* Build one row in the list of modules
*
* @param Extension $module
* The module that the row is build for
*
* @return array
* The row data for the table select element
*/
protected function buildRow(Extension $module) {
$row = [];
$row['title'] = $module->info['name'];
$row['description'] = $this
->t($module->info['description']);
return $row;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('nagios.settings');
$ignored_modules = array_keys(array_filter($form_state
->getValue('modules')));
$config
->set('nagios.ignored_modules', $ignored_modules);
$config
->save();
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 |
IgnoredModulesForm:: |
protected | property | The module handler service. | |
IgnoredModulesForm:: |
protected | function | Build the list of modules | |
IgnoredModulesForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
IgnoredModulesForm:: |
protected | function | Build one row in the list of modules | |
IgnoredModulesForm:: |
protected | function | Build the list of modules | |
IgnoredModulesForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
IgnoredModulesForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
IgnoredModulesForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
IgnoredModulesForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
IgnoredModulesForm:: |
public | function |
Constructs a ModulesListForm object. Overrides ConfigFormBase:: |
|
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. | |
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. |