2011-12-22 11:26:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Administration functions for language.module.
|
|
|
|
*/
|
|
|
|
|
2014-02-20 12:14:22 +00:00
|
|
|
use Drupal\Component\Utility\String;
|
2014-03-31 17:37:55 +00:00
|
|
|
use Drupal\Core\Render\Element;
|
2011-12-22 11:26:12 +00:00
|
|
|
|
2012-04-11 14:47:06 +00:00
|
|
|
/**
|
|
|
|
* Returns HTML for the language negotiation configuration form.
|
|
|
|
*
|
|
|
|
* @param $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - form: A render element representing the form.
|
|
|
|
*
|
|
|
|
* @ingroup themeable
|
|
|
|
*/
|
|
|
|
function theme_language_negotiation_configure_form($variables) {
|
|
|
|
$form = $variables['form'];
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
foreach ($form['#language_types'] as $type) {
|
|
|
|
$rows = array();
|
2014-03-04 16:16:14 +00:00
|
|
|
$title = '<h2>' . $form[$type]['#title'] . '</h2>';
|
2012-04-11 14:47:06 +00:00
|
|
|
$description = '<div class="description">' . $form[$type]['#description'] . '</div>';
|
|
|
|
|
|
|
|
foreach ($form[$type]['title'] as $id => $element) {
|
|
|
|
// Do not take form control structures.
|
2014-03-31 17:37:55 +00:00
|
|
|
if (is_array($element) && Element::child($id)) {
|
2012-04-11 14:47:06 +00:00
|
|
|
$row = array(
|
|
|
|
'data' => array(
|
|
|
|
'<strong>' . drupal_render($form[$type]['title'][$id]) . '</strong>',
|
|
|
|
drupal_render($form[$type]['description'][$id]),
|
|
|
|
drupal_render($form[$type]['enabled'][$id]),
|
|
|
|
drupal_render($form[$type]['weight'][$id]),
|
|
|
|
),
|
|
|
|
'class' => array('draggable'),
|
|
|
|
);
|
|
|
|
if ($form[$type]['#show_operations']) {
|
|
|
|
$row['data'][] = drupal_render($form[$type]['operation'][$id]);
|
|
|
|
}
|
|
|
|
$rows[] = $row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$header = array(
|
|
|
|
array('data' => t('Detection method')),
|
|
|
|
array('data' => t('Description')),
|
|
|
|
array('data' => t('Enabled')),
|
|
|
|
array('data' => t('Weight')),
|
|
|
|
);
|
|
|
|
|
|
|
|
// If there is at least one operation enabled show the operation column.
|
|
|
|
if ($form[$type]['#show_operations']) {
|
|
|
|
$header[] = array('data' => t('Operations'));
|
|
|
|
}
|
|
|
|
|
2013-06-09 17:53:24 +00:00
|
|
|
$build = array(
|
2013-12-20 12:05:47 +00:00
|
|
|
'#type' => 'table',
|
2013-06-09 17:53:24 +00:00
|
|
|
'#header' => $header,
|
|
|
|
'#rows' => $rows,
|
|
|
|
'#attributes' => array('id' => "language-negotiation-methods-$type"),
|
2013-12-20 12:05:47 +00:00
|
|
|
'#tabledrag' => array(
|
|
|
|
array(
|
|
|
|
'action' => 'order',
|
|
|
|
'relationship' => 'sibling',
|
|
|
|
'group' => "language-method-weight-$type",
|
|
|
|
),
|
|
|
|
),
|
2012-04-11 14:47:06 +00:00
|
|
|
);
|
2013-12-20 12:05:47 +00:00
|
|
|
|
2013-07-03 12:48:55 +00:00
|
|
|
$table = drupal_render($form[$type]['configurable']);
|
|
|
|
$table .= drupal_render($build);
|
2012-04-11 14:47:06 +00:00
|
|
|
$table .= drupal_render_children($form[$type]);
|
|
|
|
|
2013-07-03 12:48:55 +00:00
|
|
|
$output .= '<div class="form-item table-language-group table-' . $type . '-wrapper">' . $title . $description . $table . '</div>';
|
2012-04-11 14:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output .= drupal_render_children($form);
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2012-09-06 05:48:34 +00:00
|
|
|
/**
|
|
|
|
* Theme browser configuration form as table.
|
|
|
|
*
|
|
|
|
* @param $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - form: A render element representing the form.
|
|
|
|
*
|
|
|
|
* @ingroup themeable
|
|
|
|
*/
|
|
|
|
function theme_language_negotiation_configure_browser_form_table($variables) {
|
|
|
|
$form = $variables['form'];
|
|
|
|
$rows = array();
|
2014-03-31 17:37:55 +00:00
|
|
|
foreach (Element::children($form, TRUE) as $key) {
|
2012-09-06 05:48:34 +00:00
|
|
|
$row = array();
|
|
|
|
$row[] = drupal_render($form[$key]['browser_langcode']);
|
|
|
|
$row[] = drupal_render($form[$key]['drupal_langcode']);
|
2012-10-09 19:49:07 +00:00
|
|
|
$links = array();
|
|
|
|
$links['delete'] = array(
|
|
|
|
'title' => t('Delete'),
|
|
|
|
'href' => "admin/config/regional/language/detection/browser/delete/$key",
|
|
|
|
'attributes' => array(
|
|
|
|
'class' => array('image-style-link'),
|
|
|
|
),
|
2012-09-06 05:48:34 +00:00
|
|
|
);
|
2012-10-09 19:49:07 +00:00
|
|
|
$row[] = array(
|
|
|
|
'data' => array(
|
|
|
|
'#type' => 'operations',
|
|
|
|
'#links' => $links,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$rows[] = $row;
|
2012-09-06 05:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$header = array(
|
|
|
|
t('Browser language code'),
|
|
|
|
t('Drupal language'),
|
|
|
|
t('Operations'),
|
|
|
|
);
|
|
|
|
|
2013-06-09 17:53:24 +00:00
|
|
|
$table = array(
|
2014-03-12 15:46:33 +00:00
|
|
|
'#type' => 'table',
|
2013-06-09 17:53:24 +00:00
|
|
|
'#header' => $header,
|
|
|
|
'#rows' => $rows,
|
|
|
|
'#attributes' => array('id' => 'lang-neg-browser'),
|
|
|
|
);
|
|
|
|
$output = drupal_render($table);
|
2012-09-06 05:48:34 +00:00
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2012-12-29 08:13:54 +00:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_HOOK() for theme_language_content_settings_table().
|
|
|
|
*/
|
|
|
|
function template_preprocess_language_content_settings_table(&$variables) {
|
|
|
|
// Add a render element representing the bundle language settings table.
|
|
|
|
$element = $variables['element'];
|
|
|
|
|
|
|
|
$header = array(
|
|
|
|
array(
|
|
|
|
'data' => $element['#bundle_label'],
|
|
|
|
'class' => array('bundle'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'data' => t('Configuration'),
|
|
|
|
'class' => array('operations'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$rows = array();
|
2014-03-31 17:37:55 +00:00
|
|
|
foreach (Element::children($element) as $bundle) {
|
2012-12-29 08:13:54 +00:00
|
|
|
$rows[$bundle] = array(
|
|
|
|
'data' => array(
|
|
|
|
array(
|
|
|
|
'data' => array(
|
|
|
|
'#prefix' => '<label>',
|
|
|
|
'#suffix' => '</label>',
|
2014-02-20 12:14:22 +00:00
|
|
|
'#markup' => String::checkPlain($element[$bundle]['settings']['#label']),
|
2012-12-29 08:13:54 +00:00
|
|
|
),
|
|
|
|
'class' => array('bundle'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'data' => $element[$bundle]['settings'],
|
|
|
|
'class' => array('operations'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'class' => array('bundle-settings'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$variables['build'] = array(
|
|
|
|
'#title' => $element['#title'],
|
|
|
|
'#header' => $header,
|
|
|
|
'#rows' => $rows,
|
2014-03-12 15:46:33 +00:00
|
|
|
'#type' => 'table',
|
2012-12-29 08:13:54 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns HTML for an administration settings table.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - build: A render element representing a table of bundle content language
|
|
|
|
* settings for a particular entity type.
|
|
|
|
*
|
|
|
|
* @ingroup themable
|
|
|
|
*/
|
|
|
|
function theme_language_content_settings_table($variables) {
|
|
|
|
return '<h4>' . $variables['build']['#title'] . '</h4>' . drupal_render($variables['build']);
|
|
|
|
}
|
|
|
|
|
2013-07-03 12:48:55 +00:00
|
|
|
/**
|
|
|
|
* Helper function to disable the language switcher blocks.
|
|
|
|
*
|
|
|
|
* @param array $language_types
|
|
|
|
* Array containing all language types whose language switchers need to be
|
|
|
|
* disabled.
|
|
|
|
*/
|
|
|
|
function _language_disable_language_switcher(array $language_types) {
|
|
|
|
$blocks = _block_rehash();
|
|
|
|
foreach ($language_types as $language_type) {
|
|
|
|
foreach ($blocks as $block) {
|
|
|
|
if (strpos($block->id, 'language_switcher_' . substr($language_type, 9)) !== FALSE) {
|
|
|
|
$block->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|