1.20.x locale.admin.inc | language_negotiation_configure_form_table(&$form, $type) |
Helper function to build a language provider table.
File
- modules/
locale/ locale.admin.inc, line 39 - Admin page callbacks for the Locale module.
Code
function language_negotiation_configure_form_table(&$form, $type) {
$info = $form['#language_types_info'][$type];
$table_form = array(
'#title' => t('@type language detection', array('@type' => $info['name'])),
'#tree' => TRUE,
'#description' => $info['description'],
'#language_providers' => array(),
'#show_operations' => FALSE,
'weight' => array('#tree' => TRUE),
'enabled' => array('#tree' => TRUE),
);
$language_providers = $form['#language_providers'];
$enabled_providers = (array) config_get('language.settings', "language_negotiation.$type");
// Order providers list by weight.
foreach ($language_providers as $id => $provider) {
$set_weight = array_search($id, $enabled_providers);
$language_providers[$id]['set_weight'] = $set_weight !== FALSE ? $set_weight - 10 : 20;
}
// Put the default language at the bottom of the list.
$last_provider = end($enabled_providers);
if ($last_provider === LANGUAGE_NEGOTIATION_DEFAULT) {
$language_providers[$id]['set_weight'] = 21;
}
backdrop_sort($language_providers, array('set_weight' => SORT_NUMERIC, 'weight' => SORT_NUMERIC));
if ($last_provider === LANGUAGE_NEGOTIATION_DEFAULT) {
$language_providers[$id]['set_weight'] = 10;
}
foreach ($language_providers as $id => $provider) {
$enabled = in_array($id, $enabled_providers);
$provider = $language_providers[$id];
// List the provider only if the current type is defined in its 'types' key.
// If it is not defined default to all the configurable language types.
$types = array_flip(isset($provider['types']) ? $provider['types'] : $form['#language_types']);
if (isset($types[$type])) {
$table_form['#language_providers'][$id] = $provider;
$provider_name = check_plain($provider['name']);
$table_form[$id]['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight for !title language detection method', array('!title' => backdrop_strtolower($provider_name))),
'#title_display' => 'invisible',
'#default_value' => $provider['set_weight'] > 10 ? $provider['weight'] : $provider['set_weight'],
'#attributes' => array('class' => array("language-provider-weight-$type")),
);
$table_form[$id]['title'] = array('#markup' => $provider_name);
$table_form[$id]['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enable !title language detection method', array('!title' => backdrop_strtolower($provider_name))),
'#title_display' => 'invisible',
'#default_value' => $enabled,
);
if ($id === LANGUAGE_NEGOTIATION_DEFAULT) {
$table_form[$id]['enabled']['#default_value'] = TRUE;
$table_form[$id]['enabled']['#attributes'] = array('disabled' => 'disabled');
}
$table_form[$id]['description'] = array('#markup' => filter_xss_admin($provider['description']));
$config_op = array();
if (isset($provider['config'])) {
$config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $provider['config']);
// If there is at least one operation enabled show the operation column.
$table_form['#show_operations'] = TRUE;
}
$table_form[$id]['operation'] = $config_op;
}
}
$form[$type] = $table_form;
}