From 77dec69a5a8580ed412fd0bb564116f073e21503 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 10 Dec 2013 13:56:39 +0000 Subject: [PATCH] =?UTF-8?q?Issue=20#2148797=20by=20G=C3=A1bor=20Hojtsy,=20?= =?UTF-8?q?yched,=20effulgentsia:=20field=5Flanguage()=20always=20NULL=20f?= =?UTF-8?q?or=20non-configurable=20fields=20(=3D>=20in-place=20editing=20o?= =?UTF-8?q?f=20node=20title=20fails).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/Drupal/edit/Tests/EditLoadingTest.php | 82 +++++++++++++++++++ core/modules/field/field.deprecated.inc | 9 +- 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php index 914c0e401af..c76ed8988e9 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditLoadingTest.php @@ -289,6 +289,88 @@ class EditLoadingTest extends WebTestBase { } } + /** + * Tests the loading of Edit for the title base field. + */ + public function testTitleBaseField() { + $this->drupalLogin($this->editor_user); + $this->drupalGet('node/1'); + + // Retrieving the metadata should result in a 200 JSON response. + $htmlPageDrupalSettings = $this->drupalSettings; + $post = array('fields[0]' => 'node/1/title/und/full'); + $response = $this->drupalPost('edit/metadata', 'application/json', $post); + $this->assertResponse(200); + $expected = array( + 'node/1/title/und/full' => array( + 'label' => 'Title', + 'access' => TRUE, + 'editor' => 'plain_text', + 'aria' => 'Entity node 1, field Title', + ) + ); + $this->assertIdentical(drupal_json_decode($response), $expected, 'The metadata HTTP request answers with the correct JSON response.'); + // Restore drupalSettings to build the next requests; simpletest wipes them + // after a JSON response. + $this->drupalSettings = $htmlPageDrupalSettings; + + // Retrieving the form for this field should result in a 200 response, + // containing only an editFieldForm command. + $post = array('nocssjs' => 'true', 'reset' => 'true') + $this->getAjaxPageStatePostData(); + $response = $this->drupalPost('edit/form/' . 'node/1/title/und/full', 'application/vnd.drupal-ajax', $post); + $this->assertResponse(200); + $ajax_commands = drupal_json_decode($response); + $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); + $this->assertIdentical('editFieldForm', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldForm command.'); + $this->assertIdentical('
assertTrue($form_tokens_found, 'Form tokens found in output.'); + + if ($form_tokens_found) { + $edit = array( + 'title[0][value]' => 'Obligatory question', + 'op' => t('Save'), + ); + $post = array( + 'form_id' => 'edit_field_form', + 'form_token' => $token_match[1], + 'form_build_id' => $build_id_match[1], + ); + $post += $edit + $this->getAjaxPageStatePostData(); + + // Submit field form and check response. This should store the + // updated entity in TempStore on the server. + $response = $this->drupalPost('edit/form/' . 'node/1/title/und/full', 'application/vnd.drupal-ajax', $post); + $this->assertResponse(200); + $ajax_commands = drupal_json_decode($response); + $this->assertIdentical(1, count($ajax_commands), 'The field form HTTP request results in one AJAX command.'); + $this->assertIdentical('editFieldFormSaved', $ajax_commands[0]['command'], 'The first AJAX command is an editFieldFormSaved command.'); + $this->assertTrue(strpos($ajax_commands[0]['data'], 'Obligatory question'), 'Form value saved and printed back.'); + + // Ensure the text on the original node did not change yet. + $this->drupalGet('node/1'); + $this->assertNoText('Obligatory question'); + + // Save the entity by moving the TempStore values to entity storage. + $post = array('nocssjs' => 'true'); + $response = $this->drupalPost('edit/entity/' . 'node/1', 'application/json', $post); + $this->assertResponse(200); + $ajax_commands = drupal_json_decode($response); + $this->assertIdentical(1, count($ajax_commands), 'The entity submission HTTP request results in one AJAX command.'); + $this->assertIdentical('editEntitySaved', $ajax_commands[0]['command'], 'The first AJAX command is an editEntitySaved command.'); + $this->assertIdentical($ajax_commands[0]['data']['entity_type'], 'node', 'Saved entity is of type node.'); + $this->assertIdentical($ajax_commands[0]['data']['entity_id'], '1', 'Entity id is 1.'); + + // Ensure the text on the original node did change. + $this->drupalGet('node/1'); + $this->assertText('Obligatory question'); + } + } + /** * Tests that Edit doesn't make pseudo fields or computed fields editable. */ diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index 9578f3d320c..abe5a375efe 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -895,18 +895,15 @@ function field_valid_language($langcode, $default = TRUE) { */ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = NULL) { $langcode = \Drupal::entityManager()->getTranslationFromContext($entity, $langcode)->language()->id; - $definitions = $entity->getPropertyDefinitions(); $translatable = field_has_translation_handler($entity->entityType()); if (!isset($field_name)) { $display_langcodes = array(); - foreach ($definitions as $name => $definition) { - if ($definition->isConfigurable()) { - $display_langcodes[$name] = $translatable ? $langcode : Language::LANGCODE_NOT_SPECIFIED; - } + foreach ($entity->getPropertyDefinitions() as $name => $definition) { + $display_langcodes[$name] = $translatable ? $langcode : Language::LANGCODE_NOT_SPECIFIED; } return $display_langcodes; } - elseif ($definitions[$field_name]->isConfigurable()) { + else { return $translatable ? $langcode : Language::LANGCODE_NOT_SPECIFIED; } }