Problem/Motivation
Brand new clean install of 9.1.8.
First thing I do is create a new theme in themes/custom/
I create the ...
themename.info.yml
and
themename.libraries.yml
Files.
name: themename
type: theme
description:
core: 8.x
core_version_requirement: ^8 || ^9
# Defines the base theme
base theme: stark
# Defines libraries group in which we can add css/js.
libraries:
- themename/global-styling
- themename/global-scripts
When I go to /admin/appearance I get a white screen error with this error.
InvalidArgumentException: $string ("") must be a string. in Drupal\Core\StringTranslation\TranslatableMarkup->__construct() (line 132 of /app/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php).
I left the "description" blank, cause... I didn't think I needed it.
I sorta deduced what the problem is, and added some characters so it had SOMETHING in the Description, and the problem went away.
I think this should not have a fatal error... or at least give you some better directions. I can see entry level theme builders throwing up their hands pretty quickly with a white screen error and they don't know how to turn on verbose error messages.
Steps to reproduce
See above.
Proposed resolution
Friendlier error messages, or allow for the Description field to be blank.
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3213079_blank_name_theme.png | 47.67 KB | hmendes |
Issue fork drupal-3213079
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:
- 3213079-empty-description-theme-info
changes, plain diff MR !1103
Comments
Comment #2
quietone commented@alphex, is this a duplicate of #2600462: Incorrect syntax in frontend theme .info.yml file will throw an error in the backend when clearing caches via the UI?
Comment #3
quietone commentedComment #5
el7cosmosProbably we can throw an exception when building theme info if the description isn't a string. If a developer want an empty description, it should be with an empty string
''Comment #7
el7cosmosComment #8
hmendes commentedI think this might be duplicated from #2600462: Incorrect syntax in frontend theme .info.yml file will throw an error in the backend when clearing caches via the UI. The problem isn't with the description field specifically, any problem in the .yml file is going to break the site with an unfriendly message.
If the correct approach is to only change the errors to be friendlier, so we could create some meta issue, and fix the problems separately:
The other option I have would be specifically to this issue, to let the description to be blank...
What do you think?
Comment #9
el7cosmosI don't think that is the same problem, the problem here is
description:, which is valid YAML syntax, whereas the other issue is invalid YAML syntax.The problem lies here is the parser translates the description into
NULL, the description itself is optional according to https://www.drupal.org/docs/theming-drupal/defining-a-theme-with-an-info... and the default value is empty string''.On the appeareance page, the description is localized with
t, expecting the description is string or default empty string, so in the end, the theme info always hasdescriptionproperty, whether or not it is defined in the info.yml. But ifdescriptionis defined with no value, which mean NULL,twill give an error, which left us with two options:- Reject
NULLor non-string value.- Cast
NULLto empty string.This behavior is already present when handling
base themeproperty in https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/lib/Drupal/C...If we really want to handle all properties of info meta-data, along with their require/optional and data type, I think we should come up with a schema
Comment #10
el7cosmosComment #11
hmendes commentedHi @el7cosmos, I saw here, and I understood what you said,
So I think this is right, IMO we should cast NULL to empty string, to do something like the name field.
Comment #12
quietone commentedLooks like this needs work for the items in #11
This will also need a test.
Comment #13
danflanagan8This is essentially a duplicate of #2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml. That one is for modules, but the problem is in the ExtensionList abstract class, which handles both modules and themes. They should be fixed together.
@quietone, you've commented on both recently. How do you think we should move forward?
Comment #17
lendude#2730807: WSOD on admin/modules if description is set but is NULL in module.info.yml was fixed with a generic solution that fixes this too.
Feel free to re-open this if you think there is something we still need to address here.
Thanks!