Problem/Motivation

Projects using the link_attributes module cannot expose those attributes on link fields.

Steps to reproduce

  1. Install the link_attributes module
  2. Set the form display of a link field to be "Link (with Attributes)"
  3. Expose the field using GraphQL Compose
  4. No attributes exposed

Proposed resolution

Create a sub-module that could be enabled if link_attributes exist in the project and exposed a new LinkAttributes schema as part of the Link field.

CommentFileSizeAuthor
#12 vrt_links.zip9.57 KBcedricl
Command icon 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

roaguicr created an issue. See original summary.

roaguicr’s picture

Issue summary: View changes

roaguicr’s picture

The MR includes a submodule that extends the Link schema to add LinkAttributes on it, it should work with the default attributes included in the link_attributes module.

anicoto’s picture

I applied the patch and tested on a web site and is working.

Drupal Version 10.2.6
PHP 8.2.21

anicoto’s picture

Status: Active » Reviewed & tested by the community
jmolivas’s picture

+1 on this submodule

almunnings’s picture

Happy to bring this into main module rather than a sub module.

almunnings’s picture

Also looks like changes have been made on the 2.2.x branch and not on the issue branch. I'll do some force pushes to move this around.

cedricl’s picture

StatusFileSize
new9.57 KB

We also did something like this but with support for custom attributes. Instead of just only adding the default attributes from the module. We created the custom attributes 'style' and 'type'. But this can be everyting since we loop over the definitions from the \Drupal\link_attributes\LinkAttributesManager

mcortes19’s picture

+1

almunnings’s picture

Status: Reviewed & tested by the community » Needs review

Heyya
I've combined the feedback.

Are you able to test PR 97 please.

If all good I'll write some tests for the various link mod modules.

almunnings’s picture

Version: 2.2.x-dev » 2.3.x-dev
theodorosploumis’s picture

I found an issue with this feature which may be related to the main module.

When I enable the new module graphql_compose_linkattributes it seems that I cannot override later the Link class with another custom module. Only when I disable the the module graphql_compose_linkattributes I can override it.

How to reproduce this? Enable the graphql_compose_linkattributes module from this patch and then create another module that has similar functionality to this. When you enable it the new fields are not attached to the LinkType (although the new GraphQL type is available on Docs).

We may need to investigate here, also, if methods hook_graphql_compose_graphql_type_alter() and hook_graphql_compose_field_type_alter() allows for multiple and correct inheritance.

almunnings’s picture

On PR 95 or 97?
I’m working with 97

theodorosploumis’s picture

I was working with the patch from 95.

almunnings’s picture

Grab 97 please. 95 I’m not gonna merge. If same issues happy to move fwd on your feedback

theodorosploumis’s picture

I have no issues with the PR number 97. Thanks!

apmsooner’s picture

I don't have menu_link_attributes module enabled but do have link_attributes. Problem i'm having is the schema type in LinkAttributesType.php is set to nonNull. So my graphql queries fail on menus with this. Setting it to getNullableType fixes it for me.

apmsooner’s picture

Status: Needs review » Reviewed & tested by the community

Works great with my commit to allow null.

almunnings’s picture

Pretty-much ready to commit this, I just want to create a test for the comment in 8eaabeaf, just has me being a bit cautious here.

almunnings’s picture

Status: Reviewed & tested by the community » Fixed

Merged pending 2.3 release

almunnings’s picture

Status: Fixed » Closed (fixed)