Problem/Motivation
Tokens for retrieving site logos such as `[site:logo]`, `[site:logo:default-theme]`, and `[site:logo:active-theme]` are currently missing from Drupal core. This functionality partially existed in Drupal 7, but was removed in the transition to Drupal 8+, resulting in a regression.
This impacts use cases where site builders or module developers want to programmatically access different theme-specific or site-wide logos, such as when rendering tokens in blocks or email templates.
Steps to reproduce
1. Install a fresh Drupal 10 or 11 site.
2. Enable the Token module.
3. Attempt to use `[site:logo]` or `[site:logo:active-theme]` in a token context (e.g., block, email).
4. Observe that the tokens are unavailable or do not resolve.
Proposed resolution
Introduce a set of new site logo-related tokens to core:
- `[site:logo]`: Resolves to the logo of the active theme.
- `[site:logo:default-theme]`: Resolves to the logo configured for the site's default theme.
- `[site:logo:active-theme]`: Explicitly resolves to the active theme’s logo.
- `[site:logo:theme-machine_name]` and `[site:logo:theme-machine_name:url]`: Dynamic tokens for each installed theme.
These tokens are implemented using the existing `site` token type. Technically, new token "types" such as `site-logo` and `site-logo-properties` are introduced, but these serve primarily to provide deeper token nesting and are resolved internally via `$token_service->findWithPrefix`.
Concerns from earlier in the issue (e.g., mail rendering and token type structure) have been addressed:
- Using tokens in emails: Users can explicitly choose the correct logo token (e.g., `[site:logo:default-theme]`) depending on context.
- (#173–#180): Clarified that no truly new top-level token type is introduced, only structured subtypes under `site`.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #242 | 2842780-242.patch | 19.24 KB | grevil |
| #225 | 2842780-224.patch | 18.85 KB | anybody |
| #193 | 2842780-193.patch | 4.68 KB | atul4drupal |
| #190 | 2842780-add-site-logo-token-MR-4236-190.diff | 15.79 KB | anybody |
| #168 | 2842780-168.patch | 16.1 KB | neograph734 |
Issue fork drupal-2842780
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
Comment #2
neograph734Comment #3
neograph734Comment #4
neograph734Comment #5
kopeboyThanks, let's hope we can get this on D7 as well (if soon)
Comment #6
neograph734Kopeboy, if you have the time, you could speed this up by helping to test for Drupal 8 first.
Comment #7
neograph734Also implemented tests for the tokens and assumed
system.theme.globalwould be a suitable config for theaddCacheableDependency().Comment #9
neograph734Lets try it like this...
Comment #10
neograph734Comment #11
kopeboy@Neograph734 Haven't made any website on Drupal 8 yet, sorry.
(Cause Omega8.cc aren't supporting it yet :/ have any good, specialized & cheap hosting for europe? :D )
Comment #12
neograph734Uppercased
urlin token description to beURL, in order to be consistent with other tokens.Comment #13
neograph734Comment #15
wturrell commentedReview:
- the sole change in my patch is removing one piece of whitespace, so I'm marking this RTBC at the same time
- as @neograph734 says, the other site tokens are already in core, so see no objection for this to be
- patch applies cleanly on 8.3.x and works as described
- has automated tests, which I ran locally (I also ran a test-only patch and verified it failed)
- added issue summary template + steps to reproduce
- code style fine otherwise
- changes all in scope
- @neograph734 mentions doubts over the metadata in the IS, but has added the appropriate tests and it looks OK to me
- names of new tokens are sensible/consistent with what we already have
- this contains new translatable strings, tagged as string change
- no UI (CSS/JS) changes (other than the new text in token module - Available tokens window)
Comment #16
wturrell commentedComment #17
alexpottSo if you're using Seven as your admin theme and you send an email from the admin interface it's going to use seven logo. Also what happens if the bartik logo is customised but not the global setting.
I think the only option is to have a logo per theme and the global one. But one thing that is interesting - theme_get_setting('logo.url') will return you the logo url of the active theme so I'm not sure that using theme_get_setting is right here.
What's for sure is that we need more testing of what happens when you have multiple themes with different logos.
Comment #18
neograph734@wturrell thanks for the review.
@alexpott, feedback per point.
If there is a seven logo configured, probably, yes. Though most people probably do not specifically configure a seven logo, it is more likely the global logo will be used as fallback. But it is a possible scenario indeed.
It was my understanding that
theme_get_setting()would fetch the global permissions first and override them with theme specific settings if applicable. So iftheme_get_setting()detects bartik as the active theme, it will show the altered bartik logo.Sticking to the situation of mails, this makes not much sense to me; One would have to configure mail texts for every theme. This would greatly reduce the usability.
For user interactions this will work fine as the user will get everything in his selected theme. For admin triggered interactions this might become troublesome indeed.
After reading your scenarios I agree some more work can be done. In the end, all the issues you have pointed out originate from the same problem; How to know what theme to select. But that is difficult as well because this is a (non user specific) global token (to remain similar to site name and slogan).
If you have any idea on how to to detect the theme of the current user in, for instance a batch operation, and provide that to the replacement token I'd be happy to hear it. I'll give this some more thought as well.
Comment #19
neograph734Thinking of this again, I do not think the global theme is the correct cacheable dependency. We should use the
themecache context instead to be able to properly serve the logo per theme.theme_get_setting()could work because it has a second parameter to pass a predefined theme:theme_get_setting($setting_name, $theme = NULL) {}. We'd only have to figure out what theme to use.Alternatively, we could also choose to keep the global logo implementation as it is (for the simple cases when there is only one theme) and create something like a
[user:theme-logo]token to be able to serve every user the logo of his selected theme. This could be explained in the[site:logo]token description.Comment #20
Pavan B S commentedRerolled the patch, please review.
Comment #21
neograph734Ok, I have reworked the approach a bit.
[site:logo]now queries the default theme and passes that to theme_get_setting(). If all goes well, that means it should show the default theme logo, unless overridden by a global logo, unless overridden by a theme logo. This should be enough for most cases.For those people who need more control, there is also
[site:logo:<theme-name>], for instance[site:logo:bartik], providing the logo of the provided theme. (Again in the same order, default theme logo, global logo, manual theme logo).The same applies to
[site:logo-url]and[site:logo-url:<theme-name>].I guess this method will provide the most predictable behavior.
Comment #23
neograph734This should do it.
Comment #24
Munavijayalakshmi commentedLine exceeding 80 characters
Comments should (noramlly) begin with a capital letter and end with a full stop / period .
Fixed and attached new patch.
Comment #25
neograph734Updated the description to include the
[site:logo:?]tokens.Comment #27
anybody#24 works great. I'd suggest to RTBC this. Can we get some more feedback?
Comment #28
matthiasm11 commentedApplied the patch from #24, still working on 8.4.2.
Comment #29
anybodyYes I can confirm that too. #24 RTBC.
Comment #30
plachThanks for your work here! I'm going to retest #24 against 8.5.x as feature requests should target the development branch. A release manager may consider backporting this to the production branch (8.4.x).
Comment #31
MixologicImage dimension test fails were artifacts of php container upgrade issues, unrelated to this patch.
Comment #32
larowlanShould this render in a context, catch any bubbleable metadata and add to the existing one?
Comment #33
plachGood stuff! I found only a few minor things and a possible improvement:
Wrong indentation :)
These calls can be moved outside the foreach loop.
Can we add the case of a non-default theme with a custom logo and check whether the token is correctly generated also in both of these cases?
Deprecated calls, we should use
::assertEquals().In all the four hunks of
system.tokens.incI'm seeing some duplicate code. I'm wondering whether we could factor it out to an internal helper function, something like this:In the first two cases we would be passing the default theme as parameter.
Comment #34
plachComment #35
plachOne more, sorry:
What about adding also info about all the theme-specific tokens?
Comment #36
neograph734@plach (and others), thanks for taking a look. Could you help me out with a few questions?
All other assertions in that file still use the old
assertEqual(), I felt it would not be right to combine old and new standards, so I went ahead with what was already present in the file. If you still feel I should update it, I will do it.I am not sure how to. Would it be something like this?
I will implement the rest of your feedback shortly.
Comment #37
neograph734Let's see how this holds up.
Comment #39
neograph734Rebased the code. Lets hop it works now.
Comment #41
neograph734Like this?
Comment #42
neograph734Comment #44
neograph734That was a stupid typo. The other fails do not seem to be related.
Comment #45
plachChanges look good to me, thanks!
I don't feel strongly about this, but it seems to me that our deprecation policy recommends not to introduce new usages of deprecated code, although it's not crystal clear on this matter:
I'm assuming that if it applies for contrib/custom code it should apply for core code as well.
Well, I was thinking about explicitly listing the available theme-specific tokens.
To validate this suggestion, I enabled the Token module on a vanilla core installation and it seems to me that when values are known in advance the Tokens UI lists them explicitly. Question marks are used when the suffix in not specified or can be a custom string.
Comment #47
neograph734Thanks, as you might have seen already, I had updated the assertions.
Since there can theoretically be an endless list of enabled themes, I felt the question mark approach would be more appropriate, rather than listing all themes. On the other hand, the patch uses the system names of the themes, which might be
I am however struggling because none of the core tokens seem to explicitly list the question mark, yet they show up in the list of available tokens (for instance the custom date format). So explicitly defining them seems to be wrong. On the other hand, the date tokens seem to list all available date formats including all custom ones.
Once I have figured out how they do it, I will try to put all themes in the list.
Comment #48
neograph734This should be listing the different tokens for all themes.
Comment #49
neograph734Hmm, that was a bit jumping to conclusions. I had tested this at the top level and assumed that it would work at a sub level as well. But the items to not show up. Cluttering the
site:*space does not seem to be nice either.So another idea. List the abailable themes in the description.
Comment #50
neograph734One small copy-paste error (site:token in the description of site:token-url) :(
Comment #52
ksujitha18 commented@Neograph734
Good effort!. But this patch has one bugs. Please refer below metnioed steps for testing scenario
1. Applied patch (2842780-50-token_for_site_logo.patch)
2. Go to Structure -> Content type -> Article
3. Click Manage fields -> Edit Body field
4. Click "Browse available tokens" underneath help text.
#BUG 1
Token displayed "[site:logo:?]" and "[site:logo-url:?]". It does not refer the theme name by default. Manually I have added the theme name in the token like "[site:logo:bartik]" & " [site:logo-url:bartik]". Then Logo and logo reference url - /drupal-8/core/themes/seven/logo.svg displayed great
#BUG 2
Incase I have omega theme it does not work like "[site:logo:omega]" & " [site:logo-url:omega]". Refer attached screenshots
Comment #53
plachI guess @ksujitha18 meant this :)
The RTBC status should be used when the patch is deemed ready for incorporation in the Drupal codebase.
Comment #54
neograph734Thanks @ksujitha18,
Bug 1 is not a bug, but this is by design. It does not seem to be possible to define 3rd level tokens without chaining them. This means that it is impossible to define all tokens like
[site:logo:<theme>]. The alternative[site:logo-<theme>]could work, but with multiple themes it would become harder to find other tokens like[site:name]. So it is[site:logo:?]. IMHO this is made very clear in the description:(There should have been comma's there.)
I will give Omega a try. Have you tried clearing the cache?
Comment #55
neograph734Tweaked the UI some more. List of available themes is comma separated, and the default token no longer has a question mark, but the description explains it can be chained with a theme name. The alternative option is to have them side by side and list [site:logo],
[site:logo:?], [site:logo-url] and [site:logo-url:?]. But for now that seems a bit too much. I think this will work.
I have changed the logic to obtain the logo, so it now also detects the default omega (and other theme's) logo, as well as overridden logos.
Comment #56
venkatesh rajan.j commented@Neograph734,
#55, works only for the default site logo [site:logo] and site logo URL [site:logo-url].
Unable to use tokens like [site:logo:seven] or [site:logo-url:?]. Refer the screenshot
Please correct me if I am wrong.
Comment #57
neograph734That is strange because the test passed... (And that requests the token for seven as well.) Did you clear the cache?
It might be because I have removed
dynamicfromsystem_token_info(). Could you try placing that back? (See the interdiff from #55).Comment #58
venkatesh rajan.j commentedAwesome... When I add dynamic to the system_token_info() function, it's working perfectly.
Can you add in the patch as well?
Comment #59
neograph734I will put it back in once I have some time. Thanks for testing!
Comment #60
venkatesh rajan.j commentedComment #61
venkatesh rajan.j commentedPatch attached
Comment #62
venkatesh rajan.j commentedComment #64
venkatesh rajan.j commentedComment #65
jeetendrakumar commentedHi Venkatesh
Can you please attach interdiff file?
Comment #66
venkatesh rajan.j commentedHi jeetendrakumar,
Interdiff file attached.
Thanks for reviewing...
Comment #67
berdirI'm not sure if the default token should really use the default theme or if it should be using the *active* theme?
missing function description.
Comment #68
neograph734@Berdir, initially it was the active theme, but the feedback was that that would lead to unexpected behavior when using the tokens for mails sent via the admin interface. In such situations mails would be sent with the admin theme logo, instead of the 'normal' logo.
I'll have a look at the function description this weekend.
Comment #69
berdirThat is a valid point, but it will also use the *templates* of the active theme then, unless you use mailsystem and its setting for the mail theme.
If you send e-mails, you could explicitly specify the theme you want to have the token from. But if you e.g. use this token in metatags or so, then you'd want to have it respect the active theme?
One option would to always require an explicit selection and have site:logo:default and :active?
Comment #70
neograph734Valid point. I supposed most sites will use only one theme, so the default theme will suffice. But you are right that the active theme should be respected as well.
Yes, I think that could work. It should not be that hard to add and the added value is significant. I will see if I can get it in.
Comment #71
neograph734I have been playing around with hook_token_info a bit and I guess this will be my new approach.
It provides a list of all themes as well as 'active' and 'default'. With below each item an
:urlsuffixed token. UI wise I think this is the cleanest approach so far. However to achieve the different levels, the code became a bit more complicated:I hope the added value outweighs the increased code complexity.
The next days I will work on implementing this and updating the tests. If for some reason you do not like this approach, please speak up now and safe me some work :)
Comment #72
neograph734Oke, here it goes. No interdiff due to the large architectural change.
Comment #73
tr commentedOne of the use cases frequently mentioned above is to use the new tokens to include a locally-stored image in an email. This is something that is not possible since #1494670: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send went in (almost two years ago), because now all URLs generated by core for local assets are relative URLs. And there is no way in core to force them to be absolute. Images can't/won't be shown in an email unless you can produce an absolute URL with the token.
So +1 for putting this in, but only if you can give us absolute URLs because email is one of the primary needs for these tokens.
There is a proposal in #2704597: Relative URLs in mails should be converted to absolute ones to fix this relative/absolute issue for email, but there has been little activity over there. I think the tokens should wait until that issue or something like it is resolved, otherwise you're going to see a LOT of bug reports/support requests/unhappy users of these new tokens when they don't work as expected.
Comment #74
plachDidn't look at the code yet but I'm definitely +1 on the new approach. Thanks for putting it together!
I'm wondering whether default and active are reserved theme names or we could have some clashes in those cases...
Comment #75
neograph734Well, https://www.drupal.org/project/active and https://www.drupal.org/project/default both show a 404 as of today, but it might be possible to register those names and install them in a site. We could do
drupal-defaultanddrupal-active, but then again there is nothing preventing people from registering those projects.Adding a separation for core and contrib themes could be an option, but that would involve yet another layer of token types and a more complex UI.
Comment #76
plachWould it be possible to implement something like the following?
[site:logo:active-theme][site:logo:default-theme][site:logo:theme:bartik]or[site:logo:theme-bartik]Comment #77
neograph734I started off with the
[site:logo:theme:bartik]approach, but I could not get[site:logo:theme:bartik:url]to show up in the token browser. After some searching it appeared that the token browser comes with a recursion limit that would prevent these 'deep' tokens from showing (they did work though).But to make sure all info would be visible for most of the users, I then went along the
[site:logo:theme-bartik]route.Comment #78
wim leersYes, let's fix #2704597: Relative URLs in mails should be converted to absolute ones!
Comment #79
plachNice work! I manually tested this with emails and the Token module and it works fine.
I found only a few mostly minor issues in code:
Shouldn't this say "active theme"? Also, the parentheses feel unnecessary to me.
Shouldn't this say "default theme"?
We should filter out hidden themes (e.g. classy or stable), as those are usually base themes and are not available in the UI, so no logo can be configured.
Surplus empty lines.
Does this mean we support also unprefixed names? These wouldn't be seen as valid tokens.
Missing
(optional)prefix and default description.Can we make this URL absolute, so that these tokens can be used in emails without waiting for #2704597: Relative URLs in mails should be converted to absolute ones?
Why aren't we supporting the global logo url?
Do we need to specify the langcode here? If this is not necessary I'd leave it out, as it's confusing.
Comment #80
neograph734Hi @plach, could you clarify some things before I start fixing them?
1. You want the entire message gone, or just the brackets?
4. Core already had an empty line there to separate the different token types, I see no harm in having them?
5. No, but if we always remove the first 6 letters, the
active-themetoken would break, so we only remove them if the token starts with it. (If you have a better option, please share as I too feel this is a bit hackish.)6. What default description is missing?
7. I'll try
8. Earlier I had problems with provided and required token types; eg. the 3rd parameter would always be a theme, this is a leftover of that. Ideally you don't want
[site:logo]to be used either as the other options are more predictable. But I do not believe I can block it.Comment #81
plach1: Just the brackets, thanks!
4: The existing space was not supposed to be there: https://www.drupal.org/docs/develop/standards/coding-standards#controlst... :)
5: Oh, I see, all good then
6: Optional parameters should always have a description of the default behavior, i.e. what happens when the parameter is not specified, if it's not obvious. In this case it would be something like:
By default a URL is returned.8: Got it, thanks
Comment #82
neograph734Here you go :)
Comment #84
neograph734Rebased
Comment #86
neograph734Apparently I should not be working anymore... I'll fix it tomorrow.
Comment #87
neograph734It seems my character encoding was off. Lets try it like this.
Interdiff is in #82.
Comment #88
plachThanks, we are very close to RTBC!
(here and below) Can we stick to single quotes for consistency?
[logo:url]is not defined in the token info.Can we store the absolute URL in
$logo_urlso that also the rendered image gets it?This comment does not wrap at column 80 properly.
Comment #89
neograph734Thanks for reviewing plach.
1. Yes, possible. But should I also adapt all other tokens? The original site and date tokens do it like this as well.
I'll change the rest.
Comment #90
plachI wouldn't touch the other token definitions, just the ones introduced by this patch. We just need to ensure the new code is consistent :)
We need to add also these two to bubbleable metadata, I think, as global settings and the default theme may change, which would require cached logo token values to be invalidated.
Now that I think about it, in the case of the
active-themewe also need to manually add thethemecache context, otherwise if logo tokens are used in cacheable contexts, e.g. node bodies, the active theme will be cached and subsequent request may get the wrong theme.Comment #91
neograph734I think I have got figured out like this:
theme_get_settingcan use either the global config or a theme specific implementation, so we need both configs. Only the default theme depends onsystem.theme, and active comes with a cache context.Regarding #88-2, It is more or less in line with #80-8.
site:logorenders the active theme logo, sosite:logo:urlshould return the active theme url. But that also already had a dedicated token. I think it would be better to not actively promote it, as the dedicated tokens are more predictable.Comment #92
plach#91 looks good to me, thanks!
If a token is not defined in token info, it cannot be validated, so it cannot be used wherever token validation is applied, e.g. user mail notification settings. If you strongly feel it shouldn't be promoted, then we should revert the change for #80.8 and not provide a replacement for it. The current state is confusing and inconsistent IMO :)
Comment #93
neograph734Self assigning. I am in the process of reworking the tests, so we can proper test if all tokens work. (I had some doubts on the active token test, and frankly the current test is quite messy.) I will implement some switches in active theme and default theme config and see if the tokens follow as expected.
It should be done by the end of this week.
Comment #94
neograph734I think this includes all discussed changes. Double quotes have been replaced by single ones, the
site:logo:urltoken has been removed. And the tests have been cleaned up and are readable now.However that are a few things I ran into.
This returns an image using the local path only:
<img src="/path/to/file">, rather than<img src="http://example.com/path/to/file">I cannot get the test to fail. I'd expect that removing all cacheable dependencies from
_system_tokens_get_actual_logo(and disabling their assertions in TokenReplaceKernelTest) would break, because the system should serve the same token again rather than recreate it (the metadata did not change). However all tokens output as expected.Test it like this:
And use this for any of the tests.
Howcome?
Comment #95
tr commentedYes, this is what I said in #73 above, as well as two years ago in the issue that broke this: #1494670-121: References to CSS, JS, and similar files should be root-relative URLs: avoids mixed content warnings & fewer bytes to send.
If you use
'#theme' => 'image'you will ALWAYS get a relative path for a local image, even if you specify'absolute' => TRUE.The only way to get an absolute URL right now is to explicitly write out the link as markup:
This is not a great solution, because then you don't get the attributes in the img tag that would normally be added by the theme function, but at least you get a working link.
Comment #97
xjmPlease only tag string changes after the issue is actually committed. Thanks!
Comment #98
neograph734Converting relative mails to full ones is covered in #2704597: Relative URLs in mails should be converted to absolute ones.
Comment #100
mgoncalves commentedI was testing the patch #94 and faced an situation.
All my files (including Logo) are being saved on CDN. When I try to see the logo information replaced by token, the following message is delivered on my screen.
"This image has been removed. For security reasons, only images from the local domain are allowed."
Is it the behavior expected ?
Thank you all.
Comment #102
stomusicPatch #94 updated for Drupal 8.7
Comment #103
alonaoneill commentedPatch applied on 8.8.
Comment #104
othmen commentedpatch #94 applied and worked for D 8.6.16
Comment #105
john cook commentedThe patch in #102 needs a re-roll for the 8.8.x branch. So I've set the "needs reroll" and "novice" tags for this task.
Comment #106
yogeshmpawarComment #107
joshi.rohit100Adding tag for DCD 2019 code sprint.
Comment #108
yogeshmpawarRe-rolled patch for #102.
Comment #109
anybody#2704597: Relative URLs in mails should be converted to absolute ones is fixed now (mentioned in patch #108 as comment).
Comment #110
tr commented#108 can't be RTBC because it doesn't even apply, "PHP 7.1 & MySQL 5.7 PHPLint Failed". You can't even try it out on your site without fixing this first.
The reason it fails to apply is a duplicate "use" statement in TokenReplaceKernelTest.php
Here is a new patch identical to #108 but with that duplicate "use" statement removed. I have NOT evaluated this patch to see if it solves the issue, this is just a re-roll to make the patch apply so the testbot can look at it and so it can be reviewed here.
Comment #111
mpp commentedCan/Should we also add a token for the admin theme?
Some nitpicks, mostly double quotes where we should use single quotes:
Use single quotes.
Use single quotes.
Use single quotes.
Use single quotes.
The logo of the active theme. Note that the administration theme may have a different logo.
'description' => t('The logo for the %theme theme.', [
'%theme' => $info->info['name'],
]),
===
===
Comment #113
dqdI am confused ... what has troubled me a lot since ages was that the logo always relied on theme settings only, but not on basic site info configuration settings as a general override, where users type in the name and the slogan. So does this token will change the logo path regarding the theme used when the token is present? Doesn't it cause cache issues? Especially when the theme changes under certain conditions? What about contrib modules which change logo under certain conditions or themes which use more than one logo for different styles (mobile, etc.?)...
Comment #115
mayurgajar commentedHi @ TR
patch #110 file : 2842780-110.patch apply cleanly LGTM +1 RTBC .
Thanks..!!!
Comment #116
dqdI still think this considerations are not obsolete yet. Would love to get some thoughts on it to let it go ...
@#115: Thanks for reviewing and reporting. But... I copied the paragraph from the OT for you. Do you have done precisely what has been listed here before setting it RTBC? Please provide more details in your review. Thanks.
Comment #117
dqdAnd for @#115: again: Apart from that please do not assign the issue to yourself while setting it RTBC. (It maybe happend accidently.) Just to let you know.
Comment #118
xjmThanks for proposing this feature. Since it is a new feature, I'm moving it to the 9.1.x development branch. I also queued a test against 9.1.x.
It looks like #111 could still be addressed. I also had a quick look at the patch myself and noticed a couple things. (Haven't done a full review.)
This is missing a data type.
Out-of-scope change.
"Pay attention" seems a bit adversarial. Maybe:
Nit: Theme-specific.
Can we more specifically describe the data type of the array? It is maybe
array[]orstring[][]ormixed[][]depending on the data structure of the returned config -- we could check the called method to see exactly how the data is structured.Comment #119
kishor_kolekar commentedComment #120
kishor_kolekar commentedAddressed #111 and #118
please review the patch.
Comment #121
kishor_kolekar commentedComment #122
IhorMaster commentedHello everyone!
I had the same issue with creating a token of site logo and tried to use patches from this topic. But into all of them use function theme_get_setting() and this function is deprecated in Drupal 8.7 and Drupal 9.
So I created new patch without function theme_get_setting(). I have tested this path with different themes and all ok for me.
Please, check my patch.
Comment #123
neograph734Hi Ihor,
Your patch is removing a lot of functionality that was added before, which has all been addressed in this issue. There is a patch for Drupal 8.8 in #110, in which you could have simply replaced theme_get_setting?
But since this is feature request, it should be tested against 9.1 as xjm explained in #118 (and there is a patch in #120). Once it is in Drupal 9, we can focus on the backport to 8.
If you want to help push this issue forward, please help testing the patch from #120 with Drupal 9.
Comment #124
samiullah commentedApplied the patch #122 on drupal 9.1x
Was able to see site logo token
If there is more code review needed, after that it can be moved to RTBC
Comment #125
neograph734Hi samiullah, please review #120, which is much more complete. Thanks
Comment #126
samiullah commented@neograph that one looks better. Probably a code review is needed before we can move it to RTBC
Comment #128
neograph734Well, I had a fresh look and I found some strange things that should be looked into.
Feedback on the patch from #120.
Let's move this below all logo tokens and just before the date tokens where it is used.
This comment does not really match the token.
Site logo property tokens.
Since the patch evolved and we have much more control over the selected theme, this fallback makes no sense anymore (perhaps it never did). It can even lead to unexpected behavior. Besides, theme_get_setting() already defaults to the global configuration if the theme does not provide one.
I think this should be enough:
$logo_path = theme_get_setting('logo.url', $theme)This issue is closed by now, so let's make use of it. For the images, relative paths should be save to use again. SystemBrandingBlock does it like this:
However for the URLs we should still make use of the absolute path (I can not imagine a use case for a relative path as token). So it could become something like this:
This now feels like two unrelated sentences. Besides, I think it would be out of scope for this patch.
Do we really have to test that the active and default theme tokens work for both bartik and seven coming from $subsequent_tests? Even for the testSystemSiteLogoThemeTokenReplacement I think one theme might be enough? (Also see next comment)
This is an odd one. It was supposed to be a data provider, but it also does things.
I think installing one theme and one configuration (removing the need for foreach in the above comment) should be enough and can be handled within the three tests themselves. (Or test during test setup).
Comment #129
neograph734Well, I just did one round of cleanups. Tests are combined to 2 and the awkward data provider has been removed. Furthermore it made more sense to use
file_create_url()instead ofUrl::fromUserInput($logo_path, ['absolute' => TRUE])->toString().When testing, please also include it in an email to verify that #2704597: Relative URLs in mails should be converted to absolute ones indeed works.
Thanks for all effort so far. Let's make sure this makes it into Drupal 9.2 :)
Comment #131
neograph734Using assertStringContainsString instead of assertContains for string comparison...
Comment #133
neograph734Perhaps I should not do these things that late..
The change
file_create_url()instead ofUrl::fromUserInput($logo_path, ['absolute' => TRUE])->toString()was passing all test, but resulted in a root relative URL, not an absolute one. So I had to revert that change.Apart from that, I think this is much cleaner than what I originally built.
Patch has been tested with emails, and I can confirm that #2704597: Relative URLs in mails should be converted to absolute ones works. It was however a bit tricky to get it working as that patch only acts on markup (so you cannot use the account created/cancelled/ etc mail). So In the end I used token_filter, simplenews and swiftmailer to include it in a newsletter (make sure that you enable HTML for both swiftmailer, simplenews and the newsletter bundle).
Followup issue to make this display everywhere #2855653: FilterHtmlImageSecure filters out valid local svg images.
Comment #134
abhijith s commentedApplied patch #133 .It works fine. There will be tokens available for site logo and site logo url after installing this patch.
Including screenshots

before patch:
after patch(tokens available):

after patch(tokens output):

RTBC
Comment #135
paulocsFixing Drupal code standard.
Comment #137
neograph734Patch still applies to 9.3. Back to RTBC based on #134.
Comment #138
alexpottThis looks really odd. Yes it is equivalent to
but I don't think the changing it to this is really worth it.
How about being explicit and doing...
Ahhh I see you're doing the same here. I can see the benefit here but it still looks really odd. Do we have other examples of this format in core?
Earlier in the same test we do
Which, to me, looks as readable and less surprising than what's in the patch.
The multiple assignments were introduced in #94 and have not yet been discussed in the comments as far as I can see.
I'm not really sure... about this going to leave at RTBC and solicit more opinion.
Comment #139
alexpottDiscussed with #138 with @catch and neither of us are particularly keen on multi-line multiple assignments. Let's see if there's another way of doing this.
Comment #140
AnnaE1990 commentedI'm using a modified Bootstrap Barrio 8.x-4.28 theme. in the registration e-mail of the new user the website logo should appear but it looks:
"
img src="/sites/default/files/logo2.0_1.png" alt="" typeof="foaf:Image"
AnnaEjankowska
Dziękujemy za rejestrację na stronie e-jankowska. Twoja prośba o utworzenie konta oczekuje na zatwierdzenie. Po zatwierdzeniu otrzymasz kolejny e-mail zawierający informacje o tym, jak się zalogować, ustawić hasło i inne szczegóły.
-- Zespół e-jankowska
"
instead of the displayed image.
I use the swift mailer to send e-mails.
core drupal 9.2 PHP 7.4
a screenshot of the settings for shipping.
How to fix this issue?
Comment #141
tr commented(You need to format your post with the "code" formatting so drupal.org displays the raw output without the HTML tags escaped.)
@AnnaE1990: Drupal core does not directly support HTML email, that functionality is provided by contributed modules. If your email is not displaying the HTML correctly that's a problem with the contributed module you're using (swiftmailer). That's unrelated to this issue. If you type in an image tag directly instead of using the token you would see the same result.
This issue is about making the token available and making sure the token has the right value. I think your post is saying the token has the value
<img src="/sites/default/files/logo2.0_1.png" alt="" typeof="foaf:Image">, which appears to be basically correct except it's a relative URL instead of absolute. I raised this as a major problem more than 3 years ago in #73, and I'm disappointed that this problem hasn't been addressed yet.Comment #142
AnnaE1990 commentedthere is a fresh module, and its working fine https://www.drupal.org/project/simple_html_mail
Comment #143
neograph734Implemented the feedback from #138 and #139. Added some empty arrays to better match with the other tests too.
Comment #145
neograph734Obviously that was all just stacking up instead of starting from scratch. I think this is better to understand rather then a whole bunch of clones.
Comment #146
darvanenThis is powerful.
Is there a way we can make this a more systemic change?
(Note: I'm still familiarising myself with the deeper token sysetms)
Comment #149
anybodyTo push things forward here and as @alexpott's comments from #138 have been addressed in #145 settings this RTBC.
Any further thoughts or issues? Otherwise, I think we could try to finish this nice feature after > 5 years? :)
LGTM!
Comment #151
anybodyComment #152
neograph734I think the order of cache tags has changed, so the array is no longer an exact match. Adding a patch with a changed order just to be sure. (Changes the order in lines 281 - 283).
Comment #153
anybodyThanks @Neograph734, yes indeed. Could you please include an interdiff to be sure? Thanks!
Comment #154
neograph734I think it is a bit more complicated than initially assumed. I think this is no longer applying because Bartik has been replaced by Olivero... So some more time is needed for a proper reroll.
Comment #155
neograph734Let's see what this does.
Comment #156
neograph734Comment #157
neograph734Funny how these patches do apply locally... :s
Comment #159
neograph734It turns out that all instances of REQUEST_TIME have been updated. This was causing 152 to fail. No other big changes have been done. Nevertheless, now all occurences of Bartik and Seven have been updated to be Olivero and Claro instead.
Comment #160
neograph734Awesome!
No significant changes, as can be seen in the interdiff. Restoring the RTBC from #149.
Comment #161
alexpottWhat does "Nesting for more options." mean?
$name = str_starts_with($name, 'theme-') ? substr($name, 6) : $name;Easier to read and with have PHP 8 polyfill on D9.
I think we should have one function to get the logo url for the provided theme and another function to get the rendered logo.
I'm also not convinced that we should renderPlain here. I think we want a markup object so the token system knows this is markup and does the right thing with it in different contexts. See #2580723: Fix token system confusion, with new function Token::replacePlain() for more about this.
I also wonder what we should do for accessibility. I think the rendered image should have alt text.
Comment #162
alexpottWe should use primitive typehints here...
_system_tokens_get_actual_logo(string $theme, BubbleableMetadata &$bubbleable_metadata, bool $render = FALSE) {Also the _actual in the function name does seem to add anything to me.
Also See above - I think this function should be split into two functions so the return value is consistent.
Plus we should be using return typehints too.
Comment #163
pradhumanjain2311 commentedComment #164
pradhumanjain2311 commented@alexpott i add primitive typehints in _system_tokens_get_actual_logo function as per your comment #162.
But other changes like function should be split into two functions so the return value is consistent.
Plus we should be using return typehints still remains.
Comment #165
neograph734@alexpott feedback addressed. I am only not sure what you meant with this:
\Drupal::service('renderer')->renderPlain returns a MarkupInterface object, so that should be good right? I'd like to remain as close as possible to what is happening in SystemBrandingBlock::build().
Comment #166
neograph734Comment #168
neograph734Ah, I thought I had only changed the function signatures so the test should still apply. But the alt attribute had to be added to the test as well.
Comment #170
nod_The logo is not defined in the site settings (as in, on the
/admin/config/system/site-informationpage).The token should probably be
[theme:logo]instead of[site:logo:...], it will avoid having to do the default-theme/admin-theme dance.Comment #171
neograph734I think that would make it even more unpredictable. What theme will be used in such case? And the site token is already an exsiting container. As I user I would expect to find the logo there.
Comment #172
nod_Comment #173
darvanenWith regards to #170 vs #171:
The description of the
sitetoken type isAs the logo is not a site-wide setting I believe this token falls outside of the scope for that token type.
Having a token type specifically for the logo seems rather restrictive, and though there are some examples of single-purpose token types I think the introduction of a [theme] token type would be more extensible.
My vote would be for this kind of structure:
to which you could add any of the following suffixes:
and provides the capacity to access such things as favicons and breakpoint settings IF such things were deemed necessary to be accessed by non-developer site builders and users.
This is a big scope change though, and the introduction of a new token type in core is not to be taken lightly. If the above structure were accepted it may be best to move this effort to the token module instead.
So, questions:
Comment #174
tr commentedOh come on. This is a long standing REGRESSION - we used to have a site token for the logo in D7 and this was left out of core when the Token module was partially merged into core. It's lost functionality, not a "new token type". It shouldn't take 5 years to restore that lost functionality, and you're not helping by throwing a monkey wrench into the process.
Comment #175
nod_I can understand both points of view here.
The main problem to me is that there is no module maintainer that can make the call and live with it afterwards by providing support/guidance on what to do on the long term.
I don't have any skin in this issue and while it's unfortunate that it probably means this issue will stall I'm postponing it on the fact that there is no maintainer for the module.
If someone really wants this to move along I think the only solution is starting to look at the token queue and applies for maintainership of the module. I can't help maintain the module but I can help navigate the process so anyone is up for it and wants to talk about it, feel free to ping me :)
Comment #176
berdirNo need to get emotional but I do agree that this doesn't need a new token type. The proposed structure doesn't work quite work, you can't have theme be two different things and a token that then depends on the current theme is just as global as "site".
I don't think we postpone single issues over not having a maintainer. This has been RTBC, and there was core maintainer feedback from @alexpott in #161, someone needs to verify that this has been addressed and if yes, can be set back to RTBC.
Comment #177
adamps commentedThat's a very interesting point.
On the other hand, may of the existing tokens such as [node:body] have output that depends on theme. In these cases, the current theme is used. Every part of the page even is rendered in the current theme - which can be switched if needed. If we describe the logo token as "the logo from the current theme" then arguably it is global information. It's not really clear me what the use case is for displaying the logo from a different theme when everything else is from the current theme.
I feel there are good reasons for sticking with the simpler [site:logo]. It's easier to understand, it avoids creating a new token type, and it matches the way it worked in D7.
Comment #178
gaurav-mathur commentedComment #179
gaurav-mathur commentedPatch #168 applied successfully on Drupal 10.1.x-dev.
The patch work properly for me.
Refer to screenshots.
Comment #180
darvanenConsider me convinced.
I have reviewed the patch against the feedback in #161 and #162.
162 is complete except for:
which means this needs to go back to NW for that. So while I'm doing that I'll note one nit:
As much I would prefer to do this kind of cleanup as we go, core committers seem pretty strict around not including unrelated changes (I think it's a slippery slope problem, I can see where it could become a problem).
Comment #182
anybodyThis needs a reroll against 11.x-dev now. #168 doesn't apply against 10.1.x for me?!
Comment #185
rpayanmI rerolled #168
Comment #186
rpayanmComment #187
neograph734Back to NR
Comment #188
smustgrave commentedGoing to mark it but left 1 comment in the MR for the committer.
Comment #189
neograph734FYI, casting to string is a requirement for assertSame. See the link in failing test of #184.
Comment #190
anybody@smustgrave see #189, perhaps that comment can be resolved?
Attached MR!4236 diff as static patch, if anyone needs it!
Comment #191
quietone commentedI am doing triage on the core RTBC queue.
I read the issue summary. There is a proposed resolution so reviewers know what to look for. However, the remaining tasks show another issue, is this issue supposed to be postponed on that or is a follow up needed?
This is adding tokens so there should be a Change record. This should include examples. I am adding the tag and setting to NW.
I then read the comments, mostly trying to find unanswered questions. Its that @Neograph734 did a very nice job keeping up with the feedback. It is hard to follow but I think everything has been responded to expect for two items.
1) There was concern about emails, #17. I am not sure if that was resolved. Or does this need documentation, including the CR, on how using these new tokens with mail will work.
2) Should be using a site-wide token, #173 - #180. In #176 @Berdir stated the proposed structure wouldn't work and there has been no other response from them on the subject. Has this truly been resolved? If that has been resolved it is worth adding a summary of that discussion in the Issue Summary so that it is clear for a committer.
I then read the MR, I did not do a code review. I spotted some things that need changing which I have commented on in the MR.
I am removing the 'Needs maintainer tag' because I think that intention is covered by 'Needs subsystem maintainer review' and it is not a defined special tag.
This is long issue in comments as well as time (7 years), thanks everyone for getting the bulk of the work done. Just a few more things to do.
Comment #192
atul4drupal commentedI tried to read through the thread to understand it, and as far I understood for #191 point 2:
@Berdir I believe is responding to the proposed suggestion for having seperate token type to which he disaggred, and that is something still not addressed as we see a new token type "site-logo" being introduced in the code.
Also @Berdir expressed for someone to verify if suggestions from #161 are implemented which I verifed have been incorporated and this was also verified in #180.
#191 point 1 (refering #17) this I think will relate to what approach we take with respect to the concern raised around introducing new token type, as in the current solution if we take off the new token type, #17 remain open.
It is a situation in hand, will spend some time on it however some direction around how to address #17 will be helpful, keeping in mind that people in general are not inclined towards introducing a new token type.
Comment #193
atul4drupal commentedAdding patch to update changes as suggested in #191.
Still have a few open TODO items on the issue:
1) Decide on an approach to address concern raised in #17 (possibly without adding new token type). If new token type needed then this need to be discussed and agreed upon before moving forward with this approach.
2) IS to be updated
(leaving this for someone who has more hold on this issue thread, will revisit to update IS if not updated in some time).
Comment #194
gouthamraon commented#168 patch is not applying with the Drupal 10.1.5 version.
Issue with kernal test changes. Updated the changes and adding the new patch.
Comment #195
_utsavsharma commentedFixed failures in #194.
Comment #196
anybodyFinally I gave up the hope that this will ever be finished by anyone (including me). So maybe we should better put our time into implementing a contrib solution?
Maybe in https://www.drupal.org/project/theme_tokens?
Seems there are enough people here to do that...
Comment #199
jeroentI fixed the feedback in the MR.
Comment #200
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #201
jeroentThe tests were failing because the token hooks moved to a hook class.
Tests are now green again.
Comment #203
smustgrave commentedThere was already an MR for 11.x should continue there
Comment #204
jeroentMerged 11.x-dev back into the Merge request !4236
Comment #207
grevil commentedCurrent MR doesn't apply to latest 11.x any more. Rebasing is quite cumbersome, because the changes here conflict within themselves. Also there will be new conflicts for every new commit to 11.x now...
Comment #208
smustgrave commentedWe actually don't have a token sub-maintainer so bumping to framework.
Can 1 MR be closed or hidden that's not for 11.x
4236 is 200+ commits back so probably will need a rebase at some point.
CR still appears to be needed
Comment #216
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #218
jeroentRebased the MR on 11.x.
Comment #219
grevil commentedRTBC! Works great and as expected for latest 11.x-dev.
Regarding #191:
No, the issue summary is fairly old. Both "default-" and "active-theme" works as expected.
If a user wants a specific theme logo or the default logo instead of the active theme logo, he can simply use the [site:logo:default-theme] or [site:logo:theme-my_theme] to specify the logo he wants.
The disussion was about adding new token types, but I think it was specifically about adding a "theme" type, as theoretically there are new token types added ("site-logo" and "site-logo-properties"), but they are mainly there to simply resolve to when using tokens such as [site:logo:default-theme] through "$token_service->findWithPrefix". So we don't really add new types but just new subtypes of "site".
TLDR: IMO, this is solved as well.
I'll create the change record and update the issue summary.
Comment #220
grevil commentedComment #221
grevil commentedCreated the change record here. That should be it! RTBC!
Comment #222
grevil commentedTests fail now, maye because of removing the (string) type casting.
Comment #223
grevil commentedAlright all done, back to needs review because of the new adjustments.
Comment #224
anybody@quietone: @Grevil addressed your comments, could you see if they are fixed?
Would be great to get this one finished finally... :D
Comment #225
anybodyCurrent status as static patch. Setting this RTBC for now as everything worked fine in my tests, but see my comment in #224 - would be great, if the framework manager could take a look and someone with permission could close the resolved GitLab comments. Thanks!
Comment #226
quietone commentedI had a go at updating credit, always a challenge on older issues with lots of comments.
Comment #227
alexpottI think we need some usability input on the correct alt text here - or whether we should not have any at all. Note that the alt text was added due to my comment in #161 - but there was no subsequent discussion for what the alt text should be. I think in order to move this issue on we should remove the alt text here and file a follow-up to be reviewed by the usability team for what the alt should be and how it should work.
Comment #228
anybodyHopefully this can finally get smashed? ;)
Comment #229
anybodySorry, this is not a bug. My mistake. Still waiting for reply from @alexpott, but would be super happy to get this DONE finally.
If it's fine to add this for Bug Smash Initiative please re-add. Sorry!
Comment #230
grevil commentedI agree with @anybody here. IMO, no alt text at all isn't good either.
We have a similar case in core, where the Drupal logo isn't perfect @core/modules/system/src/Plugin/Block/SystemBrandingBlock.php:
I'd say we leave it as is and create a follow-up issue, where we add the ability to change the alt text for both the Branding Block and this token.
Comment #231
alexpottI think we should remove and open a follow-up. I think wrong and redundant alt text is more harmful than no alt text to humans. Yes we'll probably do pass tests on checkers which just test if alt text exists rather than the quality but we should care about humans more than automated checkers.
Comment #232
alexpottFWIW I should have asked for a follow-up to discuss alt text back in 2022 #161... as this debate in this issue is all my fault. Sorry.
Comment #233
grevil commentedI removed the alt text, replaced the deprecated "theme_get_setting" call and rebased the issue fork.
Comment #234
grevil commentedCreated the follow-up issue here: #3554559: Add alt text configuration for the site logo (and [site:logo] token).
Comment #235
anybodyThank you very much for finishing this @grevil and creating the follow-up! I left a comment there, but that's out of scope here.
Back to RTBC then. @alexpott should we remove the Needs framework manager review tag? Is all fine then?
Comment #236
anybodyPS: Regarding
theme_get_setting()deprecation (https://www.drupal.org/node/3035289 - #3035288: Deprecate theme_get_setting()) please note that the minimum core version for this fix will be the same as over there - or we'll have to revert that for the cherry-pick!Comment #237
grevil commentedTests fail.
Comment #238
jeroentFixed the failing tests.
Comment #239
anybodyThanks @jeroent!
Comment #240
amanire commentedGlad to see this issue moving forward. Another good use case for this token is Schema.org Metatag.
Comment #241
anybody@quietone @alexpott this needs a reroll again. Do we have a chance to finally review and eventually merge afterwards for finishing? :)
Comment #242
grevil commentedNew rebased patch attached.
Comment #244
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #245
anybodyRebased. Everything green again!
Comment #246
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #247
anybody@nod_ everything is green, so I think the testbot sets it to NW because it has "Needs framework manager review"?
Will this be reviewed by the framework manager automatically?
The issue is 9Y old and has much activity so I think we should be happy if it can be resolved finally?
Comment #248
smustgrave commentedDid not review. HEAD was broken so it tricked the bot
Comment #250
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #251
anybodyComment #252
larowlanFrom a framework manager point of view, I don't think this fits the 80% use case. Additionally it can be achieved in contrib - the MR shows that the existing token APIs/hooks don't prevent this from living in a contrib module.
I realise a lot of effort has gone into this, but I don't think in our new Product (Drupal CMS) vs Framework (Drupal Core) world that this is a framework feature. I'll poll other committers including product managers - but from my point of view I think we should encourage this to live in contrib.
Comment #253
neograph734@larowlan, My personal argument is that all other elements from the system branding block (site name and slogan) are available as site tokens provided by core.
Those are defined in a different config, but they are displayed as one.
Also modules such as Metadata might benefit from this patch by having the site logo easily accessible(?).
Comment #254
anybodyI have to agree with @Neograph734 (#253) while this is definitely worth the discussion, I also think the benefit is large enough, a lot of work went into this and we for example need this in nearly all projects (everywhere Metatag module is used - which is quite a lot).
So I'd vote to add this in core.
P.S.: I think the fact that so many different users are active here is also very good evidence.
Comment #255
darvanen@Anybody may I ask how many of those sites don't have the token module installed?