Commit e3de68b0 authored by alexpott's avatar alexpott

Issue #2606548 by Lendude, dawehner, alexpott, catch, tim.plunkett, xjm,...

Issue #2606548 by Lendude, dawehner, alexpott, catch, tim.plunkett, xjm, damiankloip: \Drupal\rest\Plugin\views\row\DataFieldRow::render should take into account the 'exclude' flag
parent 027c0d82
......@@ -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 the raw output option has been set, just get the raw value.
if (!empty($this->rawOutputOptions[$id])) {
$value = $field->getValue($row);
......
......@@ -470,6 +470,32 @@ public function testFieldRawOutput() {
$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');
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment