Not save "empty" array\data into dblog_filter.settings (on settings form submit)

Created on 9 July 2023, 12 months ago
Updated 10 July 2023, 12 months ago

It is necessary to maintain only useful data. Do not process dblogfilter.php with "empty" array\data.
In our case ($severity_levels = $config->get('severity_levels')... if (!empty($severity_levels[$level_array[$level]]))..)
(

[] == ["emergency" => 0, "alert" => 0, "critical" => 0, "error" => 0, "warning" => 0, "notice" => 0, "info" => 0, "debug" => 0]

)
dblog_filter\src\Form\DBLogFilterSettingsForm.php

  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Save configurations.
    $values = $form_state->getValues(); //dump($values);
    $config = $this->config('dblog_filter.settings');
    $fields = [
      'severity_levels',
      'log_values',
      'method',
      'syslog_severity_levels',
      'syslog_method',
    ];
    foreach ($fields as $field) {
      if (isset($values[$field])) {
/*-*/   //$config->set($field, $values[$field]);
/*+*/   $config->set($field, is_array($values[$field]) ? array_filter($values[$field], 'is_string') : $values[$field] ); /*Store if|in array only useful values (not 0)*/
      }
    }
    $config->save();
    parent::submitForm($form, $form_state);
  }

✨ Feature request
Status

Active

Version

3.2

Component

Code

Created by

🇮🇱Israel Promo-IL

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024