Loading core/modules/views/config/schema/views.style.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,9 @@ views.style.table: description: type: text label: 'Table description' class: type: string label: 'Table class' views.style.default_summary: type: views_style Loading core/modules/views/src/Plugin/views/style/Table.php +8 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ protected function defineOptions() { $options = parent::defineOptions(); $options['columns'] = ['default' => []]; $options['class'] = ['default' => []]; $options['default'] = ['default' => '']; $options['info'] = ['default' => []]; $options['override'] = ['default' => TRUE]; Loading Loading @@ -215,6 +216,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { return; } $form['class'] = [ '#title' => $this->t('Table CSS classes'), '#type' => 'textfield', '#description' => $this->t('Classes to provide on the table. Separate multiple classes with a space. Example: classA classB'), '#default_value' => $this->options['class'], ]; $form['override'] = [ '#type' => 'checkbox', '#title' => $this->t('Override normal sorting if click sorting is used'), Loading core/modules/views/src/ViewsConfigUpdater.php +47 −0 Original line number Diff line number Diff line Loading @@ -302,4 +302,51 @@ public function processRememberRolesUpdate(array &$handler, string $handler_type return FALSE; } /** * Checks for table style views needing a default CSS table class value. * * @param \Drupal\views\ViewEntityInterface $view * The view entity. * * @return bool * TRUE if the view has any table styles that need to have * a default table CSS class added. */ public function needsTableCssClassUpdate(ViewEntityInterface $view): bool { return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) use ($view) { return $this->processTableCssClassUpdate($view); }); } /** * Processes views and adds default CSS table class value if necessary. * * @param \Drupal\views\ViewEntityInterface $view * The view entity. * * @return bool * TRUE if the view was updated with a default table CSS class value. */ public function processTableCssClassUpdate(ViewEntityInterface $view): bool { $changed = FALSE; $displays = $view->get('display'); foreach ($displays as &$display) { if ( isset($display['display_options']['style']) && $display['display_options']['style']['type'] === 'table' && !isset($display['display_options']['style']['options']['class']) ) { $display['display_options']['style']['options']['class'] = ''; $changed = TRUE; } } if ($changed) { $view->set('display', $displays); } return $changed; } } core/modules/views/tests/fixtures/update/test_table_css_class.php 0 → 100644 +19 −0 Original line number Diff line number Diff line <?php /** * @file * Test fixture. */ use Drupal\Core\Database\Database; use Drupal\Core\Serialization\Yaml; $connection = Database::getConnection(); $connection->insert('config') ->fields([ 'collection' => '', 'name' => 'views.view.test_table_css_class', 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/fixtures/update/views.view.test_table_css_class.yml'))), ]) ->execute(); core/modules/views/tests/fixtures/update/views.view.test_table_css_class.yml 0 → 100644 +286 −0 Original line number Diff line number Diff line uuid: 6b9a3dba-03ce-4f55-b644-1dce0d234a2a langcode: en status: true dependencies: module: - node - user id: test_table_css_class label: test_table_css_class module: views description: '' tag: '' base_table: node_field_data base_field: nid display: default: id: default display_title: Default display_plugin: default position: 0 display_options: fields: title: id: title table: node_field_data field: title relationship: none group_type: group admin_label: '' entity_type: node entity_field: title plugin_id: field label: '' exclude: false alter: alter_text: false make_link: false absolute: false word_boundary: false ellipsis: false strip_tags: false trim: false html: false element_type: '' element_class: '' element_label_type: '' element_label_class: '' element_label_colon: true 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: true 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 pager: type: mini options: offset: 0 pagination_heading_level: h4 items_per_page: 10 total_pages: null id: 0 tags: next: ›› previous: ‹‹ 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 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 access: type: perm options: perm: 'access content' cache: type: tag options: { } empty: { } sorts: created: id: created table: node_field_data field: created relationship: none group_type: group admin_label: '' entity_type: node entity_field: created plugin_id: date order: DESC expose: label: '' field_identifier: '' exposed: false granularity: second arguments: { } filters: status: id: status table: node_field_data field: status entity_type: node entity_field: status plugin_id: boolean value: '1' group: 1 expose: operator: '' style: type: table options: grouping: { } row_class: '' default_row_class: true columns: title: title default: '-1' info: title: sortable: false default_sort_order: asc align: '' separator: '' empty_column: false responsive: '' override: true sticky: false summary: '' empty_table: false caption: '' description: '' row: type: fields options: default_field_elements: true inline: { } separator: '' hide_empty: false query: type: views_query options: query_comment: '' disable_sql_rewrite: false distinct: false replica: false query_tags: { } relationships: { } header: { } footer: { } display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url.query_args - 'user.node_grants:view' - user.permissions tags: { } block_1: id: block_1 display_title: Block display_plugin: block position: 1 display_options: style: type: table options: grouping: { } row_class: '' default_row_class: true columns: title: title default: '-1' info: title: sortable: false default_sort_order: asc align: '' separator: '' empty_column: false responsive: '' override: true sticky: false summary: '' empty_table: false caption: '' description: '' row: type: fields options: default_field_elements: true inline: { } separator: '' hide_empty: false defaults: style: false row: false display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url.query_args - 'user.node_grants:view' - user.permissions tags: { } page_1: id: page_1 display_title: Page display_plugin: page position: 2 display_options: style: type: table options: grouping: { } row_class: '' default_row_class: true columns: title: title default: '-1' info: title: sortable: false default_sort_order: asc align: '' separator: '' empty_column: false responsive: '' override: true sticky: false summary: '' empty_table: false caption: '' description: '' row: type: fields options: default_field_elements: true inline: { } separator: '' hide_empty: false defaults: style: false row: false display_extenders: { } path: test-table-css-class cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url.query_args - 'user.node_grants:view' - user.permissions tags: { } Loading
core/modules/views/config/schema/views.style.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -124,6 +124,9 @@ views.style.table: description: type: text label: 'Table description' class: type: string label: 'Table class' views.style.default_summary: type: views_style Loading
core/modules/views/src/Plugin/views/style/Table.php +8 −0 Original line number Diff line number Diff line Loading @@ -71,6 +71,7 @@ protected function defineOptions() { $options = parent::defineOptions(); $options['columns'] = ['default' => []]; $options['class'] = ['default' => []]; $options['default'] = ['default' => '']; $options['info'] = ['default' => []]; $options['override'] = ['default' => TRUE]; Loading Loading @@ -215,6 +216,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { return; } $form['class'] = [ '#title' => $this->t('Table CSS classes'), '#type' => 'textfield', '#description' => $this->t('Classes to provide on the table. Separate multiple classes with a space. Example: classA classB'), '#default_value' => $this->options['class'], ]; $form['override'] = [ '#type' => 'checkbox', '#title' => $this->t('Override normal sorting if click sorting is used'), Loading
core/modules/views/src/ViewsConfigUpdater.php +47 −0 Original line number Diff line number Diff line Loading @@ -302,4 +302,51 @@ public function processRememberRolesUpdate(array &$handler, string $handler_type return FALSE; } /** * Checks for table style views needing a default CSS table class value. * * @param \Drupal\views\ViewEntityInterface $view * The view entity. * * @return bool * TRUE if the view has any table styles that need to have * a default table CSS class added. */ public function needsTableCssClassUpdate(ViewEntityInterface $view): bool { return $this->processDisplayHandlers($view, TRUE, function (&$handler, $handler_type) use ($view) { return $this->processTableCssClassUpdate($view); }); } /** * Processes views and adds default CSS table class value if necessary. * * @param \Drupal\views\ViewEntityInterface $view * The view entity. * * @return bool * TRUE if the view was updated with a default table CSS class value. */ public function processTableCssClassUpdate(ViewEntityInterface $view): bool { $changed = FALSE; $displays = $view->get('display'); foreach ($displays as &$display) { if ( isset($display['display_options']['style']) && $display['display_options']['style']['type'] === 'table' && !isset($display['display_options']['style']['options']['class']) ) { $display['display_options']['style']['options']['class'] = ''; $changed = TRUE; } } if ($changed) { $view->set('display', $displays); } return $changed; } }
core/modules/views/tests/fixtures/update/test_table_css_class.php 0 → 100644 +19 −0 Original line number Diff line number Diff line <?php /** * @file * Test fixture. */ use Drupal\Core\Database\Database; use Drupal\Core\Serialization\Yaml; $connection = Database::getConnection(); $connection->insert('config') ->fields([ 'collection' => '', 'name' => 'views.view.test_table_css_class', 'data' => serialize(Yaml::decode(file_get_contents('core/modules/views/tests/fixtures/update/views.view.test_table_css_class.yml'))), ]) ->execute();
core/modules/views/tests/fixtures/update/views.view.test_table_css_class.yml 0 → 100644 +286 −0 Original line number Diff line number Diff line uuid: 6b9a3dba-03ce-4f55-b644-1dce0d234a2a langcode: en status: true dependencies: module: - node - user id: test_table_css_class label: test_table_css_class module: views description: '' tag: '' base_table: node_field_data base_field: nid display: default: id: default display_title: Default display_plugin: default position: 0 display_options: fields: title: id: title table: node_field_data field: title relationship: none group_type: group admin_label: '' entity_type: node entity_field: title plugin_id: field label: '' exclude: false alter: alter_text: false make_link: false absolute: false word_boundary: false ellipsis: false strip_tags: false trim: false html: false element_type: '' element_class: '' element_label_type: '' element_label_class: '' element_label_colon: true 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: true 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 pager: type: mini options: offset: 0 pagination_heading_level: h4 items_per_page: 10 total_pages: null id: 0 tags: next: ›› previous: ‹‹ 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 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 access: type: perm options: perm: 'access content' cache: type: tag options: { } empty: { } sorts: created: id: created table: node_field_data field: created relationship: none group_type: group admin_label: '' entity_type: node entity_field: created plugin_id: date order: DESC expose: label: '' field_identifier: '' exposed: false granularity: second arguments: { } filters: status: id: status table: node_field_data field: status entity_type: node entity_field: status plugin_id: boolean value: '1' group: 1 expose: operator: '' style: type: table options: grouping: { } row_class: '' default_row_class: true columns: title: title default: '-1' info: title: sortable: false default_sort_order: asc align: '' separator: '' empty_column: false responsive: '' override: true sticky: false summary: '' empty_table: false caption: '' description: '' row: type: fields options: default_field_elements: true inline: { } separator: '' hide_empty: false query: type: views_query options: query_comment: '' disable_sql_rewrite: false distinct: false replica: false query_tags: { } relationships: { } header: { } footer: { } display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url.query_args - 'user.node_grants:view' - user.permissions tags: { } block_1: id: block_1 display_title: Block display_plugin: block position: 1 display_options: style: type: table options: grouping: { } row_class: '' default_row_class: true columns: title: title default: '-1' info: title: sortable: false default_sort_order: asc align: '' separator: '' empty_column: false responsive: '' override: true sticky: false summary: '' empty_table: false caption: '' description: '' row: type: fields options: default_field_elements: true inline: { } separator: '' hide_empty: false defaults: style: false row: false display_extenders: { } cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url.query_args - 'user.node_grants:view' - user.permissions tags: { } page_1: id: page_1 display_title: Page display_plugin: page position: 2 display_options: style: type: table options: grouping: { } row_class: '' default_row_class: true columns: title: title default: '-1' info: title: sortable: false default_sort_order: asc align: '' separator: '' empty_column: false responsive: '' override: true sticky: false summary: '' empty_table: false caption: '' description: '' row: type: fields options: default_field_elements: true inline: { } separator: '' hide_empty: false defaults: style: false row: false display_extenders: { } path: test-table-css-class cache_metadata: max-age: -1 contexts: - 'languages:language_content' - 'languages:language_interface' - url.query_args - 'user.node_grants:view' - user.permissions tags: { }