我想改变我的复选框

时间:2015-05-11 08:02:41

标签: php drupal checkbox drupal-7 watchdog

我这里有一些带有watchdog_severity值的复选框:

    // Form for the severity checkboxes.
    $blabla_severity_levels = variable_get('blabla_severity_levels', array());

    // Declare empty options array.
    $blabla_severity_options = array();

    // Loop through each severity level and push to options array for form.
    foreach (watchdog_severity_levels() as $number_select => $severity) {
      $blabla_severity_options[$severity] = check_plain(drupal_ucfirst(
        $severity));
    }

    // Generate checkbox list for given severity levels.
    $blabla_form['blabla_severity'] = array(
      '#type'        => 'fieldset',
      '#title'       => t('Select the severity.'),
      '#collapsible' => TRUE,
      '#collapsed'   => TRUE,
    );

    $blabla_form['blabla_severity']['blabla_severity_levels'] = array(
      '#type'          => 'checkboxes',
      '#title'         => t('Type of log messages'),
      '#options'       => $blabla_severity_options,
      '#default_value' => array_values($blabla_severity_levels),
      '#required'      => TRUE,
    );

    return system_settings_form($blabla_form);

好的,现在我在我的函数中调用severity_levels:

function blabla_check_checkboxes() {
  $severity_levels = variable_get('blabla_severity_levels', array());
}

现在,如果仅选择信息复选框并导出$severity_levels的值,它会让我得到这样的信息:

    info (String, 4 characters ) info
    emergency (Integer) 0
    alert (Integer) 0
    critical (Integer) 0
    error (Integer) 0
    warning (Integer) 0
    notice (Integer) 0
    debug (Integer) 0

但我希望在我的函数blabla_check_checkboxes()中导出类似的内容:

        info (Integer) 6
        emergency (Integer) 0
        alert (Integer) 0
        critical (Integer) 0
        error (Integer) 0
        warning (Integer) 0
        notice (Integer) 0
        debug (Integer) 0

其中6是drupal严重性信息的编号... 有人可以帮助解决这个问题吗?

2 个答案:

答案 0 :(得分:1)

解决方案可能是修改您的函数以返回所需的结构:

function blabla_check_checkboxes() {
  $orig_severity_levels = watchdog_severity_levels();
  $blabla_severity_levels = variable_get('blabla_severity_levels', array());
  foreach ($blabla_severity_levels as $level => $name) {
    if ((int) $name) {
      $blabla_severity_levels[$level] = $orig_severity_levels[$level];
    }
  }
  return $blabla_severity_levels;
}

答案 1 :(得分:0)

因为您正在使用system_settings_form_submit - 此功能将仅保存数组键。

您需要找到一个解决方法,例如使用其他提交功能或使用包装函数来检索此结构化数组。

在这种情况下,您尝试过度使用复选框初始范围。