Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently theme.inc only looks for logo.svg. Themers would like to support other filetypes such as png, jpg, gif
The plan is to support this by letting theme developers define the path to the logo in the themename.info.yml file. This way, we can override the default path (currently logo.svg) and the format.
Remaining tasks
Finalize the featureAdd test coverageCreate change recordUpdate the documentation page- Commit the patch
Comment | File | Size | Author |
---|---|---|---|
#100 | 1507896-100.patch | 5.64 KB | tuutti |
#100 | interdiff-1507896-97-100.txt | 2.99 KB | tuutti |
#97 | 1507896-97.patch | 3.38 KB | Jeff Burnz |
#88 | 1507896-87.patch | 3.72 KB | Jeff Burnz |
Comments
Comment #1
realityloopThis patch checks favors less lossy formats over lossier formats.
Would we get any benefit from caching the result and checking for variable instead of checking on every load?
Comment #2
RobLoachWill all those file system hits hurt performance? Maybe we should set default_logo on a per-theme basis explicitly?
-1 days to next Drupal core point release.
Comment #3
realityloopYes, thats why I asked about caching the result somehow
Comment #4
brahmjeet789 CreditAttribution: brahmjeet789 commentedYes !! if i added any .jpg or .gif image in my theme to use as Logo,my site would show a blank screen without adding this patch .After adding the patch the site working fine due to this patch. Its working fine now.
Thanks :)
Comment #5
realityloopImproved with use of cache so file_exists only gets called once until next cache clear.
Comment #6
realityloopI have a D7 version of the patch ready too if we want to backport it
https://dl.dropbox.com/s/jwdto3b0mx26wzd/1507896-allow-other-filetypes-i...
(dropbox link to stop testbot from D7/D8 mixup)
Comment #8
realityloop#5: 1507896-allow-other-filetypes-instead-of-only-logo.png-5.patch queued for re-testing.
Comment #9
cafuego CreditAttribution: cafuego commentedDo you think that logo.png should be the last option in the case list? It's the default now, so any other file the user drops in will automatically act as an override if it checks for logo.png last.
Comment #11
droplet CreditAttribution: droplet commentedI'd like to close it as "works as designed". It assumed logo.png is the default logo to all drupal themes. if there're different name or filetypes, custom logo is your choose.
Comment #13
Topplestack CreditAttribution: Topplestack commentedI am interested in this as well, for instance, I would like to use an SVG as my main logo, but I would like it to fall back to a png for older IE browsers.
Comment #15
rkendall CreditAttribution: rkendall commentedCould I suggest an alternative approach? How about instead of hard coding the logo filename we instead specify it in the theme .info file.
For example:
features[logo] = logo.png
Then if I want I can change that to:
features[logo] = my-company-logo-200px.jpg
Personally, I find it annoying that I have to name the logo file 'logo.png' even when I am happy to use a .png file.
I guess in some ways this is an additional suggestion to the above, as it could always default to logo.* when not specified.
Thanks,
Ross.
Comment #16
rkendall CreditAttribution: rkendall commentedre-reading the thread, I think that was the kind of thing Rob Loach was suggesting as well (at #2).
Comment #17
kajeny1 CreditAttribution: kajeny1 commentedThanks for your great post also thanks for that your giving us great information on logo.png
Comment #18
mgiffordIt's been almost a year since there's been any movement on this issue. It would be great if it could be part of D8 and possibly backported to D7.
It seems like adding more SVG support to themes would have lots of benefits - http://net.tutsplus.com/tutorials/why-arent-you-using-svg/
EDIT: Also adding link to http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/getting-starte... as there are advantages for mobile devices.
Comment #19
LewisNymanThere's a reliable technique for falling back from SVG to PNG here.
I think that might be out of scope of this issue though. Let's just recognise other file types and create a follow up to add a fallback method.
Comment #20
Hanno CreditAttribution: Hanno commentedIf we want to provide a fallback for svg, isn't it better to create an extra variable for a svg logo, instead of allowing more file types?
It would be nicer when a png or jpg version for older browsers is automatically renderd by Drupal out of a svg. Sadly that's not possible with imagemagick nor modernizr. It is possible with nodejs but that's not in core. http://eng.wealthfront.com/2011/12/converting-dynamic-svg-to-png-with.html
Comment #21
LewisNymanSo Drupal 8 doesn't support no SVG browsers any more, so we don't need to provide a fallback method in core.
Comment #22
Hanno CreditAttribution: Hanno commentedIf SVG is supported we could move away from png and switch to vector based logo.svg as a standard?
Comment #23
LewisNymanI think we should still allow people to choose PNG, just for themers that might not have access to the SVG versions. That's definitely happened to me before! But the good news is we don't have to accommodate a fallback method, it would be easy for contrib to implement.
Here's a reroll of the patch from #5
Here's a screenshot of the patch in action, I just added an example logo.svg to Bartik.
Comment #24
realityloopyay for not needing fallbacks.
Comment #25
alexpottThe problem is that this will possible do upto 4 additional file_exists checks per request. The cache you are setting here is a static cache.
Comment #26
realityloop@alexpott can you possibly suggest a better way to implement it please? I'm happy to do the work.
Comment #27
LewisNymanI had a go wrapping the logo url in a cache object but mysql broke before I could test it (again). Here's how far I got.
Comment #29
droplet CreditAttribution: droplet commentedIt's cool but I have no idea why we're making CORE such complexity. We can register a new Logo easily in own theme or through yml settings
Comment #30
LewisNymanNow that I am able to test this patch, it seems like Bartik is loading the Seven logo. So I guess we would need a separate cache for each theme?
Comment #31
LewisNyman#2142653: Change default logo filetype to .svg and add an SVG version of Druplicon has been committed which changes the purpose of this issue slightly
Comment #32
mgiffordHere's a reroll that should help nudge this along.
Comment #33
alexpottLet's not do the whole file exists thing but allow theme developers to add the default logo filename to the theme's .info.yml
Comment #35
itapplication CreditAttribution: itapplication commentedComment #36
akalata CreditAttribution: akalata commentedRemoving unnecessary tags (per [#1023102]).
Comment #37
akalata CreditAttribution: akalata commentedComment #38
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedLets see how this goes..
removed logo quite a few bits of old logo code, most likely didnt find all of the code that is now obselete
not attaching interdiff as its compeletely different
with patch you're able to set logo through THEMENAME.info.yml example = logo: abc.png
Comment #39
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedaand forgot my hardcoded test value in bartik.info.yml... new patch.
Comment #40
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedcancelled tests, misreaded issue as we only want themers to be able to add default file name to info.yml, so need to re-add the code that allows uploads thru UI,
also now that i think of that cache statement is useless there.
Comment #41
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedMaybe it works now..:P
Comment #42
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedbot to work.
Comment #46
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedfixes exceptions and probably tests
Comment #48
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedfixes tests
Comment #49
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedUnassigned ticket.
Comment #50
joelpittetI don't think the property_exists condition is needed. Otherwise this looks good to go.
@see http://3v4l.org/qVbYK
You'll notice it actually throws notices on line 14 where it doesn't when you don't check the property.
Comment #51
mducharme CreditAttribution: mducharme commentedComment #52
darol100 CreditAttribution: darol100 as a volunteer and commentedFixing status because there is a patch.
Comment #53
joelpittetSetting as needs review for testbot.
Comment #54
lauriiiComment #55
tuutti CreditAttribution: tuutti commentedAdded tests for logo path.
Comment #56
umarzaffer CreditAttribution: umarzaffer at Srijan | A Material+ Company commentedWhile reviewing this I:
1. Applied the patch.
2. Made changes to .info.yml of bartik theme and specified logo value to screenshot.png.
3. The new logo reflected properly.
4. Ran tests using Testing module interface on Theme/ThemeSettingsTest with zero errors/warnings returned.
Comment #57
alexpottLet's add a getLogo method to the activeTheme class and populate it during theme initialisation and then move this logic into that method.
Also I think under the beta evaluation https://www.drupal.org/core/beta-changes this might need to be postponed to 8.1
Comment #58
cbanman CreditAttribution: cbanman at Acro Commerce commentedMade change suggested in #57.
Comment #59
cbanman CreditAttribution: cbanman at Acro Commerce commentedComment #60
Anonymous (not verified) CreditAttribution: Anonymous at Druid commentedlooks good
Comment #61
opratr CreditAttribution: opratr as a volunteer commentedLooks good. RTBC+
Comment #62
lauriiiThanks for working on the issue and sorry for the nits :)
This is a getter method so it should be documented starting with "Gets"
Just a nice thing to have would be a extra line change before return :)
Maybe we could document this a little bit more accurately
Comment #63
umarzaffer CreditAttribution: umarzaffer at Srijan | A Material+ Company commentedComment #64
cbanman CreditAttribution: cbanman at Acro Commerce commentedMade changes as per #62.
Comment #65
cbanman CreditAttribution: cbanman at Acro Commerce commentedI don't see how this is in need of a re-roll.
Comment #67
cbanman CreditAttribution: cbanman at Acro Commerce commentedI guess I reacted too soon. Sorry, re-roll it is.
Comment #68
umarzaffer CreditAttribution: umarzaffer at Srijan | A Material+ Company commentedHave re-rolled the patch along with recommendations in #62.
Thanks
Comment #69
lauriiiNow this looks good to me :) Sorry for the interruption here!
Comment #70
lauriiiSorry I didn't review other things yet.. Still something to figure out.
Comment #72
lauriiiThis doesn't match beta evaluation. Pushing to 8.1.x
Comment #73
star-szrWe would need to do this in a backwards compatible way.
Comment #75
joachim CreditAttribution: joachim as a volunteer commented> We would need to do this in a backwards compatible way.
To me that says 'needs work' as in 'needs a rethink' rather than postponed.
Comment #77
manumilou CreditAttribution: manumilou commentedI re-rolled the patch for 8.3.x.
I had to adjust unit tests to make them use file_url_transform_relative function, which is now called in theme.inc as well to generate the logo url.
It seems backward-compatible to me, but I may be missing something here.
Comment #78
manumilou CreditAttribution: manumilou commentedComment #80
oakulm CreditAttribution: oakulm as a volunteer commented- applied the patch: allow_theme_developers-1507896-77.patch
- made bartik child theme with these instructions https://www.drupal.org/docs/8/theming-drupal-8/creating-a-drupal-8-sub-t...
- added logo.png to theme folder
- added line "logo: logo.png" to theme.info.yml
I can confirm that the feature is working as intended.
Comment #81
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedComment #82
oakulm CreditAttribution: oakulm as a volunteer commentedComment #83
xjmMinor nit: This line is one character over the max line length, so we need to wrap another word here.
Is this logo key a schema addition for the theme info file? We would probably need to add documentation for it somewhere.
Also, it's not a "configuration" file, is it? As in, it's not simple config or a config entity as managed by the configuration system. We should change the variable names if it's not to avoid confusion.
Other than that, this looks like a good feature addition to me. It appears backwards-compatible and safe for a minor version (8.4.x at this point). I have not yet reviewed the test coverage in full, but I'd like to get one of the theme maintainers' signoff here based on the earlier discussions. So one of @Cottser or @lauriii.
Also, we still need that change record.
Thanks everyone!
Comment #84
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedFix for #83-1
Comment #85
tameeshb CreditAttribution: tameeshb at Google Summer of Code commentedMade interdiff.patch by mistake, .txt attached here...
Comment #87
tuutti CreditAttribution: tuutti as a volunteer commentedIt's
Drupal\Core\Extension\Extension
object, so maybe $extension or $file_info would make more sense?ThemeSettingsTest::testLogoConfig()
is indented incorrectly with 3 spaces and is missing an empty line before the closing bracket.assertIdentical() is deprecated and might be good idea to replace them with assertSame() or assertEquals().
Comment #88
Jeff Burnz CreditAttribution: Jeff Burnz commentedI was looking at this patch and this seems a big inconsistent with how everything else uses the constructor values from getActiveTheme(), after looking at this I wondered if we could creep this a tad and make logo's inheritable. The reason I ask is that I often work on big projects with multiple skin type themes, all use the same logo etc.
I've whipped up a patch as a PoC, and sorry I don't mean to throw a spanner in this issue as it's coming along nicely and a tad overdue already, it's just a thought that this should at least be passed from getActiveTheme(), and could we do inheritance (which would be a nice feature I think).
This is like only the second patch I've written for D8 so please excuse if I've duffed somewhere here. No test incl.
Nice work everyone!
Comment #89
eiriksm@Jeff Burnz I think that looks way cleaner, and makes things way more intuitive, while still achieving what we want in this issue.
Patch works and looks great as well. We should probably add tests though. I can whip up some quickly if you don't want to?
Thanks to everyone working on this.
Comment #90
AdamPS CreditAttribution: AdamPS commentedLike many on this thread I am keen to see this issue committed. We are really close now. There has been a lot of work to create the existing patch, pulling in feedback from many people to build a consensus that has been well tested and reviewed. We have got to the stage of reviewing at the level of "minor nits".
Regarding comment #88, I can see that inheritance would be a bonus. Can we creep to add it in? Personally I think no, that should be a separate issue, which validly incrementally builds on what we have here. We are too close to completion here to make significant additions. However even if consensus is that we do creep, it must be done very soon, with a patch that is very closely based on the work so far, with a small addition for inheritance, and otherwise of the same standard of testing and automatic testing.
Apologies @Jeff Burnz, I'm afraid I think you are very much throwing a spanner in the works! You seem to be discarding the established patch and going back to a totally new "proof of concept" currently without tests. Personally I don't even agree with you that the new approach is more intuitive or consistent (libraries is an array, yes, because a theme has multiple libraries, but a theme has just one logo), and I can see some possible flaws in the new approach. However I don't even want to start that debate. We have a simple, clean, working solution with a consensus of acceptance and should stick with it.
I have hidden the new patch, and propose that the next step is for final review of patch #87.
FWIW Here is my suggestion for how to build on what we have to add inheritance in a future issue. I would suggest that getLogo could be extended to included a third case, so it becomes:
This solution has the following advantages:
Comment #91
Jeff Burnz CreditAttribution: Jeff Burnz commentedNone of the theme API sub-system maintainers have chimed in on this for more than 18 months, and none since the patch you assert to be "established" was written. As we can see the issue has taken many turns already, based on maintainer feedback - lets give one of them a chance to review various approaches etc. I think that's pretty fair.
Note that xjm added that tag (needs sub-system maintainer review etc) in her last review, we need one of them to review the whole issue.
No, I am calling out the whole approach as inconsistent, this is not a minor nit.
I have not made these claims. What I argue is that the patch from #87 is inconsistent. Please don't put words into my mouth.
Such as?
Comment #92
Jeff Burnz CreditAttribution: Jeff Burnz commentedAnd one more thing (sorry...):
You haven't provided a review, patch or discussion on this issue until now, so I feel a tad blindsided by your harsh critique. I actually argued for something like my patch before we even changed to SVG as default and imposed this limitation (years ago now) - note that I was met with the argument that since it was established that .png was the only file type previously supported, a single file type would be fine. It was viewed as scope creep to allow others, and now years later we'er still here doing this dance. Sometimes a little creep can save a lot of mucking around.
Comment #93
Jeff Burnz CreditAttribution: Jeff Burnz commentedInheritance could be another issue, granted. It just seems like a grand opportunity to do something missing from Drupal forever.
I'm working on a group of sites for a legal services company that has 40 offices, 40 sites, and a number of sub-themes (different services are provided depending on the office type) but they all have the same corporate logo.
A few years ago on D7 I worked on a similar system that had around 25 sub-themes and thousands of sites. All with the same logo (a very large ivy league college).
My point is this is not out of the ordinary for companies, clubs, institutions etc to have many sub-sites with sub-themes yet all have the same logo.
Comment #94
lauriiiThank you for tagging this issue to be reviewed by the Theme API maintainers.
Adding the logo value to the theme info itself is fine. As @xjm pointed out on #83, we will have to ensure that we have proper documentation in place. Besides creating the change record, this should be added at least to the documentation page about creating a theme info.yml file.
The problem with the approach taken on this issue is that we add some logic to a value object. On the latest patch from @Jeff Burnz, we are moving to the right direction. It already removes some of the logic that the original approach introduces to the ActiveTheme value object. Looking at this, I think we should move the default value handling also to the ThemeInitialization.
I agree that the theme inheritance would be a nice feature, but I'd leave it out of the scope of this issue since it opens up some new issues we wouldn't have to deal with otherwise. I strongly believe that the theme inheritance can be done in a non-BC breaking way even after committing this, why I'd like to suggest that we open up a follow-up issue for that.
Thanks everyone and keep up the good work!
Comment #95
Jeff Burnz CreditAttribution: Jeff Burnz commentedOK, opened the follow up for inheritance: #2854740: Allow sub-themes to inherit the base theme logo
WiP patch attached. I think I have this right based on feedback from @lauriii in #94.
Tests omitted at this stage, because I am a test neophyte to be frank :/
Should we push this change into a core theme to expose this new feature, e.g. Bartik? I'm not sure about BC with regards to tests if we do that.
Comment #96
Jeff Burnz CreditAttribution: Jeff Burnz commentedOps, wrong patch.
Comment #97
Jeff Burnz CreditAttribution: Jeff Burnz commentedThis one.
Comment #99
lauriiiLooks good! As mentioned, we will have to add test coverage, tagged and moved back to needs work for that.
Good idea! Bartik has been marked internal which means we are allowed to make this type of changes.
Comment #100
tuutti CreditAttribution: tuutti as a volunteer commentedI agree with this being a better approach.
Using ->getActiveTheme() to figure out the logo path will break $theme argument in theme_get_settings().
I wrote some initial tests and replaced getActiveTheme() call with getActiveThemeByName().
Comment #101
Jeff Burnz CreditAttribution: Jeff Burnz commentedUsing ->getActiveTheme() to figure out the logo path will break $theme argument in theme_get_settings().
Out of interest what is the breakage here, wrong theme name etc?
Comment #102
tuutti CreditAttribution: tuutti as a volunteer commentedYep.
theme_get_settings() allows you to specify theme name as a second argument and load settings for any given theme and
getActiveTheme()
will always load logo for the currently active theme regardless of given argument.Comment #104
joelpittetThe novice task is to create a test and write a change record, tagging for DrupalCon Vienna
Comment #105
gugalamaciek CreditAttribution: gugalamaciek as a volunteer commentedI'm on DrupalCon, with help of gambry, I've chosen that task and will try to work on it.
Comment #106
gugalamaciek CreditAttribution: gugalamaciek as a volunteer commentedWhile reviewing this I:
1. Applied the patch.
2. Made simple subtheme of classy, and included in info file information about logo.png to use (logo: logo.png)
3. The new logo was used properly.
Still TODO:
1. Run tests.
Comment #107
MaskyS CreditAttribution: MaskyS at Google Code-In commentedWorking on change record.
Comment #109
eiriksmAdded a change record draft and updated the IS.
Tried to draft a change to the doc page, but that goes live directly? What is the process of drafting a change there? I can update it once it is committed, but not sure what is the best way to draft it in the meantime?
Comment #110
BrankoC CreditAttribution: BrankoC as a volunteer commentedMaybe the documentation should be a different issue, because now the patch is waiting for the documentation, but the documentation cannot be released until the patch is in.
Another option would be that you attached your draft to this issue (either in a comment or as a text file) so that it could be reviewed. I.e. it would not be part of the patch but we could still review it.
Comment #111
markhalliwellPatch looks great, CR looks good. I also just went ahead and added it to https://www.drupal.org/docs/8/theming-drupal-8/defining-a-theme-with-an-... in anticipation of this being committed using a version heading to indicate when it was introduced (which should help alleviate any confusion until this is committed).
Comment #113
lauriiiThank you @markcarver for updating the documentation. Thank you @tuutti for adding the test coverage.
The changes look good for me. Committed 018baee and pushed to 8.6.x. I also published the change record. Thanks everyone!