Problem/Motivation
When using the "Title" field provided by display suite, in the 3rd party settings we are able to check a "Link" checkbox to output the title wrapped within an A tag. This works great, but there is no further way to control the output of the link, since it comes from an embedded twig template within /src/Plugin/DsField/Field.php.
In almost every site we build, I want to add classes to these links, for example using Boostrap, the "stretched-link" class can be added so I can make my entire card clickable.
In the past I've achieved the same thing by using the patch to provide token support in the prefix/suffix and expert display mode with the token for the entity alias. Or I add the "Read More" display suite field into my designs, and add the link classes i want there. These are both workarounds. In the end, they don't cover all cases, and an produce extra markup.
In a recent patch, blank attributes were added to links for preprocessing. This patch connects the dots with that patch and the Field UI.
Steps to reproduce
- Add a title field on a DS enabled view mode.
- Check off link
- Try to figure out how to theme that link with a class
Proposed resolution
Add in link attribute support to the title field, when link is checked off.
Remaining tasks
TBD
User interface changes
- Adjust the 3rd party settings to add a link class field for title

- Update the summary to show it.

API changes
None
Data model changes
- Add the link class to the default config of the title field.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 3196670-13.patch | 2.61 KB | swentel |
| #5 | 3196670-5-add-link-class-title.patch | 3.03 KB | swentel |
| #3 | 3196670-3-add-link-class-title.patch | 2.58 KB | devkinetic |
| image (1).png | 9.08 KB | devkinetic | |
| image.png | 34.06 KB | devkinetic |
Issue fork ds-3196670
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:
- 3196670-add-link-class
compare
- 3196670-add-link-class1
changes, plain diff MR !2
Comments
Comment #2
devkinetic commentedComment #3
devkinetic commentedComment #4
swentel commentedI like the patch! I'm just wondering whether it wouldn't be better use an underscore for the setting, so 'link_class' instead of 'link class'.
Reasoning: The patch misses the schema configuration which should be added to ds.field_plugin.title
This then becomes
I'm not a 100% sure if spaces are allowed in config properties - maybe they are. Other than that, patch looks fine though. Applying it after a display has been configured doesn't trigger any notices or so, so no danger for upgrades.
Comment #5
swentel commentedPatch:
Comment #8
swentel commentedcommitted to both branches, thanks!
Will be in the next release, not sure exactly when that will be though.
Comment #9
swentel commentedComment #10
swentel commentedNote: just found that the Link class in DS uses spaces too, so there's no problem with them.
Good to know for myself too :)
Comment #11
devkinetic commented@swentel, Glad you liked the patch! Yeah, I used the link class in DS to derive the original patch. I too thought that space was odd, but kept it consistent. Perhaps we should put it back to the space now that we've come full circle?
Comment #12
swentel commented@devkinetic : sure, if you roll a patch, I'll commit it!
Comment #13
swentel commentedLet's see
Comment #16
swentel commenteddone!
Comment #17
devkinetic commentedAh thank you, I meant to get to this soon.