block--fences.html.twig does (and should?) not overwrite theme overwrites

Created on 19 August 2022, over 2 years ago
Updated 17 February 2023, almost 2 years ago

By design fences_block places block--fences-block.html.twig and adds a higher weighted suggestion for block--fences-block.html.twig via

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function fences_block_theme_suggestions_block_alter(array &$suggestions, array $variables, $hook) {
  // Further suggestions MIGHT be added here later, see:
  // https://www.drupal.org/project/fences_block/issues/3304737
  // Add suggestion above block.html.twig:
  array_unshift($suggestions, 'block__fences');
}

Intentionally, it does NOT overwrite block.html.twig in general, otherwise it could reintroduce the problem that the modules overwrites (core / admin / contrib) themes custom implementations / overwrites, which are needed.

For a history of on this topic please read the following issues before commenting:

From #3303750: Add basic tests :
Our problem now is, that there's nothing like a "custom theme" as a special layer. Also Olivero or stark are at the same level as our custom themes and already have overrides for block.html.twig. So we have to decide if fences_block weight is higher or lower in general or add a setting or whatever is a good idea...

The implementation I pushed now should work for all blocks that are NOT overwriting block.html.twig, but for the reasons above, that might not be enough in many cases, so it will seem like fences_block doesn't (fully) work!

Some examples (tested with Stark theme, like the tests do):
Good:

 FILE NAME SUGGESTIONS:
   * block--stark-content.html.twig
   * block--system-main-block.html.twig
   * block--system.html.twig
   x block--fences-block.html.twig
   * block.html.twig

Bad:

 FILE NAME SUGGESTIONS:
   * block--stark-site-branding.html.twig
   x block--system-branding-block.html.twig
   * block--system.html.twig
   * block--fences-block.html.twig
   * block.html.twig

For Stark theme, which is the default testing theme, the following blocks twig files are overwritten:
(in "system" module):

block--local-actions-block.html.twig
block--system-branding-block.html.twig
block--system-menu-block.html.twig
block--system-messages-block.html.twig

Stark theme itself doesn't overwrite twig files.

Olivero theme for example has even more block overwrites:
block--page-title-block.html.twig
block--primary-menu--plugin-id--search-form-block.html.twig
block--search-form-block.html.twig
[...]

We now have tests in place, which ensure the core themes are NOT overwritten! If we'll ever find a clever solution, these have to be changed accordingly. See FencesBlockFunctionalBlockDisfunctional.php

But we have to be 100% sure we don't break anything! Instead we should provide as much safety & flexibility as possible.

📌 Task
Status

Postponed

Version

2.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024