Problem/Motivation

Olivero adds table.css to its base library, but the vast majority of pages don't include tables.

I think Olivero could define a table library, move the CSS there, then attach this to all table render elements / #theme table.

This would remove 2.2k of unused CSS on pages that don't have tables.

Steps to reproduce

Proposed resolution

Add a new library, like olivero.table and move table.css there.

Attach the library to tables, probably could be done in olivero_preprocess_table() which already exists.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3515093

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

sandip’s picture

I am working on it.

sandip’s picture

Status: Active » Needs review

Please review the changes.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems pretty straight forward

@sandip poddar looking at your post history, could probably elevate past novice tagged issues. Thanks!

sandip’s picture

Thanks @smustgrave! I'll definitely start looking into more advanced issues.

nod_’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Novice

The css is not added to pages with a table, something doesn't work here. I checked /admin/content with olivero as admin theme.

The file needs to have the deprecation dance: see https://www.drupal.org/about/core/policies/core-change-policies/how-to-d... for an example you can check #3512194: Move resize CSS into its own library

sandip’s picture

StatusFileSize
new154.14 KB

Hi @nod_ thanks for the review. I wanted to clarify that I can see the table.css file being added correctly. For testing purpose, I intentionally added background-color: blue to the table tag, and I verified in the Network tab also that the stylesheet is loading as expected. Can you again have a look at it please.

For reference, I’ve attached a screenshot

Thanks again for your guidance and for providing these valuable resources. I haven’t try any recordable changes yet, but I’m going through the documentation you shared and trying to implement the same here.

sandip’s picture

Sorry my bad! that thing is only works for table.html.twig not working for view-view-table.html.twig. Sorry for the above noice i did not notice it before. I am fixing it.

sandip’s picture

Status: Needs work » Needs review

Here is the change record: https://www.drupal.org/node/3517675

Please review the changes.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Cleaned up the CR a bit. Don't think we needed to include the MR as a patch, and tweaked the versions.

  • nod_ committed ab9823e4 on 11.x
    Issue #3515093 by sandip, catch, smustgrave: Olivero table.css should be...
nod_’s picture

Status: Reviewed & tested by the community » Fixed

Committed ab9823e and pushed to 11.x. Thanks!

mherchel’s picture

Somehow I missed this.

Tables can also be added via CKEditor, which is why we had it as a global library. You can see at https://git.drupalcode.org/project/drupal/-/blob/11.2.x/core/themes/oliv..., we're also targeting tables that appear in .text-content (which is formatted text).

  • catch committed dc12bed4 on 11.2.x authored by nod_
    Revert "Issue #3515093 by sandip, catch, smustgrave: Olivero table.css...

  • catch committed cfd4c18d on 11.x authored by nod_
    Revert "Issue #3515093 by sandip, catch, smustgrave: Olivero table.css...
catch’s picture

Status: Fixed » Needs work

@mherchel - best to re-open issues if there's a problem or create a follow-up, it's easy for comments on fixed issues to go missing.

I've reverted this from 11.x and 11.2.x for more discussion. We could potentially add the library when text fields are rendered too.

sandip’s picture

Hi @catch, @mherchel
Can we try something like this below. Is it the right approach for it?

diff --git a/core/themes/olivero/olivero.theme b/core/themes/olivero/olivero.theme
index b2f3bff2684..0ee7fed1c81 100644
--- a/core/themes/olivero/olivero.theme
+++ b/core/themes/olivero/olivero.theme
@@ -365,6 +365,7 @@ function olivero_preprocess_field(&$variables): void {
 
   if (in_array($variables['field_type'], $rich_field_types, TRUE)) {
     $variables['attributes']['class'][] = 'text-content';
+    $variables['#attached']['library'][] = 'olivero/olivero.table';
   }
 
   if ($variables['field_type'] == 'image' && $variables['element']['#view_mode'] == 'full' && !$variables["element"]["#is_multiple"] && $variables['field_name'] !== 'user_picture') {

New change:

/**
 * Implements hook_preprocess_HOOK().
 */
function olivero_preprocess_field(&$variables): void {
  $rich_field_types = ['text_with_summary', 'text', 'text_long'];

  if (in_array($variables['field_type'], $rich_field_types, TRUE)) {
    $variables['attributes']['class'][] = 'text-content';
    $variables['#attached']['library'][] = 'olivero/olivero.table';
  }

  if ($variables['field_type'] == 'image' && $variables['element']['#view_mode'] == 'full' && !$variables["element"]["#is_multiple"] && $variables['field_name'] !== 'user_picture') {
    $variables['attributes']['class'][] = 'wide-content';
  }
}
sandip’s picture

If you agree i am updating this in the MR so.

nod_’s picture

that looks reasonable

sandip’s picture

Status: Needs work » Needs review
StatusFileSize
new103.65 KB
new210.81 KB

@nod_ sorry for the delay. I've raised the MR and attached some images for clarity. Moving the issue to NR.

smustgrave’s picture

Status: Needs review » Needs work

Deprecation versions need to be updated for 11.3, CR too.

CR maybe could use before/after code snippets for people to use this library.

sandip’s picture

I am working on it.

sandip’s picture

Status: Needs work » Needs review

@smustgrave, I have implemented your suggestions please review the changes. Here is the updated CR: https://www.drupal.org/node/3517675

mherchel’s picture

Status: Needs review » Reviewed & tested by the community

New changes look good. The table library will be loaded when rich text fields are being displayed.

  • nod_ committed 3713df50 on 11.x
    Issue #3515093 by sandip, catch, smustgrave, nod_, mherchel: Olivero...
nod_’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3713df5 and pushed to 11.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.