diff --git a/core/modules/views/config/schema/views.data_types.schema.yml b/core/modules/views/config/schema/views.data_types.schema.yml index 26f14c6e4b..19841fa6db 100644 --- a/core/modules/views/config/schema/views.data_types.schema.yml +++ b/core/modules/views/config/schema/views.data_types.schema.yml @@ -574,6 +574,31 @@ views_field: plugin_id: type: string label: 'Plugin ID' + # In case of using aggregation, field has numeric settings. + set_precision: + type: boolean + label: 'Round' + precision: + type: integer + label: 'Precision' + decimal: + type: string + label: 'Decimal point' + separator: + type: string + label: 'Thousands marker' + format_plural: + type: boolean + label: 'Format plural' + format_plural_string: + type: plural_label + label: 'Plural variants' + prefix: + type: label + label: 'Prefix' + suffix: + type: label + label: 'Suffix' views_pager: type: mapping diff --git a/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_aggregate_count_int.yml b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_aggregate_count_int.yml new file mode 100644 index 0000000000..3c22dbf571 --- /dev/null +++ b/core/modules/views/tests/modules/views_test_config/test_views/views.view.test_aggregate_count_int.yml @@ -0,0 +1,229 @@ +langcode: en +status: true +dependencies: + module: + - entity_test +id: test_aggregate_count_int +label: test_aggregate_count_int +module: views +description: '' +tag: '' +base_table: entity_test +base_field: id +display: + default: + display_plugin: default + id: default + display_title: Default + position: 0 + display_options: + access: + type: none + options: { } + cache: + type: tag + options: { } + query: + type: views_query + options: + disable_sql_rewrite: false + distinct: false + replica: false + query_comment: '' + query_tags: { } + exposed_form: + type: basic + options: + submit_button: Apply + reset_button: false + reset_button_label: Reset + exposed_sorts_label: 'Sort by' + expose_sort_order: true + sort_asc_label: Asc + sort_desc_label: Desc + pager: + type: mini + options: + items_per_page: 10 + offset: 0 + id: 0 + total_pages: null + expose: + items_per_page: false + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 25, 50' + items_per_page_options_all: false + items_per_page_options_all_label: '- All -' + offset: false + offset_label: Offset + tags: + previous: ‹‹ + next: ›› + style: + type: default + options: + grouping: { } + row_class: '' + default_row_class: true + uses_fields: false + row: + type: fields + options: + inline: { } + separator: '' + hide_empty: false + default_field_elements: true + fields: + name_alias: + id: name_alias + table: entity_test + field: name_alias + relationship: none + group_type: group + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + click_sort_column: value + type: string + settings: + link_to_entity: false + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + separator: ', ' + field_api_classes: false + entity_type: entity_test + entity_field: name + plugin_id: field + id: + id: id + table: entity_test + field: id + relationship: none + group_type: count + admin_label: '' + label: '' + exclude: false + alter: + alter_text: false + text: '' + make_link: false + path: '' + absolute: false + external: false + replace_spaces: false + path_case: none + trim_whitespace: false + alt: '' + rel: '' + link_class: '' + prefix: '' + suffix: '' + target: '' + nl2br: false + max_length: 0 + word_boundary: true + ellipsis: true + more_link: false + more_link_text: '' + more_link_path: '' + strip_tags: false + trim: false + preserve_tags: '' + html: false + element_type: '' + element_class: '' + element_label_type: '' + element_label_class: '' + element_label_colon: false + element_wrapper_type: '' + element_wrapper_class: '' + element_default_classes: true + empty: '' + hide_empty: false + empty_zero: false + hide_alter_empty: true + set_precision: false + precision: 0 + decimal: . + separator: ', ' + format_plural: false + format_plural_string: !!binary MQNAY291bnQ= + prefix: '' + suffix: '' + click_sort_column: value + type: number_integer + settings: { } + group_column: value + group_columns: { } + group_rows: true + delta_limit: 0 + delta_offset: 0 + delta_reversed: false + delta_first_last: false + multi_type: separator + field_api_classes: false + entity_type: entity_test + entity_field: id + plugin_id: field + filters: { } + sorts: { } + header: { } + footer: { } + empty: { } + relationships: { } + arguments: { } + display_extenders: { } + group_by: true + cache_metadata: + max-age: -1 + contexts: + - entity_test_view_grants + - 'languages:language_content' + - 'languages:language_interface' + - url.query_args + tags: { } diff --git a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php index 522ff701ca..02b6aab584 100644 --- a/core/modules/views/tests/src/Kernel/QueryGroupByTest.php +++ b/core/modules/views/tests/src/Kernel/QueryGroupByTest.php @@ -27,6 +27,7 @@ class QueryGroupByTest extends ViewsKernelTestBase { 'test_aggregate_count', 'test_aggregate_count_function', 'test_group_by_count', + 'test_aggregate_count_int', 'test_group_by_count_multicardinality', 'test_group_by_field_not_within_bundle', ]; @@ -100,6 +101,27 @@ public function testAggregateCountFunction() { $this->assertCount(1, $view->result, 'Make sure the count of rows is one.'); } + /** + * Tests aggregate count feature on an integer field. + */ + public function testAggregateCountInt() { + $this->setupTestEntities(); + + $view = Views::getView('test_aggregate_count_int'); + $this->executeView($view); + + $this->assertCount(2, $view->result, 'Make sure the count of items is right.'); + + $types = []; + foreach ($view->result as $item) { + // num_records is an alias for id. + $types[$item->entity_test_name] = $item->id; + } + + $this->assertEquals(4, $types['name1']); + $this->assertEquals(3, $types['name2']); + } + /** * Provides a test helper which runs a view with some aggregation function. *