Loading core/modules/views/src/Entity/Render/EntityFieldRenderer.php +6 −4 Changes for core/modules/views/src/Entity/Render/EntityFieldRenderer.php: 6 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -215,11 +215,13 @@ protected function buildFields(array $values) { $display_sets = []; foreach ($field_ids as $field_id) { $field = $this->view->field[$field_id]; $field_name = $field->definition['field_name']; $index = 0; while (isset($display_sets[$index][$field->definition['field_name']])) { while (isset($display_sets[$index]['field_names'][$field_name])) { $index++; } $display_sets[$index][$field_id] = $field; $display_sets[$index]['field_names'][$field_name] = $field; $display_sets[$index]['field_ids'][$field_id] = $field; } // For each set of fields, build the output by bundle. Loading @@ -231,7 +233,7 @@ protected function buildFields(array $values) { 'bundle' => $bundle, 'status' => TRUE, ]); foreach ($display_fields as $field_id => $field) { foreach ($display_fields['field_ids'] as $field) { $display->setComponent($field->definition['field_name'], [ 'type' => $field->options['type'], 'settings' => $field->options['settings'], Loading @@ -242,7 +244,7 @@ protected function buildFields(array $values) { // Collect the field render arrays and index them using our internal // row indexes and field IDs. foreach ($display_build as $row_index => $entity_build) { foreach ($display_fields as $field_id => $field) { foreach ($display_fields['field_ids'] as $field_id => $field) { $build[$row_index][$field_id] = !empty($entity_build[$field->definition['field_name']]) ? $entity_build[$field->definition['field_name']] : []; } } Loading core/modules/views/src/Tests/Handler/FieldFieldTest.php +17 −0 Changes for core/modules/views/src/Tests/Handler/FieldFieldTest.php: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ protected function setUp() { $this->testUsers[$i] = User::create([ 'name' => 'test ' . $i, 'timezone' => User::getAllowedTimezones()[$i], 'created' => REQUEST_TIME - rand(0, 3600) ]); $this->testUsers[$i]->save(); } Loading Loading @@ -371,31 +372,47 @@ public function testComplexExecute() { public function testComplexRender() { $executable = Views::getView('test_field_field_complex_test'); $executable->execute(); $date_formatter = \Drupal::service('date.formatter'); $this->assertEqual($this->testUsers[0]->getTimeZone(), $executable->getStyle()->getField(0, 'timezone')); $this->assertEqual("1, 3", $executable->getStyle()->getField(0, 'field_test_multiple')); $this->assertEqual("1", $executable->getStyle()->getField(0, 'field_test_multiple_1')); $this->assertEqual("3", $executable->getStyle()->getField(0, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(0, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(0, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(0, 'created_2')); $this->assertEqual($this->testUsers[1]->getTimeZone(), $executable->getStyle()->getField(1, 'timezone')); $this->assertEqual("7, 0", $executable->getStyle()->getField(1, 'field_test_multiple')); $this->assertEqual("7", $executable->getStyle()->getField(1, 'field_test_multiple_1')); $this->assertEqual("0", $executable->getStyle()->getField(1, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(1, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(1, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(1, 'created_2')); $this->assertEqual($this->testUsers[2]->getTimeZone(), $executable->getStyle()->getField(2, 'timezone')); $this->assertEqual("3, 5", $executable->getStyle()->getField(2, 'field_test_multiple')); $this->assertEqual("3", $executable->getStyle()->getField(2, 'field_test_multiple_1')); $this->assertEqual("5", $executable->getStyle()->getField(2, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(2, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(2, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(2, 'created_2')); $this->assertEqual($this->testUsers[3]->getTimeZone(), $executable->getStyle()->getField(3, 'timezone')); $this->assertEqual("9, 9", $executable->getStyle()->getField(3, 'field_test_multiple')); $this->assertEqual("9", $executable->getStyle()->getField(3, 'field_test_multiple_1')); $this->assertEqual("9", $executable->getStyle()->getField(3, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(3, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(3, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(3, 'created_2')); $this->assertEqual($this->testUsers[4]->getTimeZone(), $executable->getStyle()->getField(4, 'timezone')); $this->assertEqual("9, 0", $executable->getStyle()->getField(4, 'field_test_multiple')); $this->assertEqual("9", $executable->getStyle()->getField(4, 'field_test_multiple_1')); $this->assertEqual("0", $executable->getStyle()->getField(4, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(4, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(4, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(4, 'created_2')); } /** Loading core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_complex_test.yml +39 −0 Changes for core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_complex_test.yml: 39 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -58,6 +58,45 @@ display: plugin_id: field relationship: user_id alter: {} created: id: created table: users_field_data field: created relationship: user_id type: timestamp settings: date_format: custom custom_date_format: 'Y' timezone: '' entity_type: user entity_field: created plugin_id: field created_1: id: created_1 table: users_field_data field: created relationship: user_id type: timestamp settings: date_format: custom custom_date_format: 'H:i:s' timezone: '' entity_type: user entity_field: created plugin_id: field created_2: id: created_2 table: users_field_data field: created relationship: user_id type: timestamp settings: date_format: fallback custom_date_format: '' timezone: '' entity_type: user entity_field: created plugin_id: field relationships: user_id: table: entity_test Loading Loading
core/modules/views/src/Entity/Render/EntityFieldRenderer.php +6 −4 Changes for core/modules/views/src/Entity/Render/EntityFieldRenderer.php: 6 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -215,11 +215,13 @@ protected function buildFields(array $values) { $display_sets = []; foreach ($field_ids as $field_id) { $field = $this->view->field[$field_id]; $field_name = $field->definition['field_name']; $index = 0; while (isset($display_sets[$index][$field->definition['field_name']])) { while (isset($display_sets[$index]['field_names'][$field_name])) { $index++; } $display_sets[$index][$field_id] = $field; $display_sets[$index]['field_names'][$field_name] = $field; $display_sets[$index]['field_ids'][$field_id] = $field; } // For each set of fields, build the output by bundle. Loading @@ -231,7 +233,7 @@ protected function buildFields(array $values) { 'bundle' => $bundle, 'status' => TRUE, ]); foreach ($display_fields as $field_id => $field) { foreach ($display_fields['field_ids'] as $field) { $display->setComponent($field->definition['field_name'], [ 'type' => $field->options['type'], 'settings' => $field->options['settings'], Loading @@ -242,7 +244,7 @@ protected function buildFields(array $values) { // Collect the field render arrays and index them using our internal // row indexes and field IDs. foreach ($display_build as $row_index => $entity_build) { foreach ($display_fields as $field_id => $field) { foreach ($display_fields['field_ids'] as $field_id => $field) { $build[$row_index][$field_id] = !empty($entity_build[$field->definition['field_name']]) ? $entity_build[$field->definition['field_name']] : []; } } Loading
core/modules/views/src/Tests/Handler/FieldFieldTest.php +17 −0 Changes for core/modules/views/src/Tests/Handler/FieldFieldTest.php: 17 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -83,6 +83,7 @@ protected function setUp() { $this->testUsers[$i] = User::create([ 'name' => 'test ' . $i, 'timezone' => User::getAllowedTimezones()[$i], 'created' => REQUEST_TIME - rand(0, 3600) ]); $this->testUsers[$i]->save(); } Loading Loading @@ -371,31 +372,47 @@ public function testComplexExecute() { public function testComplexRender() { $executable = Views::getView('test_field_field_complex_test'); $executable->execute(); $date_formatter = \Drupal::service('date.formatter'); $this->assertEqual($this->testUsers[0]->getTimeZone(), $executable->getStyle()->getField(0, 'timezone')); $this->assertEqual("1, 3", $executable->getStyle()->getField(0, 'field_test_multiple')); $this->assertEqual("1", $executable->getStyle()->getField(0, 'field_test_multiple_1')); $this->assertEqual("3", $executable->getStyle()->getField(0, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(0, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(0, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[0]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(0, 'created_2')); $this->assertEqual($this->testUsers[1]->getTimeZone(), $executable->getStyle()->getField(1, 'timezone')); $this->assertEqual("7, 0", $executable->getStyle()->getField(1, 'field_test_multiple')); $this->assertEqual("7", $executable->getStyle()->getField(1, 'field_test_multiple_1')); $this->assertEqual("0", $executable->getStyle()->getField(1, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(1, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(1, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[1]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(1, 'created_2')); $this->assertEqual($this->testUsers[2]->getTimeZone(), $executable->getStyle()->getField(2, 'timezone')); $this->assertEqual("3, 5", $executable->getStyle()->getField(2, 'field_test_multiple')); $this->assertEqual("3", $executable->getStyle()->getField(2, 'field_test_multiple_1')); $this->assertEqual("5", $executable->getStyle()->getField(2, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(2, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(2, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[2]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(2, 'created_2')); $this->assertEqual($this->testUsers[3]->getTimeZone(), $executable->getStyle()->getField(3, 'timezone')); $this->assertEqual("9, 9", $executable->getStyle()->getField(3, 'field_test_multiple')); $this->assertEqual("9", $executable->getStyle()->getField(3, 'field_test_multiple_1')); $this->assertEqual("9", $executable->getStyle()->getField(3, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(3, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(3, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[3]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(3, 'created_2')); $this->assertEqual($this->testUsers[4]->getTimeZone(), $executable->getStyle()->getField(4, 'timezone')); $this->assertEqual("9, 0", $executable->getStyle()->getField(4, 'field_test_multiple')); $this->assertEqual("9", $executable->getStyle()->getField(4, 'field_test_multiple_1')); $this->assertEqual("0", $executable->getStyle()->getField(4, 'field_test_multiple_2')); $this->assertEqual($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'Y'), $executable->getStyle()->getField(4, 'created')); $this->assertEqual($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'custom', 'H:i:s'), $executable->getStyle()->getField(4, 'created_1')); $this->assertEqual($date_formatter->format($this->testUsers[4]->getCreatedTime(), 'fallback'), $executable->getStyle()->getField(4, 'created_2')); } /** Loading
core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_complex_test.yml +39 −0 Changes for core/modules/views/tests/modules/views_test_config/test_views/views.view.test_field_field_complex_test.yml: 39 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -58,6 +58,45 @@ display: plugin_id: field relationship: user_id alter: {} created: id: created table: users_field_data field: created relationship: user_id type: timestamp settings: date_format: custom custom_date_format: 'Y' timezone: '' entity_type: user entity_field: created plugin_id: field created_1: id: created_1 table: users_field_data field: created relationship: user_id type: timestamp settings: date_format: custom custom_date_format: 'H:i:s' timezone: '' entity_type: user entity_field: created plugin_id: field created_2: id: created_2 table: users_field_data field: created relationship: user_id type: timestamp settings: date_format: fallback custom_date_format: '' timezone: '' entity_type: user entity_field: created plugin_id: field relationships: user_id: table: entity_test Loading