Issue #2148797 by Gábor Hojtsy, yched, effulgentsia: field_language() always NULL for non-configurable fields (=> in-place editing of node title fails).
parent
51e320178e
commit
77dec69a5a
|
@ -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('<form ', Unicode::substr($ajax_commands[0]['data'], 0, 6), 'The editFieldForm command contains a form.');
|
||||
|
||||
// Prepare form values for submission. drupalPostAjaxForm() is not suitable
|
||||
// for handling pages with JSON responses, so we need our own solution
|
||||
// here.
|
||||
$form_tokens_found = preg_match('/\sname="form_token" value="([^"]+)"/', $ajax_commands[0]['data'], $token_match) && preg_match('/\sname="form_build_id" value="([^"]+)"/', $ajax_commands[0]['data'], $build_id_match);
|
||||
$this->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.
|
||||
*/
|
||||
|
|
|
@ -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()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue