public function LoggingConfigForm::buildForm in Purge 8.3
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
purge_ui/ src/ Form/ LoggingConfigForm.php, line 53
Class
- LoggingConfigForm
- Configure logging behavior.
Namespace
Drupal\purge_ui\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#attached']['library'][] = 'core/drupal.dialog.ajax';
$form['msg'] = [
'#prefix' => '<p>',
'#suffix' => '</p>',
'#markup' => $this
->t("Purge and modules that integrate with it bundle all log messages into a single channel named <i><code>purge</code></i>. This configuration form allows you to select what substreams and at which levels are allowed to log."),
];
// Define the table header.
$form['table'] = [
'#type' => 'table',
'#header' => [
'id' => $this
->t('Id'),
],
];
foreach (RfcLogLevel::getLevels() as $level => $label) {
$form['table']['#header']["{$level}"] = $label;
}
// Populate the rows and define checkboxes for each severity.
foreach ($this->purgeLogger
->getChannels() as $channel) {
$form['table'][$channel['id']] = [];
$form['table'][$channel['id']]['id'] = [
'#markup' => $channel['id'],
];
foreach (RfcLogLevel::getLevels() as $level => $label) {
$form['table'][$channel['id']][$level] = [
'#type' => 'checkbox',
'#default_value' => in_array($level, $channel['grants']),
];
}
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t("Save"),
'#weight' => -10,
'#button_type' => 'primary',
'#ajax' => [
'callback' => '::setChannels',
],
];
$form['actions']['cancel'] = [
'#type' => 'submit',
'#value' => $this
->t('Cancel'),
'#button_type' => 'danger',
'#ajax' => [
'callback' => '::closeDialog',
],
];
return $form;
}