Display node title (a text) in by default when creating link in ckeditor5

Created on 20 September 2023, 9 months ago
Updated 23 May 2024, about 1 month ago

Problem/Motivation

By default module linkit returns the system path in this format: /node/xxx, and this value is used as href(correct), but also in text -> where we would appreciate the entity title.

Steps to reproduce

Create a link using linkit(with node list autocomplete) using ckeditor5 plugin when no text is selected.

Proposed resolution

Automatically use the entity label as text in A tag - e.g <a href="/node/XXX" data-entity-type="node" data-entity-uuid="..." data-entity-substitution="canonical">Lorem ipsum dolar</a> instead of <a href="/node/XXX" data-entity-type="node" data-entity-uuid="..." data-entity-substitution="canonical">/node/XXX</a>

thank you in advance!

Feature request
Status

Needs work

Version

7.0

Component

User interface

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @evonasek
  • Status changed to Postponed: needs info 9 months ago
  • 🇺🇸United States mark_fullmer Tucson

    This sounds like a duplicate of Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work . If the original poster can confirm that, let's mark this as a duplicate.

  • 🇮🇳India gskharmujai

    After trying out the patch that is available in https://www.drupal.org/project/linkit/issues/2966320 Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work , the patch applied successfully for D10 but it failed to address the required functionality which involves CKEditor 5.

    In D9 this was implemented using a core patch https://www.drupal.org/project/drupal/issues/2961554 Display node title by default when creating link with drupalink, allow configuration. Needs work but now with CKEditor5 as default in D10, a core patch dosent seem feasible at all.

  • This is not a duplicate issue. We have also tried to install the patch from https://www.drupal.org/project/linkit/issues/2966320 Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work , but this is not working in the ckeditor5 plugin. Please keep this issue open.

  • 🇺🇸United States mark_fullmer Tucson

    Thanks for the additional responses. If this is not a duplicate issue, please explain how the goal or purpose of this issue is different from the goal of Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work . If that issue is what you want but the current patch is not working, we typically don't open a new issue; we try to explain what is not working there and resolve it.

    Based on a few responses, it sounds like you're saying that Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work is not working with the CKEditor 5 plugin. My preference as a maintainer of this module is that this should be stated on that issue and work should continue there to make the patch compatible with either CKEditor 4 and CKEditor 5, rather than having one issue for CKEditor 4 and a different issue for CKEditor 5.

    Thank you!

  • Thank you Mark. I have commented https://www.drupal.org/project/linkit/issues/2966320#comment-15245574 Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work , so, please close this issue.

  • Status changed to Closed: duplicate 9 months ago
  • 🇺🇸United States mark_fullmer Tucson

    Thanks for the clarification. Closing this issue as a duplicate.

  • 🇳🇿New Zealand klidifia Christchurch

    This is specifically about what the default link text is when a link is inserted via the plugin button into CKE so I don't think this is a duplicate of 2966320 ((ref comment #3 paragraph 2 (Issue 2961554)).

    That issue no longer applies in D10 because the Drupal form used as an intermediary between Drupal/CKEditor no longer exists.

    I am not sure the issue outlined here can be solved within Linkit now -- I don't know how this can be achieved.

  • Pipeline finished with Canceled
    about 1 month ago
    Total: 200s
    #177595
  • 🇳🇿New Zealand klidifia Christchurch

    I needed to solve this so have altered JS so when creating a new (internal) link in CKEditor5 using the Link function and locating the entity using LinkIt - the URL alias is inserted as the default link text.

    There are a lot of other issues in Linkit around this or related to this:

    Display node title by default when creating link with drupalink, allow configuration. Needs work (Core) - This is where a solution had been made until Drupal 10 / CKEditor5
    Show URL alias after autocomplete selection instead of internal route (e.g., /node/123) RTBC
    Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work
    #3014297: Use target name as anchor text
    Insert node title instead of # when no link text is selected Closed: works as designed
    Allow customization of default text when text not selected Closed: outdated

  • Pipeline finished with Failed
    about 1 month ago
    Total: 296s
    #177596
  • Pipeline finished with Success
    about 1 month ago
    Total: 285s
    #177648
  • Pipeline finished with Success
    about 1 month ago
    Total: 295s
    #177650
  • 🇹🇭Thailand Nick Hope

    @klidifia Thanks for the heads-up on the related issue .

    I made a patch out of #10 and patched 7.0.0-alpha1 with it.

    In my testing (linking to taxonomy terms only, which is my use case), if a link to a taxonomy term is inserted in an article without first selecting text, the small link window does not dismiss when the green arrow is clicked. I can dismiss that window by clicking outside it, in the body of the article. Then the link is just shown as a vertical bar (like a pipe symbol). When I save the article, the taxonomy term name is shown, but followed by the term route. e.g. Thailand/taxonomy/term/683, where "Thailand" is the term name.

  • 🇳🇿New Zealand klidifia Christchurch

    @nick-hope thanks for trying it. I can't see what might be happening, I imagine it is producing some sort of JS error in console when not closing the Link window. I tried the same on a Fresh D10 install. Configured the default Linkit matcher to include taxonomy terms, made a term (Thailand) and tested on a new page in a few separate places. (Type 'Thai', select via Linkit, enters Link URL as /taxonomy/term/1, click green tick, entered as Thailand.)

    <p>
        <a href="/taxonomy/term/1" data-entity-type="taxonomy_term" data-entity-uuid="c2415acd-08e0-494d-b51d-09acc1728f0d" data-entity-substitution="canonical" data-entity-title="Thailand">Thailand</a>
    </p>
  • 🇹🇭Thailand Nick Hope

    @klidifia Thanks for testing it.

    I'm testing with Drupal 10.2.6, Linkit 7.0.0-alpha1 with a patch downloaded from your last MR. I've tried on an old Drupal D10 project and a near-vanilla D10 project. Tried articles, basic pages, basic HTML, full HTML, default Linkit profile, new "Taxonomy Terms" Linkit profile.

    I'm finding that the link window will close correctly for the first link I create in an article, but today I'm getting the route before the term name in the anchor text (reverse of yesterday), like this:

    <a href="/taxonomy/term/9" data-entity-type="taxonomy_term" data-entity-uuid="2c20c5cb-dee2-4af4-9408-2394309a3c19" data-entity-substitution="canonical" data-entity-title="Thailand">/taxonomy/term/9Thailand</a>

    When I try to create a 2nd link in the same article, I get this console error in Chrome (I'm afraid I'm not much use at interpreting it):

    ckeditor5-dll.js?v=40.2.0:5 Uncaught TypeError: Cannot read properties of undefined (reading 'attributes')
        at Ar.getChanges (ckeditor5-dll.js?v=40.2.0:5:376656)
        at html-support.js?v=40.2.0:5:44080
        at $r._callPostFixers (ckeditor5-dll.js?v=40.2.0:5:390254)
        at $r._handleChangeBlock (ckeditor5-dll.js?v=40.2.0:5:389512)
        at Cn._runPendingChanges (ckeditor5-dll.js?v=40.2.0:5:424836)
        at Cn.change (ckeditor5-dll.js?v=40.2.0:5:421831)
        at r.on.priority (editorAdvancedLink.js?v=10.2.6:1:7035)
        at oe.fire (ckeditor5-dll.js?v=40.2.0:5:604093)
        at <computed> [as execute] (ckeditor5-dll.js?v=40.2.0:5:607777)
        at f.execute (ckeditor5-dll.js?v=40.2.0:5:112967)
    rethrowUnexpectedError @ ckeditor5-dll.js?v=40.2.0:5
    change @ ckeditor5-dll.js?v=40.2.0:5
    r.on.priority @ editorAdvancedLink.js?v=10.2.6:1
    fire @ ckeditor5-dll.js?v=40.2.0:5
    <computed> @ ckeditor5-dll.js?v=40.2.0:5
    execute @ ckeditor5-dll.js?v=40.2.0:5
    execute @ ckeditor5-dll.js?v=40.2.0:5
    (anonymous) @ link.js?v=40.2.0:5
    fire @ ckeditor5-dll.js?v=40.2.0:5
    e.listenTo.useCapture @ ckeditor5-dll.js?v=40.2.0:5
    fire @ ckeditor5-dll.js?v=40.2.0:5
    t @ ckeditor5-dll.js?v=40.2.0:5

    I could do a screen recording with a completely fresh D10 project if that would help, so we can see if/where our steps differ.

  • Status changed to Needs work about 1 month ago
  • 🇳🇿New Zealand ericgsmith

    Nice work @klidifia!

    I am reopening this issue since its hidden being closed when there is work continuing on it.

    I agree that it sounds like it is not exactly a duplicate of Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work although that issue would be useful alongside this one - but that is specifically talking about the UI shown after making a selection from the autocomplete - where as this is about the default text content of the link.

    I have this a test on a clean install and it looks good to me - updated issue summary with a gif recording of it.

    I think the existing LinkitDialogCKEditor5Test should be updated to show that the default text is the entity label. Setting to needs work for this change.

    I also did not get the error reported in #11 - but I see in the js log it mentions editorAdvancedLink - I have not tested in combination with this module but could that be doing anything to interfere with the attributes?

  • 🇹🇭Thailand Nick Hope

    Good spot @ericgsmith. It does indeed seem to be an incompatibility with the Editor Advanced Link module . If I uninstall that, then this patch works correctly. Apologies for that oversight.

    Editor Advanced Link is quite a widely adopted module (109k sites), so this incompatibility should probably be addressed before (if) this feature is added to Linkit. Not sure which side it would need addressing from.

    There are also important views and discussion on the related issues ( example Show entity title after autocomplete selection instead of internal route (e.g., /node/123) Needs work ) that should be considered.

  • 🇳🇿New Zealand klidifia Christchurch

    Thanks both -- Yeah I can replicate that with installing Editor Advanced Module.

    I note the code block on both modules is basically the same around the _addExtraAttributeOnLinkCommandExecute

    Both have same priority high, if I change editoradvancedlink to highest, then it works OK. I'm not sure yet of the best way to make them play nice together and if there are other issues with both modules in play.

Production build 0.69.0 2024