When multiple Link fields are present and set to "automatically populate", link title values in other fields can be overwritten

Created on 3 May 2023, about 1 year ago
Updated 31 May 2023, about 1 year ago

Problem/Motivation

If one has multiple link fields on a block or content type and one of them has the Allow link text disabled odd things happen.
Among them, when the entity is saved the block hijacks all other title link texts and try inserting the description for that link even for links that were blank before.
So for a block with 4 cards it will try to populate the other card titles even if the don't belong to the same link group.

Steps to reproduce

1. Create a new content type or edit the basic page one
2. Add two "Link" type fields to the content type (Link1, Link2), all set to Limited "1".
3. Set the first field to "Allow link text" = "Disabled"
5. Set the second field to "Allow link text" = "Optional"
6. Set both fields' form display to "Linkit". (Leave both form settings to "Automatically populate link text from entity label: Yes" or because one does not have a title select the first one to say "Automatically populate link text from entity label: No" and the second link field to "Automatically populate link text from entity label: Yes" )
7. Create a node of the new content type.
8. Populate the link URL field link field 1, it will automatically populate the link field 2 title since it does not have a title of its own and one of the two fields had the Automatically populate option on.

Proposed resolution

Do not allow the JavaScript to populate a different field instance.

🐛 Bug report
Status

Fixed

Version

6.1

Component

Code

Created by

🇺🇸United States bernardm28 Tennessee

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bernardm28
  • 🇺🇸United States bernardm28 Tennessee
  • 🇺🇸United States bernardm28 Tennessee
  • 🇺🇸United States bernardm28 Tennessee
  • 🇺🇸United States mark_fullmer Tucson

    Hrm. Sounds like some greedy JavaScript. Thanks for reporting this. I'll leave it at the "Normal" priority for now.

  • 🇺🇸United States mark_fullmer Tucson

    I may need some help reproducing the problem.

    I set about trying to reproduce this problem and was unable to do so (running on Drupal 10.0.x), using the 6.0.x branch of this module (this only differs from the 6.1.x branch in its implementation of the CKEditor 5 plugin, so for the purposes of this issue, the branches should be interchangeable).

    Here are the steps I took:

    1. Create a new content type
    2. Add three "Link" type fields to the content type (test, test2, test3), all set to "Unlimited instances".
    3. Set the first field to "Allow link text" = "Disabled"
    4. Set the second field to "Allow link text" = "Optional"
    5. Set the third field to "Allow link text" = "Required"
    6. Set all three fields' form display to "Linkit". (Leave all form settings at "Automatically populate link text from entity label: No")
    7. Create a node of the new content type.
    8. Click "Add another item" for all 3 link fields on the node, effectively producing 6 different link inputs.
    9. Populate the link URL field on each of the link inputs with an internal node title and subsequently with an absolute URL.

    In none of the instances in Step 9 did I observe one field "hijacking" the link text value of any other field. In all instances the link text value remained the same.

    I then set the field with "Optional" link text form setting to "Automatically populate link text from entity label: Yes" and was still unable to produce the 'hijacking.'

    I then added the field with "Required" link text form setting to "Automatically populate link text from entity label: Yes" and was still unable to produce the 'hijacking.'

    Screenshot attached.

  • 🇺🇸United States mark_fullmer Tucson
  • Status changed to Postponed: needs info about 1 year ago
  • 🇺🇸United States mark_fullmer Tucson
  • 🇺🇸United States bernardm28 Tennessee


    Here is a video of the issue and how to reproduce it. Thanks for adding the steps above.

    1. Create a new content type or edit the basic page one
    2. Add two "Link" type fields to the content type (Link1, Link2), all set to Limited "1".
    3. Set the first field to "Allow link text" = "Disabled"
    5. Set the second field to "Allow link text" = "Optional"
    6. Set both fields' form display to "Linkit". (Leave both form settings to "Automatically populate link text from entity label: Yes" or because one does not have a title select the first one to say "Automatically populate link text from entity label: No" and the second link field to "Automatically populate link text from entity label: Yes" )
    7. Create a node of the new content type.
    8. Populate the link URL field link field 1, it will automatically populate the link field 2 title since it does not have a title of its own and one of the two fields had the Automatically populate option on.

    Hopefully those steps help.

  • 🇺🇸United States bernardm28 Tennessee
  • Status changed to Active about 1 year ago
  • 🇺🇸United States mark_fullmer Tucson

    Thanks for the additional info! It looks like the missing bit of information to reproduce was that one field needs to be set to "Automatically populate link title." I've updated the title and added the steps to reproduce to the issue description.

    Setting back to "Active."

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    83 pass
  • 🇺🇸United States mark_fullmer Tucson

    The attached patch checks that the link text field that can receive the autopopulated text has the same drupal selector (field id and delta) as the link URI that the text is coming from.

    This should reliably narrow the scope so that only the URI field associated with the Link text field can populate.

  • Assigned to ravi kant
  • Issue was unassigned.
  • 🇮🇳India ravi kant Jaipur

    I have the latest Drupal version (Drupal 10 and Drupal 10 alpha) and getting "Automatically populate link text from entity label: No" in both cases. I set "yes" for both but the issue is not replicating for me.

  • 🇺🇸United States mark_fullmer Tucson

    "Automatically populate link text from entity label: No" in both cases. I set "yes" for both but the issue is not replicating for me.

    Thanks for attempting to test. The steps to reproduce in the issue description specifically state that the first field needs to have its link text "Disabled" and the second "Optional", in additional to setting "Automatically populate link text to "yes".

  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States bernardm28 Tennessee

    This Patch fixes the bug. I did a test on both a vanilla Drupal 9.5.9 install and on our own website.
    Thanks for the quick fix.

  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States mark_fullmer Tucson

    Thanks for the review!

  • Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update about 1 year ago
    Waiting for branch to pass
  • @bernardm28 opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States bernardm28 Tennessee

    I may have spoken too soon.
    It works well on a content type node. But when I tried on our layout builder blocks the block will just hang.
    I imagine it has to do with dropping the handlers too early with the false statement.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States mark_fullmer Tucson
  • 🇺🇸United States bernardm28 Tennessee

    I did some more testing on this today. I haven't been able to reproduce the new bug with a vanilla D9 site.
    I think your fix does resolve that issue for a lot of scenarios.
    That said, I did find out that changing (!== to ===) and wrapping the if statement below as shown on the merge request above seems to fix it for both scenarios. Though that seems to break one of the tests.
    Why would return false halt the on-click action in some cases? I don't know yet.
    We could call it fixed with the first patch and I could start a new issue if you would rather do that.

  • 🇺🇸United States mark_fullmer Tucson

    We could call it fixed with the first patch and I could start a new issue if
    you would rather do that.

    I think that's a great suggestion. Let's proceed that way.

  • Status changed to Fixed about 1 year ago
  • 🇺🇸United States bernardm28 Tennessee

    I will open a new issue for the layout builder bug as described above.
    I need to test it more on a vanilla version of Drupal to why that makes a difference.

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

Production build 0.69.0 2024