Problem/Motivation

If the Allow link text setting of a link field is changed from Optional/Required to Disabled after content has been saved, when the content is edited again the title won't be reset to NULL and the content will then display the old title value.

Steps to reproduce

  • Add a field link to the content type article with the setting Required for Allow link text
  • Create a content and put a URL/Title in this link e.g. : https://www.drupal.org/8 / About Drupal 8
  • Save and view the content, you will see <a href="https://www.drupal.org/8">About Drupal 8</a>
  • Change the configuration of the link field to set the title as Disabled
  • Edit your content and replace the URL by https://www.drupal.org/about/9
  • Save and view the content, you will see <a href="https://www.drupal.org/about/9">About Drupal 8</a> (new URL with old title) instead of <a href="https://www.drupal.org/about/9">https://www.drupal.org/about/9</a>

So the old title is kept and isn't editable anymore by the end user unless the administrator changes back the link field settting.

Proposed resolution

Reset the link title value if the setting is Disabled

Remaining tasks

Manual testing
Review
Commit

User interface changes

Link title uses current correct value.

API changes

N/A

Data model changes

N/A

Release notes snippet

CommentFileSizeAuthor
#66 3165999-66.patch4.22 KBmrinalini9
#64 3165999-64.patch5.15 KBakashkumar07
#64 interdiff_50-64.txt761 bytesakashkumar07
#52 after-patch.png28.17 KBasha nair
#52 before-patch.png21.05 KBasha nair
#50 3165999-50.patch4.26 KBsmustgrave
#50 interdiff-34-50.txt4.7 KBsmustgrave
#47 Drupal10.png215.37 KBrinku jacob 13
#47 Drupal9 After.png128.51 KBrinku jacob 13
#47 Drupal9 Before.png123.62 KBrinku jacob 13
#46 interdiff_34_46.txt4.58 KBrishabh vishwakarma
#46 3165999-46.patch4.13 KBrishabh vishwakarma
#39 After-Link-Patch.png57.23 KBManibharathi E R
#39 Before-link_Patch.png51.15 KBManibharathi E R
#37 3165999-after_patch.png57.13 KBabhijith s
#37 3165999-before_patch.png28.89 KBabhijith s
#35 after_patch34.png34.59 KBsonam.chaturvedi
#35 before_patch34.png34.05 KBsonam.chaturvedi
#34 3165999-34.patch4.14 KBsmustgrave
#34 interdiff-22-34.txt4.35 KBsmustgrave
#30 3165999-30.patch1.17 KBakashkumar07
#22 interdiff_3165999_19-22.txt808 bytesvakulrai
#22 3165999-22.patch4.36 KBvakulrai
#22 3165999-22-fail.patch1.17 KBvakulrai
#20 Screenshot 2021-05-15 at 21.30.17.png71.69 KBgauravvvv
#20 Screenshot 2021-05-15 at 21.26.30.png77.49 KBgauravvvv
#19 interdiff_15-19.txt4.7 KBneslee canil pinto
#19 3165999-19.patch4.36 KBneslee canil pinto
#16 interdiff-3165999-13-15.txt5.5 KBvakulrai
#15 interdiff-3165999-13-15.patch5.5 KBvakulrai
#15 change_link_title_old_values-3165999-15.patch5.21 KBvakulrai
#13 interdiff-3165999-10-13.txt2.79 KBvakulrai
#13 change_link_title_old_values-3165999-13.patch2.56 KBvakulrai
#10 3165999-10.patch2.26 KBranjith_kumar_k_u
#9 after-patch.jpg241.87 KBranjith_kumar_k_u
#9 before-patch.jpg237.39 KBranjith_kumar_k_u
#6 3165999-6.patch2.23 KBtostinni
#3 after patch.png14.14 KBanu.a_95
#3 before patch.png12.94 KBanu.a_95
#2 3165999-2.patch940 bytestostinni

Issue fork drupal-3165999

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

tostinni created an issue. See original summary.

tostinni’s picture

Status: Active » Needs review
StatusFileSize
new940 bytes

Here is a patch to reset the #default_value if the title setting is set to Disabled.

I'm not sure the double ? test is very readable, should I create a $default_value variable and set it outside the element ?

I imagine this would need some tests ?

anu.a_95’s picture

StatusFileSize
new12.94 KB
new14.14 KB

Applied patch #2 successfully

Steps for reproducing the issue mentioned in the issue description is easy to follow.

