Commit 2952d3e2 authored by webchick's avatar webchick

Issue #1757504 by Maxtorete, boran, c31ck, Gábor Hojtsy: Fixed Regression:...

Issue #1757504 by Maxtorete, boran, c31ck, Gábor Hojtsy: Fixed Regression: language field is not visible on manage display.
parent a12dc7e8
......@@ -33,6 +33,8 @@
* - label: The human readable name of the component.
* - description: A short description of the component contents.
* - weight: The default weight of the element.
* - visible: The default visibility of the element. Only for 'display'
* context.
*/
function hook_field_extra_fields() {
$extra['node']['poll'] = array(
......
......@@ -431,6 +431,7 @@ function _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle)
$data = $extra_fields['display'];
foreach ($extra_fields['display'] as $name => $field_data) {
$settings = isset($bundle_settings['extra_fields']['display'][$name]) ? $bundle_settings['extra_fields']['display'][$name] : array();
$field_data['visible'] = isset($field_data['visible']) ? $field_data['visible'] : TRUE;
$view_modes = array_merge(array('default'), array_keys($entity_type_info['view modes']));
foreach ($view_modes as $view_mode) {
if (isset($settings[$view_mode])) {
......@@ -439,7 +440,7 @@ function _field_info_prepare_extra_fields($extra_fields, $entity_type, $bundle)
else {
$field_data['display'][$view_mode] = array(
'weight' => $field_data['weight'],
'visible' => TRUE,
'visible' => $field_data['visible'],
);
}
}
......
......@@ -78,6 +78,13 @@ function testNodeTypeInitialLanguageDefaults() {
$language_field = $this->xpath('//*[@id="language"]');
$this->assert(!empty($language_field), 'Language field is visible on manage fields tab.');
// Tests if the language field can be rearranged on the manage display tab.
$this->drupalGet('admin/structure/types/manage/article/display');
$language_display = $this->xpath('//*[@id="language"]');
$this->assert(!empty($language_display), 'Language field is visible on manage display tab.');
// Tests if the language field is hidden by default.
$this->assertOptionSelected('edit-fields-language-type', 'hidden', 'Language is hidden by default on manage display tab.');
// Changes the inital language settings.
$edit = array(
'node_type_language_default' => 'en',
......@@ -86,4 +93,42 @@ function testNodeTypeInitialLanguageDefaults() {
$this->drupalGet('node/add/article');
$this->assertOptionSelected('edit-langcode', 'en', 'The inital language is the defined language.');
}
/**
* Tests Language field visibility features.
*/
function testLanguageFieldVisibility() {
$langcode = LANGUAGE_NOT_SPECIFIED;
// Creates a node to test Language field visibility feature.
$edit = array(
'title' => $this->randomName(8),
"body[$langcode][0][value]" => $this->randomName(16),
);
$this->drupalPost('node/add/article', $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title']);
$this->assertTrue($node, 'Node found in database.');
// Loads node page and check if Language field is hidden by default.
$this->drupalGet('node/' . $node->nid);
$language_field = $this->xpath('//div[@id=:id]/div', array(
':id' => 'field-language-display',
));
$this->assertTrue(empty($language_field), 'Language field value is not shown by default on node page.');
// Changes Language field visibility to true and check if it is saved.
$edit = array(
'fields[language][type]' => 'visible',
);
$this->drupalPost('admin/structure/types/manage/article/display', $edit, t('Save'));
$this->drupalGet('admin/structure/types/manage/article/display');
$this->assertOptionSelected('edit-fields-language-type', 'visible', 'Language field has been set to visible.');
// Loads node page and check if Language field is shown.
$this->drupalGet('node/' . $node->nid);
$language_field = $this->xpath('//div[@id=:id]/div', array(
':id' => 'field-language-display',
));
$this->assertFalse(empty($language_field), 'Language field value is shown on node page.');
}
}
......@@ -678,13 +678,21 @@ function node_field_extra_fields() {
// Add also the 'language' select if Language module is enabled and the
// bundle has multilingual support.
// Visibility of the ordering of the language selector is the same as on the node/add form,
// i.e. node_type_language_hidden_TYPE variable
if ($module_language_enabled && !variable_get('node_type_language_hidden_' . $bundle->type, TRUE)) {
$extra['node'][$bundle->type]['form']['language'] = array(
// Visibility of the ordering of the language selector is the same as on the
// node/add form, i.e. node_type_language_hidden_TYPE variable.
if ($module_language_enabled) {
if (!variable_get('node_type_language_hidden_' . $bundle->type, TRUE)) {
$extra['node'][$bundle->type]['form']['language'] = array(
'label' => t('Language'),
'description' => $description,
'weight' => 0,
);
}
$extra['node'][$bundle->type]['display']['language'] = array(
'label' => t('Language'),
'description' => $description,
'weight' => 0,
'visible' => FALSE,
);
}
}
......@@ -1167,6 +1175,18 @@ function node_view(Node $node, $view_mode = 'full', $langcode = NULL) {
// Populate $node->content with a render() array.
node_build_content($node, $view_mode, $langcode);
// Add language text element on node view if language module is enabled.
if (module_exists('language')) {
$node->content['language'] = array(
'#type' => 'item',
'#title' => t('Language'),
'#markup' => language_name($langcode),
'#weight' => 0,
'#prefix' => '<div id="field-language-display">',
'#suffix' => '</div>'
);
}
$build = $node->content;
// We don't need duplicate rendering info in node->content.
unset($node->content);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment