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

Comments

Heisen-blue created an issue. See original summary.

Heisen-blue’s picture

Heisen-blue’s picture

Priority: Minor » Normal
Heisen-blue’s picture

Try to fix failed tests.

Heisen-blue’s picture

Version: 8.7.x-dev » 8.6.x-dev
Issue summary: View changes
Heisen-blue’s picture

Add default CSS class.
Will be cleaned later.

stevenx’s picture

Thanks,

Now this would be awesome to have the user choose style type in content editing mode as well (optional)

Heisen-blue’s picture

Good idea @stevenx, I will work on it in the next few days.

Heisen-blue’s picture

stevenx’s picture

take a look, me made it in user edit mode

Heisen-blue’s picture

Submitted a new patch which makes style options editable with a custom permission.
Link settings from screenshot

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

stevenx’s picture

StatusFileSize
new99.35 KB

yes, i use it in paragraphs as well, this is how it looks now:
paragraphs

Heisen-blue’s picture

Add a new option in the settings form to enable the style option in the content editing form.

Link settings form:
Link settings form

Content editing form:
Content editing form

Manage display form:
Manage display form

Heisen-blue’s picture

Title: Allow to select a style option in link formatter » Allow to select a style option on Link fields
Issue summary: View changes
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: allow-to-select-a-style-option-in-link-formatter-3032740-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Heisen-blue’s picture

Heisen-blue’s picture

Status: Needs work » Needs review
StatusFileSize
new10.91 KB

Fix last failing test and coding standards.

Heisen-blue’s picture

Issue summary: View changes

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ericdsd’s picture

+1 for that feature, looks very promising

sabina.h’s picture

Tested the patch from #17 and it works for me.

neclimdul’s picture

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

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
vikashsoni’s picture

Patch 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

ranjith_kumar_k_u’s picture

StatusFileSize
new10.85 KB

Re-rolled #17

ranjith_kumar_k_u’s picture

StatusFileSize
new10.84 KB

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The 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.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam’s picture

Status: Needs work » Closed (won't fix)
Issue tags: +stale-issue-cleanup

I 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.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.