diff --git a/core/modules/rest/src/Plugin/views/row/DataFieldRow.php b/core/modules/rest/src/Plugin/views/row/DataFieldRow.php index 68ba897..09d31d3 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 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { 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 @@ public function render($row) { $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 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])) { diff --git a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php index e3b8d26..ab6e97b 100644 --- a/core/modules/rest/src/Tests/Views/StyleSerializerTest.php +++ b/core/modules/rest/src/Tests/Views/StyleSerializerTest.php @@ -456,6 +456,32 @@ public function testFieldRawOutput() { foreach ($this->drupalGetJSON('test/serialize/field') as $index => $values) { $this->assertIdentical($values['created'], $view->result[$index]->views_test_data_created, 'Expected raw created 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'); } /**