Before patch
Before
Even if we edit the URL, old link text with new url will be shown.




After patch
After
When the link text is disabled and a content with link text is edited, old link text won't be displayed and the updated url will be shown

anu.a_95’s picture

Status: Needs review » Reviewed & tested by the community
larowlan’s picture

Version: 9.0.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Bug Smash Initiative, +Needs tests

I don't think this is technically a bug, but I think we should still resolve it.

We need a test here demonstrating the issue and that it is fixed

tostinni’s picture

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

Thanks for the review, here is the test that I added at the end of testLinkTitle() so we can benefit from the initial setup of the field and then change the settings of the test field to demonstrate the bug is now fixed.

quietone’s picture

Issue tags: -Needs tests

Looks like a test has been added, removing tag

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ranjith_kumar_k_u’s picture

StatusFileSize
new237.39 KB
new241.87 KB

I have applied the #6 patch on 9.2.x dev version and it works fine .
Before Patch before patch
After Patch after patch.RTBC

ranjith_kumar_k_u’s picture

StatusFileSize
new2.26 KB

Re-rolled

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -233,7 +233,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      '#default_value' => $this->getFieldSetting('title') === DRUPAL_DISABLED ? NULL : (isset($items[$delta]->title) ? $items[$delta]->title : NULL),
    

    (isset($items[$delta]->title) ? $items[$delta]->title : NULL)
    could use the null coalescing operator, ??.

  2. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,23 @@ public function testLinkTitle() {
    +    // Verify that if you change the settings to disable the title then link is
    +    // rendered using the URL as text and not keeping the old title.
    

    This could be simpler.

    Verify that if the title field is disabled the link is rendered using the URL as text.

  3. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,23 @@ public function testLinkTitle() {
    +    $this->drupalPostForm(NULL, $edit, t('Save'));
    +    $this->assertText(t('entity_test @id has been updated.', ['@id' => $id]));
    

    drupalPostForm and assertText have been deprecated.

vakulrai’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB
new2.79 KB

@quietone , I have updated the patch as per the inputs given by you.

Please review.

quietone’s picture

Status: Needs review » Needs work

@vakulrai, thanks.

This time I applied that patch locally. And seeing it my editor I noticed more items.

  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -233,7 +233,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      '#default_value' => $this->getFieldSetting('title') === DRUPAL_DISABLED ? NULL : $items[$delta]->title ?? NULL,
    ...
           '#access' => $this->getFieldSetting('title') != DRUPAL_DISABLED,
           '#required' => $this->getFieldSetting('title') === DRUPAL_REQUIRED && $element['#required'],
    

    I didn't notice this before but there are now 3 instances of $this->getFieldSetting('title'). I think it is now time to put that in a variable and then use the variable here, say, $title = $this->getFieldSetting('title'). One advantage is that it will reduce the length of the line being added which, at least for me, will make it easier to read.

  2. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -282,7 +282,7 @@ public function testLinkTitle() {
    +    $assert_session = $this->assertSession();
    

    No need to do this here for the one line added many lines below in this test.

  3. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,23 @@ public function testLinkTitle() {
    +    // Verify that if the title field is disabled the link is rendered
    +    // using the URL as text.
    

    Wrapping is wrong here.

  4. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,23 @@ public function testLinkTitle() {
    +    $this->field = FieldConfig::loadByName('entity_test', 'entity_test', $field_name);
    

    The field config has not changed so does not need to be loaded again.

  5. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,23 @@ public function testLinkTitle() {
    +    $this->submitForm($edit, t('Save'));
    

    Remove use of t(), it is only used in tests when specifically testing translations.

  6. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,23 @@ public function testLinkTitle() {
    +    $assert_session->pageTextContains(t('entity_test @id has been updated.', ['@id' => $id]));
    

    change to using $this->assertSession()

vakulrai’s picture

Status: Needs work » Needs review
StatusFileSize
new5.21 KB
new5.5 KB

@quietone , I have changed the patch as per #14, Please review.

Thanks

vakulrai’s picture

StatusFileSize
new5.5 KB

Uploaded wrong interdiff in # 15, please consider this one.

vakulrai’s picture

quietone’s picture

Status: Needs review » Needs work

Getting there. :-)

Some out of scope changes have crept in.

  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -202,7 +202,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    -      //    in https://www.drupal.org/node/2423093.
    +      // in https://www.drupal.org/node/2423093.
    

    Out of scope change.

  2. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -228,15 +228,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    $title = $this->getFieldSetting('title');
    

    The variable I suggested $title doesn't make much sense because this is a setting. The name should be descriptive, maybe $title_settings? Of course, you may think of something better.

  3. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -282,7 +282,6 @@ public function testLinkTitle() {
    -
    

    Out of scope change.

  4. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +364,22 @@ public function testLinkTitle() {
    +    // Verify that if the title field is disabled.
    +    // The link is rendered using URL as text.
    

    Not wrapped correctly. More details about this standard is in the Drupal API documentation standards (general) sectiion.

  5. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +364,22 @@ public function testLinkTitle() {
    +    $this->assertSession()->pageTextContains(t('entity_test @id has been updated.', ['@id' => $id]));
    

    As mentioned in #15.5 t() is not used in tests, unless specifically testing translations. This should be a string of the text expected. Refer to the other assertions in the test.

We also need a fail patch for this. Remember to upload that first then the success path.

neslee canil pinto’s picture

Status: Needs work » Needs review
StatusFileSize
new4.36 KB
new4.7 KB

@quietone updated as per #18, and i had a question regarding failing patch, where do we modify code for that case, under tests folders?

gauravvvv’s picture

Attached before and after patch screenshot for reference.
Patch #19 seems fine.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work

@Neslee Canil Pinto, nice question. A fail patch is a patch that contains the test file(s) only. In this case, when the testbot runs the tests with a fail patch testLinkTitle will fail and that gives us evidence that the test is actually testing something we want to change. And then when the 'success' patch runs we have evidence that the fix does, in fact, fix the thing being tested. The fail patch is typically named 3165999-commentNumber-fail.patch. As an example, see https://www.drupal.org/project/drupal/issues/3109767#comment-14093095. It is important to upload the fail patch first and then the success patch. That way the testbot finishes with the success patch and updates the Status based on the success patch.

#18.4 needs to be fixed, the comment should be wrapped at 80 columns.

This time I manually tested the patch and can confirm it works. And I added the complete template to the IS and added remaining tasks.

vakulrai’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB
new4.36 KB
new808 bytes

@quietone , I have followed the flow you have stated in #21, hence reuploading the patch with updated fix for #18.4 and fail patch followed by success patch .I have also made changes to the comment text, which follows 80 line syntax.

Please review.

The last submitted patch, 22: 3165999-22-fail.patch, failed testing. View results

quietone’s picture

Status: Needs review » Reviewed & tested by the community

@vakulrai, thanks.

Everything in #18 and #21 have been addressed. I didn't find anything else that needs to be done when reading through the issue.

larowlan’s picture

@Gauravmahlawat, I'm removing your issue-credit for attaching screenshots, as they'd already been added twice above.
Crediting @quietone for reviews that strongly shaped the final patch

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Looks good, Needs Review for point 1 below - tl;dr I don't think we need to null coalesce $item[$delta]->title, I think TypedData API will have our back there

  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -228,15 +228,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      '#default_value' => $title_settings === DRUPAL_DISABLED ? NULL : $items[$delta]->title ?? NULL,
           '#maxlength' => 255,
    

    It would be good to add some additional brackets here for readability

    e.g.

    $title_settings === DRUPAL_DISABLED ? NULL : ($items[$delta]->title ?? NULL)
    

    But now that I write that, I see we're null coalescing to ... null

    Is there a scenario where $items[$delta]->title would raise an error? Given that is going through the Typed data API, I think that it would return NULL regardless and shouldn't raise and error.

  2. +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php
    @@ -365,6 +365,22 @@ public function testLinkTitle() {
    +    $expected_link = (string) Link::fromTextAndUrl($value, Url::fromUri($value))->toString();
    

    reading this your first thought is wait, why cast the result of ->toString to a string, and then I realised that ->toString returns a GeneratedLink 🤦‍♂️ not the best naming

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs reroll and #26 needs to be addressed.

akashkumar07’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB

Reroll added for patch #22.

smustgrave’s picture

Status: Needs review » Needs work

You rerolled the tests only patch..

And by skipping the actual patch didn't address #26 issues.

Please read the ticket and check the code before uploading a patch. Helps keep things clear. Would recommend reading up on some documentation on drupal.org tons of good stuff that really helped me!

akashkumar07’s picture

Hi @smustgrave,
The file

core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php

already has #22 patch changes for 9.5.x-dev. So I skipped it and #26 suggestion was not address.

Thanks

smustgrave’s picture

Can you double check that? I'm not seeing it. And if it were already addressed then this ticket is a duplicate

smustgrave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.35 KB
new4.14 KB

Skipping #30 because it just rerolled the tests only patch from #22.
I confirmed the full changes in #22 were not included as mentioned in #32 so no worries.

Tried addressing #26 comments
26.1 = Added the brackets but seems more like a comment and discussion
26.2 = Also seems like a comment more than a requested change.

sonam.chaturvedi’s picture

StatusFileSize
new34.05 KB
new34.59 KB

Verified the patch and tested on 9.5.x-dev. Patch applied successfully.

Test Steps:
1. Add a field link to the content type article with the setting Required for Allow link text
2. Create a content and put a URL/Title in this link e.g. : https://www.example.com / Example Domain
3. Save and view the content, you will see Example Domain
4. Change the configuration of the link field to set the title as Disabled
5. Edit your content and replace the URL by https://www.google.com
6. Save and view the content, you will see https://www.google.com

Test Result:
When the Allow link text setting of a link field is changed from Optional/Required to Disabled after content has been saved and the content is edited again > Then the content displays the new title value

Before Patch:
bef 34

After Patch:
aftre34

RTBC +1

smustgrave’s picture

Thank you for reviewing @sonam.chaturvedi if you feel this good can you move to RTBC please.

abhijith s’s picture

StatusFileSize
new28.89 KB
new57.13 KB

Applied patch #34 on 9.5.x and it fixes the issue.

Before patch:
before

After patch:
after

smustgrave’s picture

Thank you for testing if you think the issue is fixed please mark it as such

Manibharathi E R’s picture

StatusFileSize
new51.15 KB
new57.23 KB

Patch #34 Applied successfully on Drupal 9.4.x and Drupal 9.5.x.

Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
Status: Needs review » Reviewed & tested by the community

Patch #34 is working fine.
see in #35, #37 and #39 comments.
problem solved after applying the #34 patch.
changed to RTBC.

Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned
kristen pol’s picture

Status: Reviewed & tested by the community » Needs review

@smustgrave Regarding #36 and #38, manual testing is only one step before RTBC.

From what I can tell no code review or other core gate checks have happened since #34.

I'm moving this back to needs review for this reason.

THIS ISSUE DOES NOT NEED MORE MANUAL TESTING. (It needs code review and core gate checks. Thanks.)

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

catch’s picture

Status: Needs review » Reviewed & tested by the community

Not sure about the nested ternary, but that's just a preference and in this case moving it out of the array doesn't necessarily help. Otherwise looks good.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -243,14 +243,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    $title_settings = $this->getFieldSetting('title');
    

    a nitpick so small you need an electron microscope to see it, but I think this should be $title_setting, not $title_settings

  2. +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
    @@ -243,14 +243,15 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +      '#default_value' => $title_settings === DRUPAL_DISABLED ? NULL : ($items[$delta]->title ?? NULL),
    

    #26.1 still hasn't been addressed here, and was also flagged by @catch as iffy

rishabh vishwakarma’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Needs work » Needs review
StatusFileSize
new4.13 KB
new4.58 KB

Addressed #45.1

rinku jacob 13’s picture

StatusFileSize
new123.62 KB
new128.51 KB
new215.37 KB

Tested and verified the last patch #46. It was successfully applied on drupal 9.5.x. The above patch changed as per commented on #45. The above patch is not applicable for drupal version 10.1.x.

quietone’s picture

Status: Needs review » Needs work

Needs work for #45.2

@Rinku Jacob 13, Before testing an issue it is good practice to read the comments. The work requested in #45 is not complete which means this patch is not ready for testing.

rinku jacob 13’s picture

Hi @quietone , sorry for the mistake i have done. I didn't noticed comment on 45.2. According to comment on 26.1 we can change

'#default_value' => $title_setting === DRUPAL_DISABLED ? NULL : ($items[$delta]->title ?? NULL),

to

'#default_value' => $title_setting === DRUPAL_DISABLED ? NULL : ($items[$delta]->title),

because it shouldn't raise an error. I think this changes we need to do here. If it's wrong please excuse me. If it is correct i will create a patch based on that.

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new4.7 KB
new4.26 KB

#46 seemed to be making additional changes then 45.1

Addressed both points. Just moved the ternary check above to make it easier to read.

asha nair’s picture

Applied patch #50 successfully and it fixed the issue. Also addressed both points mentioned in #45.

asha nair’s picture

StatusFileSize
new21.05 KB
new28.17 KB
feyp’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Manually tested the patch on 10.1.x-dev and it resolves the issue. The IS looks good. Before/after screenshots for this iteration were added in #52.

+    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been updated.');

I wondered if this should use FormattableMarkup, but given that \d+ matches only integer values, I think it can be ommitted in this case. Didn't find any other issues. So I'd say the code looks good.

Bottom line: I think the issue is RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 50: 3165999-50.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Random failure

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 50: 3165999-50.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Random

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 50: 3165999-50.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Reviewed & tested by the community

Think it's random.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 50: 3165999-50.patch, failed testing. View results

smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Needs work » Reviewed & tested by the community

Random failure

Ahmad Smhan made their first commit to this issue’s fork.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
@@ -244,14 +244,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+    if ($title_setting !== DRUPAL_DISABLED && isset($items[$delta]) && isset($items[$delta]->title)) {

ubernit: do we need two calls to isset here?

I think php will allow just the second one

Fine to self-rtbc after that change, please ping me to look again at that point.

akashkumar07’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new761 bytes
new5.15 KB

Hi @larowlan,
I have removed the isset($items[$delta]) as per #63 comment.

Thanks!

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Looks like failing linting, thanks

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new4.22 KB

Updated patch #64 by fixing it, please review it.

Thanks!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Removing credit for Ahmad Smhan for the empty commit

#64 appeared to be adding out of scope of changes

#66 seems good. Since this was previously RTBC and nitpicky change, think safe to remark it.

larowlan’s picture

Updating issue credits

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

I was about to commit this and whilst going through my internal checklist realised that we're making a widget/form level change here but we're not doing anything to address API level changes too.

Which leads me to believe that the fix probably belongs in LinkItem instead of in the widget.

So can we undo our changes to the widget here and instead change LinkItem::setValue to set the title to NULL when the title option is set to Disabled

We can use \Drupal\Tests\link\Kernel\LinkItemTest::testLinkItem to extend test coverage for that change.

We can retain the test changes we've made in this issue, but we need to undo the changes to the widget.

Sorry for not realising this sooner, I realise we've been around and around a few times on this one.

dcam changed the visibility of the branch 3165999-changing-link-title to hidden.

dcam changed the visibility of the branch 11.x to hidden.

dcam’s picture

Status: Needs work » Needs review

Per @larowlan's comment in #69 I moved the changes to LinkItem::setValue().

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed.

catch’s picture

Status: Reviewed & tested by the community » Needs review

This is going to silently delete old data which if a site is experimenting with field settings might possibly want to be kept around. Including in migrations judging by the test changes.

What about checking the field setting in the formatter instead?

dcam’s picture

What about checking the field setting in the formatter instead?

You'd have to implement the setting check in every formatter. There's no guarantee contrib formatters would comply or that compliance would happen quickly. That could result in an issue where a link is displayed with different formatters in different contexts where it's rendered with and without a title.

I'm also concerned about the title subfield getting disabled and then re-enabled at some point much later on. During that time span links may be changed, but old hidden title values would be retained and could get out-of-date. That thought kind of drives home the point that we're going down a rabbit hole of edge cases. Regardless, it's a concern.

I don't know that there's a perfect solution.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

@catch thoughts on #76?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

@catch what do you think about landing in 12 only? As dcam mentioned may not have a perfect solution but this seems like an improvement.

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

Apologies, I know this one's gone around a couple times, but I think we can address #75 by overriding the magic getter instead of setting the value to NULL in setValue(). (For D12, we could also use property hooks once we figure out what we're going to do about code style sniffs, but that's a follow up.)

Something like

  public function __get($name) {
      if ($name === 'title' && $this->getSetting('title') === LinkTitleVisibility::Disabled->value) {
        return NULL;
    }
    return parent::__get($name);
  }

Edited to add:
Actually, maybe not. I think this might cause the empty value to be set in storage on a re-save.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

...this might cause the empty value to be set in storage on a re-save.

Yes, it does. I tested it by removing the current changes to LinkItem and adding the magic getter from #80. The title was set to NULL upon re-saving the entity while the title field was disabled.

I'm restoring the RTBC status.