Issue #3343198: Improve documentation of hook_theme_suggestions_HOOK_alter()
Merge request reports
Activity
- Resolved by Andy Blum
- Resolved by Andy Blum
- Resolved by Andy Blum
- Resolved by Andy Blum
97 foreach ($suggestions as $key => &$suggestion) { 98 $hook = $hook ?? $variables['theme_hook_original']; 99 // Valid suggestions are $hook, $hook__*, and contain no hyphens. 100 if (($suggestion !== $hook && !str_starts_with($suggestion, $hook . '__')) || str_contains($suggestion, '-')) { 101 $invalid_suggestions[] = $suggestion; 102 unset($suggestions[$key]); 103 continue; 104 } 97 105 $template = strtr($suggestion, '_', '-') . $extension; 98 106 $prefix = ($template == $current_template) ? 'x' : '*'; 99 107 $suggestion = $prefix . ' ' . $template; 100 108 } 101 109 $output['debug_info'] .= "\n<!-- FILE NAME SUGGESTIONS:\n " . Html::escape(implode("\n ", $suggestions)) . "\n-->"; 110 111 if (!empty($invalid_suggestions)) { 112 $output['debug_info'] .= "\n<!-- INVALID FILE NAME SUGGESTIONS:\n " . Html::escape(implode("\n ", $invalid_suggestions)) . "\n-->"; I can understand how it might be confusing, but I'm not really sure what else to add here without dramatically cluttering up the debug statements.
I also think this is considerably less confusing than an invalid suggestion appearing in the list of file name suggestions and then just not working.
changed this line in version 8 of the diff
Added a new line with a link to the hook_theme_suggestions_alter documentation:
<!-- INVALID FILE NAME SUGGESTIONS: See https://api.drupal.org/node/13762860 bad_suggestion -->"
I considered using dgo.re/a/hook_theme_suggestions_alter as it should update as the supported versions of Drupal change, but wasn't sure if that would be allowed as dgo.re is a contrib project
The canonical URL, https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme_suggestions_alter/10 should be used. The node/nid URL is undocumented and may change.
- Resolved by Andy Blum
- Resolved by Andy Blum
added 2 commits
- Resolved by Andy Blum
added 1 commit
- c31d1e9a - dont overwrite $base_hook if it already exists
added 32 commits
-
c31d1e9a...e8cdbb69 - 31 commits from branch
project:10.1.x
- bfcfa2fb - Merge branch '10.1.x' into 3343198-improve-documentation-of
-
c31d1e9a...e8cdbb69 - 31 commits from branch
added 1 commit
- aff67c14 - add link to hook_theme_suggestions_alter docs with invalid patterns
added 40 commits
-
0439ae48...22a39eb4 - 28 commits from branch
project:10.1.x
- 4e6ca6d6 - Update api documentation
- 11dc2845 - Move invalid suggestions out of theme debug template list
- ed652699 - Address feedback from @murilohp
- 2929fbdb - Add tests.
- 65ca4730 - update documentation wording
- e6bfc89e - rename $hook to $base_hook
- 43213c64 - add valid/invalid suggestion examples
- 713bf984 - dont overwrite $base_hook if it already exists
- e7354529 - add link to hook_theme_suggestions_alter docs with invalid patterns
- 6fef0ec7 - Update to canonical link
- d60f5918 - Update tests with docs link
- 5a64e3e8 - Update the tests.
Toggle commit list-
0439ae48...22a39eb4 - 28 commits from branch