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

  1. Add a title field on a DS enabled view mode.
  2. Check off link
  3. 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
    3rd party settings
  • Update the summary to show it.
    summary

API changes

None

Data model changes

  • Add the link class to the default config of the title field.

Issue fork ds-3196670

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

devkinetic created an issue. See original summary.

devkinetic’s picture

Version: 8.x-4.x-dev » 8.x-3.x-dev
devkinetic’s picture

swentel’s picture

I 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

+    link class:
+      type: string
+      label: 'Link class'

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.

swentel’s picture

Status: Active » Needs review
StatusFileSize
new3.03 KB

Patch:

  • changes 'link class' to 'link_class' - couldn't find anything (yet) about config properties.
  • add config schema setting

  • swentel committed 3642918 on 8.x-3.x
    Issue #3196670 by devkinetic, swentel: Add Link Class to Title field
    

  • swentel committed 0913e56 on 8.x-4.x
    Issue #3196670 by devkinetic, swentel: Add Link Class to Title field
    
swentel’s picture

Status: Needs review » Fixed

committed to both branches, thanks!

Will be in the next release, not sure exactly when that will be though.

swentel’s picture

Status: Fixed » Closed (fixed)
swentel’s picture

Note: just found that the Link class in DS uses spaces too, so there's no problem with them.
Good to know for myself too :)

devkinetic’s picture

@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?

swentel’s picture

Status: Closed (fixed) » Needs work

@devkinetic : sure, if you roll a patch, I'll commit it!

swentel’s picture

Status: Needs work » Needs review
StatusFileSize
new2.61 KB

Let's see

  • swentel committed 49a7592 on 8.x-3.x authored by devkinetic
    Issue #3196670 by devkinetic, swentel: Add Link Class to Title field
    

  • swentel committed f647555 on 8.x-4.x authored by devkinetic
    Issue #3196670 by devkinetic, swentel: Add Link Class to Title field
    
swentel’s picture

Status: Needs review » Fixed

done!

devkinetic’s picture

Ah thank you, I meant to get to this soon.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.