On Multilingual settings (/admin/config/regional/i18n/variable) I have

Notice: Undefined index: title in variable_realm_select_variables_form() (line 32 of /var/www/--/--/sites/all/modules/variable/variable_realm/variable_realm.form.inc).

  • Variable Development version: 7.x-2.x-dev updated 11 Apr 2014
  • i18n Development version: 7.x-1.x-dev updated 2 Aug 2018
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Promo-IL created an issue. See original summary.

Promo-IL’s picture

Issue summary: View changes
apaderno’s picture

Issue tags: -variable_realm, -title, -i18n
apaderno’s picture

Version: 7.x-2.5 » 7.x-2.x-dev
Assigned: Promo-IL » Unassigned

The code causing the notice message is the following one.

  $variable_groups = variable_group_variables($list);
  foreach ($variable_groups as $group => $group_list) {
    $group_info = variable_get_group($group);
    $group_current = array_intersect($group_list, $current);
    $form['variables'][$group] = array(
      '#type' => 'fieldset',
      '#title' => $group_info['title'],  // <<< line 32
      '#theme' => 'variable_table_select',
      '#collapsible' => TRUE, '#collapsed' => TRUE,
    );
    foreach ($group_list as $name) {
      // Variable names may clash with form element names, so we need to replace '[' and ']'
      $safename = str_replace(array('[', ']'), array('<', '>'), $name);
      $form['variables'][$group][$safename] = array(
        '#type' => 'checkbox',
        '#default_value' => in_array($name, $group_current),
        '#variable_name' => $name,
        '#parents' => array('variables', $safename),
      );
    }
  }

Since the group title is not described as mandatory, but just as one of the possible values returned for a group, the code should use a default value, if the title is not given.

/**
 * Define groups of variables used by a module.
 *
 * Variable groups are used for presentation only, to display and edit the variables
 * on manageable groups. Groups can define a subset of a module's variables and can
 * be reused accross modules to group related variables.
 *
 * A form to edit all variables in a group can be generated with:
 *
 *   drupal_get_form('variable_group_form', group_name);
 *
 * @return
 *   An array of information defining variable types. The array contains
 *   a sub-array for each variable group, with the group as the key.
 *   Possible attributes:
 *   - "title": The human readable name of the group. Must be localized.
 *   - "description": The human readable description of the group. Must be localized.
 *   - "access": Permission required to edit group's variables. Will default to 'administer site configuration'.
 *   - "path": Array of administration paths where these variables can be accessed.
 *
 * @see hook_variable_group_info_alter()
 */
function hook_variable_group_info() {
  $groups['system_site_information'] = array(
    'title' => t('Site information'),
    'description' => t('Site information and maintenance mode'),
    'access' => 'administer site configuration',
    'path' => array('admin/config/system/site-information', 'admin/config/development/maintenance'),
  );
  $groups['system_feed_settings'] = array(
    'title' => t('Feed settings'),
    'description' => t('Feed settings'),
    'access' => 'administer site configuration',
  );
  return $groups;
}

Alternatively, the documentation should make clear the group title is required, and the code not setting it should be corrected.

I think the solution that is less disruptive for code already written is checking the title is set, and use a default value when it's not set.

  $variable_groups = variable_group_variables($list);
  foreach ($variable_groups as $group => $group_list) {
    $group_info = variable_get_group($group);
    $group_current = array_intersect($group_list, $current);
    $form['variables'][$group] = array(
      '#type' => 'fieldset',
      '#title' => !empty($group_info['title']) ? $group_info['title'] : $group,  // <<< line 32
      '#theme' => 'variable_table_select',
      '#collapsible' => TRUE, '#collapsed' => TRUE,
    );
    foreach ($group_list as $name) {
      // Variable names may clash with form element names, so we need to replace '[' and ']'
      $safename = str_replace(array('[', ']'), array('<', '>'), $name);
      $form['variables'][$group][$safename] = array(
        '#type' => 'checkbox',
        '#default_value' => in_array($name, $group_current),
        '#variable_name' => $name,
        '#parents' => array('variables', $safename),
      );
    }
  }
jigish.addweb’s picture

Status: Active » Needs review
FileSize
815 bytes

@Promo-IL, Please find a below-attached patch that resolves the notice error that added above. Kindly review it & share your feedback on the same.

Thanks

Dinesh18’s picture

#5 patch looks good to me. +1 to RTBC