summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-09-13 09:15:38 (GMT)
committerwebchick2012-09-13 09:15:38 (GMT)
commit2952d3e232601c9a34b09457ed6e62d97121045f (patch)
treef9fe78e5361cef29d6a0b908679fc03e0ac10467
parenta12dc7e8963f1d2a3ff5008064b799b46efbcba7 (diff)
Issue #1757504 by Maxtorete, boran, c31ck, Gábor Hojtsy: Fixed Regression: language field is not visible on manage display.
-rw-r--r--core/modules/field/field.api.php2
-rw-r--r--core/modules/field/field.info.inc3
-rw-r--r--core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php45
-rw-r--r--core/modules/node/node.module28
4 files changed, 73 insertions, 5 deletions
diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php
index a407c74..73c4a83 100644
--- a/core/modules/field/field.api.php
+++ b/core/modules/field/field.api.php
@@ -33,6 +33,8 @@ use Drupal\field\FieldUpdateForbiddenException;
* - 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(
diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc
index 0d00dbd..65c6bcc 100644
--- a/core/modules/field/field.info.inc
+++ b/core/modules/field/field.info.inc
@@ -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'],
);
}
}
diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php
index 3ba3fe6..e191eca 100644
--- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php
+++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php
@@ -78,6 +78,13 @@ class NodeTypeInitialLanguageTest extends NodeTestBase {
$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 @@ class NodeTypeInitialLanguageTest extends NodeTestBase {
$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.');
+ }
}
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 2d87534..bfba2fd 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -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);