function template_preprocess_language_negotiation_configure_form
Same name in other branches
- 9 core/modules/language/language.admin.inc \template_preprocess_language_negotiation_configure_form()
- 8.9.x core/modules/language/language.admin.inc \template_preprocess_language_negotiation_configure_form()
- 11.x core/modules/language/language.admin.inc \template_preprocess_language_negotiation_configure_form()
Prepares variables for language negotiation configuration form.
Default template: language-content-configuration-form.html.twig.
Parameters
array $variables: An associative array containing:
- form: A render element representing the form.
File
-
core/
modules/ language/ language.admin.inc, line 20
Code
function template_preprocess_language_negotiation_configure_form(&$variables) {
$form =& $variables['form'];
$variables['language_types'] = [];
foreach ($form['#language_types'] as $type) {
$header = [
t('Detection method'),
t('Description'),
t('Enabled'),
t('Weight'),
];
// If there is at least one operation enabled show the operation column.
if ($form[$type]['#show_operations']) {
$header[] = t('Operations');
}
$table = [
'#type' => 'table',
'#header' => $header,
'#attributes' => [
'id' => 'language-negotiation-methods-' . $type,
],
'#tabledrag' => [
[
'action' => 'order',
'relationship' => 'sibling',
'group' => 'language-method-weight-' . $type,
],
],
];
foreach ($form[$type]['title'] as $id => $element) {
// Do not take form control structures.
if (is_array($element) && Element::child($id)) {
$table[$id]['#attributes']['class'][] = 'draggable';
$table[$id]['#weight'] = $element['#weight'];
$table[$id]['title'] = [
'#prefix' => '<strong>',
$form[$type]['title'][$id],
'#suffix' => '</strong>',
];
$table[$id]['description'] = $form[$type]['description'][$id];
$table[$id]['enabled'] = $form[$type]['enabled'][$id];
$table[$id]['weight'] = $form[$type]['weight'][$id];
if ($form[$type]['#show_operations']) {
$table[$id]['operation'] = $form[$type]['operation'][$id];
}
// Unset to prevent rendering along with children.
unset($form[$type]['title'][$id]);
unset($form[$type]['description'][$id]);
unset($form[$type]['enabled'][$id]);
unset($form[$type]['weight'][$id]);
unset($form[$type]['operation'][$id]);
}
}
// Unset configurable to prevent rendering twice with children.
$configurable = $form[$type]['configurable'] ?? NULL;
unset($form[$type]['configurable']);
$variables['language_types'][] = [
'type' => $type,
'title' => $form[$type]['#title'],
'description' => $form[$type]['#description'],
'configurable' => $configurable,
'table' => $table,
'children' => $form[$type],
'attributes' => new Attribute(),
];
// Prevent the type from rendering with the remaining form child elements.
unset($form[$type]);
}
$variables['children'] = $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.