Problem/Motivation
The current formatter for Link field does not provide a style option. This option avoids us creating multiple twig files for each view modes. In certain cases, designers can even ask to style a field differently for the same view mode in an other content type.
Proposed resolution
- Add an option in the formatter to provide this value.
- Add an option in the widget to provide this value in content editing form.
- Add a form to manage Link settings.
Remaining tasks
- Allow to select which entity types should be concerned by the field widget update?
User interface changes
- A new form for Link settings
- A new select field in the Manage display tab under the format settings
- A new select field in the content editing form on each Link field
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 3032740-nr-bot.txt | 144 bytes | needs-review-queue-bot |
| #28 | 3032740-28.patch | 10.84 KB | ranjith_kumar_k_u |
| #27 | 3032740-27.patch | 10.85 KB | ranjith_kumar_k_u |
| #17 | allow-to-select-a-style-option-in-link-formatter-3032740-17.patch | 10.91 KB | Heisen-blue |
| #16 | allow-to-select-a-style-option-in-link-formatter-3032740-16.patch | 10.25 KB | Heisen-blue |
Comments
Comment #2
Heisen-blueComment #3
Heisen-blueComment #4
Heisen-blueTry to fix failed tests.
Comment #5
Heisen-blueComment #6
Heisen-blueAdd default CSS class.
Will be cleaned later.
Comment #7
stevenx commentedThanks,
Now this would be awesome to have the user choose style type in content editing mode as well (optional)
Comment #8
Heisen-blueGood idea @stevenx, I will work on it in the next few days.
Comment #9
Heisen-blueComment #10
stevenx commentedtake a look, me made it in user edit mode
Comment #11
Heisen-blueSubmitted a new patch which makes style options editable with a custom permission.

@stevenx thanks, I'll take a look and keep you updated very soon. I think I will add a new option in the settings form to enable the style option in the content editing form. It can be useless if users just want to manage link style with content types and view modes, but really useful if coupled with a module like Paragraphs.
Comment #12
stevenx commentedyes, i use it in paragraphs as well, this is how it looks now:

Comment #13
Heisen-blueAdd a new option in the settings form to enable the style option in the content editing form.
Link settings form:

Content editing form:

Manage display form:

Comment #14
Heisen-blueComment #16
Heisen-blueComment #17
Heisen-blueFix last failing test and coding standards.
Comment #18
Heisen-blueComment #21
ericdsd commented+1 for that feature, looks very promising
Comment #22
sabina.h commentedTested the patch from #17 and it works for me.
Comment #23
neclimdulThis looks interesting but why is the setting site wide? Wouldn't you often want to apply this sort of behavior only to specific link fields?
Comment #26
vikashsoni commentedPatch not applying in drupal-9.3.x-dev giving error
Needs to re-roll
error: patch failed: core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php:117
error: core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldFormatterSettingsTest.php: patch does not apply
Checking patch core/modules/link/config/schema/link.schema.yml...
Checking patch core/modules/link/link.links.menu.yml...
Checking patch core/modules/link/link.permissions.yml...
Checking patch core/modules/link/link.routing.yml...
Checking patch core/modules/link/src/Form/LinkSettingsForm.php...
Checking patch core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php...
Hunk #1 succeeded at 83 (offset -1 lines).
Hunk #2 succeeded at 93 (offset -1 lines).
Hunk #3 succeeded at 150 (offset -1 lines).
Hunk #4 succeeded at 188 (offset -1 lines).
Hunk #5 succeeded at 203 (offset -1 lines).
Hunk #6 succeeded at 255 (offset -1 lines).
Checking patch core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php...
error: while searching for:
$element['#element_validate'][] = [get_called_class(), 'validateTitleNoLink'];
}
// Exposing the attributes array in the widget is left for alternate and more
// advanced field widgets.
$element['attributes'] = [
error: patch failed: core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php:263
error: core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php: patch does not apply
Comment #27
ranjith_kumar_k_u commentedRe-rolled #17
Comment #28
ranjith_kumar_k_u commentedComment #31
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #33
dcam commentedI am not fond of the changes in this patch. It would need a lot of work before it could be accepted.
Support for attributes is intentionally kept minimal and left to contrib to extend. And as it happens there's a contrib module that does almost exactly what this patch is proposing: Link Class. As a result, I am going to close this issue as a "won't fix."
On a related note, as the module's maintainer I am more interested in having a plugin system for attribute support than continuing to add one-off implementations. See #3209609: Add features of link attributes module to core's link module.
Credit has been granted to those who worked on a patch.