diff --git a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php index 68ba897..3995605 100644 --- a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php +++ b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php @@ -138,9 +138,8 @@ public function render($row) { $output = array(); foreach ($this->view->field as $id => $field) { - // If this is not unknown and the raw output option has been set, just get - // the raw value. - if (($field->field_alias != 'unknown') && !empty($this->rawOutputOptions[$id])) { + // If the raw output option has been set, just get the raw value. + if (!empty($this->rawOutputOptions[$id])) { $value = $field->sanitizeValue($field->getValue($row), 'xss_admin'); } // Otherwise, pass this through the field advancedRender() method. diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php index 5f378ee..8afdfb7 100644 --- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php @@ -545,6 +545,25 @@ public function testFieldapiField() { $result = $this->drupalGetJSON('test/serialize/node-field'); $this->assertEqual($result[1]['nid'], $node->id()); $this->assertTrue(strpos($this->getRawContent(), "drupalLogin($this->adminUser); + + // Add an alias and make the output raw. + $row_options = 'admin/structure/views/nojs/display/test_serializer_node_display_field/rest_export_1/row_options'; + + // Test an empty string for an alias, this should not be used. This also + // tests that the form can be submitted with no aliases. + $this->drupalPostForm($row_options, ['row_options[field_options][title][raw_output]' => '1'], t('Apply')); + $this->drupalPostForm(NULL, [], t('Save')); + + $view = Views::getView('test_serializer_node_display_field'); + $view->setDisplay('rest_export_1'); + $this->executeView($view); + + // Test the raw 'created' value against each row. + foreach ($this->drupalGetJSON('test/serialize/node-field') as $index => $values) { + $this->assertIdentical($values['title'], $view->result[$index]->_entity->title->value, 'Expected raw title value found.'); + } } /** diff --git a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_display_field.yml b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_display_field.yml index ab50920..3bfe97c 100644 --- a/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_display_field.yml +++ b/core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_node_display_field.yml @@ -46,6 +46,26 @@ display: plugin_id: field entity_type: node entity_field: nid + title: + id: title + table: node_field_data + field: title + label: Title + exclude: false + alter: + alter_text: false + element_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + entity_type: node + entity_field: title + type: string + settings: + link_to_entity: true + plugin_id: field body: id: body table: node__body diff --git a/core/modules/views/src/Plugin/views/field/Field.php b/core/modules/views/src/Plugin/views/field/Field.php index 33253d1..c9ab37a 100644 --- a/core/modules/views/src/Plugin/views/field/Field.php +++ b/core/modules/views/src/Plugin/views/field/Field.php @@ -242,8 +242,11 @@ public function query($use_groupby = FALSE) { // Go through the list and determine the actual column name from field api. $fields = array(); + $table_mapping = $this->getTableMapping(); + $field_definition = $this->getFieldStorageDefinition(); + foreach ($options as $column) { - $fields[$column] = $this->getTableMapping()->getFieldColumnName($this->getFieldStorageDefinition(), $column); + $fields[$column] = $table_mapping->getFieldColumnName($field_definition, $column); } $this->group_fields = $fields;