Problem/Motivation
Receive this error on node pages rendering a file-link or URL-link field with GCDS theme active:
InvalidComponentException: [gcds:gcds-link/variant] Does not have a value in the enumeration ["default","light",null]. The provided value is: "".
Steps to reproduce
1. GCDS theme active (recommend using Drupal CMS 1.2.5 to reproduce error)
2. Populate a plain File field or URL Link field on a content type containing one or both types of fields.
3. View the node page containing a rendering of the File or URL Link field.
Proposed resolution
Proposing patch to GCDS Link component allowing empty string as a variant.
Additionally removing the template file field/file-link.html.twig also resolves the issue.
Issue fork gcds-3537053
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:
- 3537053-invalidcomponentexception
changes, plain diff MR !9
Comments
Comment #3
jmdeleon commentedComment #4
jmdeleon commentedComment #5
jmdeleon commentedComment #6
jmdeleon commentedComment #7
liam morlandIt would be better to find the root cause of this. The
variantproperty should be set to null instead of empty string to not specify a value.Comment #8
jmdeleon commented@liam morland: I agree.
Did some more digging and the 'variant' attribute (unique to the GCDS theme) on the gcds-link component isn't being set in the gcds_preprocess_file_link theme hook.
Proposed a fix (see the issue branch and updated merge request), enabling the 'default' value to be set for the GCDS-only 'variant' attribute. There's probably a better way to do this, but the root cause is an issue in the gcds_preprocess_file_link theme hook.
Comment #9
liam morlandIf
variantis to be default, it should just be left-out (or set to null). What is setting it to the empty string?Comment #10
jmdeleon commentedThe 'variant' property is unique to your theme. I don't know what would be setting it to an empty value.
The specs for the gcds-link component:
https://design-system.alpha.canada.ca/en/components/link/code/
https://github.com/cds-snc/gcds-components/tree/main/packages/web/src/co...
don't specify that the 'variant' property can be set to null, so it needs to be set to a default value.
Comment #11
jmdeleon commentedHere's some generic steps to reproduce the problem, without any other modules factoring in the issue:
(GCDS theme is active and the default theme)
1. Create a Drupal File field on a content type.
2. On the "Manage Display" tab for the content type, select "Generic file" as the Format for the created File field.
3. Create a node of the content type with the Drupal File field you created in Step 1, and attach any file of any type to the node.
4 . Try to view that node with the GCDS theme active.
The code to generate links from File fields doesn't know anything about the 'variant' property from your theme, and a problem with that value -- unique to your theme only -- is what's throwing the exception. Why would that code know anything about a value needed by your theme? Why should it?
Comment #12
jmdeleon commentedThe exception on the 'variant' property is also thrown when attempting to display Link fields under the GCDS theme.
You can reproduce the exception using the steps in #11, but replacing the File field with a Link field.
Proposed a fix for that too. Updated the issue branch and merge request.
Comment #13
liam morlandRegarding #10, if
variantis null or otherwise empty, thevariantattribute will not be set ingcds-link.twig.Comment #14
jmdeleon commentedTracked down the conflicting module:
Simply adding drupal/jsonapi_extras via composer require will cause the exception in this issue to be thrown on a node with a Drupal Link or File field filled in and the GCDS theme active.
jsonapi_extras (a module with 19,000 installs) does not even have to be enabled.
The patch supplied in the issue branch and accompanying merge request resolves this issue.
Comment #15
liam morlandWhat is it about
jsonapi_extrasthat does this?Comment #16
jmdeleon commented@liam morland: if I knew that, I would have posted it here. The issue appears to be in some dependent libraries jsonapi_extras brings in, without the module even being activated. So this probably could happen introducing other modules.
I've already pointed out a legitimate, reproducible problem with this theme, and beyond the normal issue reporting, proposed some resolutions. That's about the extent of what I'm able to contribute to this issue for now.
You're the maintainer of this project and it's ultimately your call on anything that goes into it.
Comment #17
jmdeleon commentedI can reproduce this bug now on a bare default installation of Drupal CMS (1.2.5) with no other modules loaded and the GCDS theme active. You no longer need to load any other modules, just a base installation of Drupal CMS 1.2.5 plus the current GCDS theme, and then render a GCDS Link component on a page (either thru a plain Link or File field).
Bumping this up to Major. Updated the Steps to reproduce.
I also reverted to using my original proposed patch (updating the issue branch for this bug report), which adds the blank string ('') to the enumeration of allowed values for the 'variant' property for the GCDS Link component, in gcds-link.component.yml
That patch adding the blank string to the list of allowed values on the -- one line of code -- doesn't introduce any other new code. The issue appears to be upstream in the GCDS component code (in TypeScript) where the empty string is not properly disallowed as a value for the 'variant' property. Adding the blank string to the list of allowed values in the theme component code -- one line of code -- is the simplest mitigation around this current issue. The theme will still work even if this change is accepted, because the allowed value of a blank string for the variant property will just be disregarded.
Comment #18
jmdeleon commentedComment #19
jmdeleon commentedComment #20
jmdeleon commentedComment #21
liam morlandAre you able to get it to exhibit this problem in automated testing?
You say this can be fixed by removing
file-link.html.twig. There is not much in that file. The content is generated ingcds_preprocess_file_link()and that doesn't set thevariantproperty.The
sizeproperty is just likevariant. It is a nullable string with enumerated options. I wonder why this problem doesn't appear with that.Comment #22
jmdeleon commentedSteps to reproduce the error:
1. Install Drupal CMS current version (not core).
2. Create a content type with either File upload field or Link field, or both.
3. Create a node from the content type created in Step 2, populating the File upload and/or Link field(s). Any File upload and/or Link URL will work. Display the link to the File upload.
4. Install GCDS theme and activate as the default theme.
5. View node page for node created in Step 3.
Applying the fix in this issue branch (one line of configuration, accepting the blank string as a value for 'variant' in the gcds-link component) and clearing cache resolves this issue.
I no longer do Drupal development professionally as my day job, so my time and attention to this issue is limited. Please try these steps before posting a reply.
Comment #23
jmdeleon commentedThe issue appears to manifest itself when the PHP library
marc-mabe/php-enumis included by a Drupal module. php-enum appears to override default PHP enum handling, and is used by many different Drupal modules.The TypeScript code for the gcds-link component in the base GCDS web component libraries appears to still accept the empty string '' as a value for variant, in line 194 of https://github.com/cds-snc/gcds-components/blob/main/packages/web/src/co...
${variant != 'default' ? `variant-${variant}` : ''}This expression is a conditional where the empty string is still returned as a value.
Nothing similar is done for the size property.
Chasing the ghosts of resolving these larger outside non-Drupal dependencies may take some time and effort, but making the one-line change accepting the blank string as a value for variant will mitigate the problem until the issues with those dependencies are resolved.
Comment #24
jmdeleon commentedAlternative steps to reproduce the error:
1. Install Drupal core current version.
2. Create a content type with either File upload field or Link field, or both.
3. Create a node from the content type created in Step 2, populating the File upload and/or Link field(s). Any File upload and/or Link URL will work. Display the link to the File upload.
4. Install GCDS theme and activate as the default theme.
5. Install and activate module JSON API Extras (jsonapi_extras).
6. View node page for node created in Step 3.
jsonapi_extras is a fairly common dependency module used by several other modules (used on 22,000 sites) that brings in marc-mabe/php-enum . There are likely other modules that bring in marc-mabe/php-enum -- jsonapi_extras was the module I found in my usage that induced the error. The upshot is that this theme does not play well with other commonly installed modules and simple use cases in its current state.
Again, applying the fix in this issue branch (one line of configuration, accepting the blank string as a value for 'variant' in the gcds-link component) and clearing cache resolves this issue.
Comment #25
jmdeleon commentedThe
variantproperty on GCDS Link is going/has gone away in the most recent versions (Mar 2026). Use case described in this issue was tested by hand on release 1.0.1-rc6 of this theme and the error no longer occurs on file and URL links on nodes displayed under this theme.