diff --git a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php index d9ed30a07c5..ef81b680d05 100644 --- a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php +++ b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php @@ -88,6 +88,10 @@ class DataFieldRow extends RowPluginBase { if ($fields = $this->view->display_handler->getOption('fields')) { foreach ($fields as $id => $field) { + // Don't show the field if it has been excluded. + if (!empty($field['exclude'])) { + continue; + } $form['field_options'][$id]['field'] = array( '#markup' => $id, ); @@ -138,6 +142,10 @@ class DataFieldRow extends RowPluginBase { $output = array(); foreach ($this->view->field as $id => $field) { + // Don't render anything if this field is excluded. + if (!empty($field->options['exclude'])) { + continue; + } // If the raw output option has been set, just get the raw value. if (!empty($this->rawOutputOptions[$id])) { $value = $field->getValue($row); diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php index b42da4218ac..b590504dc2e 100644 --- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php @@ -470,6 +470,32 @@ class StyleSerializerTest extends PluginTestBase { $this->assertIdentical($values['created'], $view->result[$index]->views_test_data_created, 'Expected raw created value found.'); $this->assertIdentical($values['name'], $view->result[$index]->views_test_data_name, 'Expected raw name value found.'); } + + // Test result with an excluded field. + $view->setDisplay('rest_export_1'); + $view->displayHandlers->get('rest_export_1')->overrideOption('fields', [ + 'name' => [ + 'id' => 'name', + 'table' => 'views_test_data', + 'field' => 'name', + 'relationship' => 'none', + ], + 'created' => [ + 'id' => 'created', + 'exclude' => TRUE, + 'table' => 'views_test_data', + 'field' => 'created', + 'relationship' => 'none', + ], + ]); + $view->save(); + $this->executeView($view); + foreach ($this->drupalGetJSON('test/serialize/field') as $index => $values) { + $this->assertTrue(!isset($values['created']), 'Excluded value not found.'); + } + // Test that the excluded field is not shown in the row options. + $this->drupalGet('admin/structure/views/nojs/display/test_serializer_display_field/rest_export_1/row_options'); + $this->assertNoText('created'); } /**