6

So I've used form alter to add in a site information variable (which auto-saves because it's a system_settings_form), but I can't seem to get it to show up as multilingual.

Here is my form alter to add the field:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function omm_form_system_site_information_settings_alter ( &$form, &$form_state ) {
    // Add field in Site Information area of admin configuration.
    $form['site_information']['site_pretitle'] = array(
        '#type' => 'textfield',
        '#title' => t('Site Pre-Title'),
        '#description' => t('This will appear above the website name on all pages.'),
        '#default_value' => variable_get('site_pretitle', ''),
        '#weight' => '0',
    );
}

Edit: I've solved this already, but need 8 hours to post the solution because I'm new.

10

So I managed to solve this after searching through Drupal's code and the Variable module. Turns out if you add a call to hook_variable_info, it will add it into the multilingual variables list, and then if you check that off, it makes it translatable like the rest of the Site Information.

/**
 * Implements hook_variable_info().
 */
function omm_variable_info($options) {
  // Site configuration, site information
  $variables['site_pretitle'] = array(
    'type' => 'text',
    'title' => t('Site Pre-Title', array(), $options),
    'default' => '',
    'description' => t("This will appear above the website name on all pages.", array(), $options),
    'group' => 'site_information',
  );

  return $variables;
}

After adding this, go to admin/config/regional/i18n/variable and click on the Site information group. Click the checkmark beside your variable (site_pretitle for mine), and hit Save configuration. Once that's done, return to the Site Information area (admin/config/system/site-information) and you should see it appear and say This is a multilingual variable. in bold.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.