The normal workflow with linkit is to select text and then click on the icon. But you can also click the icon without having selected text. In this case it creates a link with the href as the text of the link.

The default should be the title of the node (if it's a node) and there should be a way to alter the text from other modules.

Comments

oknate created an issue. See original summary.

oknate’s picture

StatusFileSize
new2.25 KB

This patch sets the text to the node title, and allows altering it with hook_linkit_default_node_text_alter().

oknate’s picture

Issue summary: View changes
oknate’s picture

StatusFileSize
new2.81 KB

I added some error handling. I was getting a ResourceNotFoundException with external links.

This wasn't happening previously, so I think some core code must have been updated.

Also, since in the 8.x.5.x-dev branch a lot of this code has been moved into core, I created a core issue for this:

https://www.drupal.org/project/drupal/issues/2961554

oknate’s picture

StatusFileSize
new2.84 KB

Updating the patch, I found a bug where links were getting "" for the text.

firewaller’s picture

StatusFileSize
new70 bytes

(PATCH INVALID)

firewaller’s picture

firewaller’s picture

StatusFileSize
new3.13 KB

#5 works for me, but I added a little cleanup and moved the alter hook (renamed to "linkit_default_text") outside of the conditional statement so that it can be altered globally.

avpaderno’s picture

(I am deleting the content of an attached file.)

firewaller’s picture

Status: Active » Needs review
vatsalkhanna’s picture

Status: Needs review » Needs work

I have reviewed the changes as per patch #8 and found an issue when an external URL is provided with the same path which exists on the site. It sets the node title if the path in the external URL matches the node URL.

Steps to reproduce:

  1. Log in as admin.
  2. Go to linkit configuration page: /admin/config/content/linkit
  3. Click on "Add profile" and add some profile name. Save and manage matchers.
  4. Click on "Add matcher".
  5. Select Content.
  6. Select Article.
  7. Check "Group by bundle" and save changes.
  8. Now configure basic HTML text format: /admin/config/content/formats/manage/basic_html
  9. Add linkit button to CKEditor and select the same profile added at step 3.
  10. Add an article at /node/add/article and set URL alias as /my-article
  11. Now add another article page.
  12. In the body field click on the linkit button.
  13. Set link field as http://www.example.com/my-article
  14. Click Save.
  15. Observe that the node title set at step #10 is added for the external link.
vatsalkhanna’s picture

Status: Needs work » Needs review
StatusFileSize
new3 KB
new570 bytes

INVALID PATCH.

vatsalkhanna’s picture

StatusFileSize
new3.21 KB
new784 bytes

Added a patch to exclude the route check if the link is external.

avpaderno’s picture

Drupal 8.9 requires PHP 7. Running tests on PHP 5.5 and Drupal 8.9 will fail.

vatsalkhanna’s picture

StatusFileSize
new3.5 KB
new3.5 KB

I have a condition where we have migrated path aliases from D7 to D8 site (nodes aren't), so patch #14 will start throwing an ajax error on saving dialog.

The "node" parameter was not converted for the path /node/{node}

This happens when we try to add the D7 node path (on linkit search dialog) which exists on the path_alias table of D8 though the node doesn't actually exist. So I am adding a patch for this special condition.

Note: Don't use this patch if you don't have this condition, use patch #14 instead.

vatsalkhanna’s picture

vatsalkhanna’s picture

StatusFileSize
new1.03 KB

Here's the interdiff for #14 and #16. Please ignore the previous one.

mark_fullmer’s picture

Status: Needs review » Closed (outdated)

For some time now, as indicated by the Linkit project page, the 8.x-4.x branch of Linkit is not undergoing active development.

To help the maintainers of the Linkit module better steward tasks under active development, I'm going to mark this issue as closed (outdated). Sites using 8.x-4.x can certainly continue to do so, but should make plans for updating to the latest supported version of Linkit.

Even better: Drupal core will soon provide link autocomplete suggestions in CKEditor similar to what this module does. Sites using or considering using Linkit should follow this core issue to evaluate whether they can use the core solution instead of Linkit. See feature differences below to compare what Linkit includes that will not initially be in Drupal core.

If this issue relates to a problem or feature request that is applicable to the latest supported version of Linkit, please create a new issue, associated with that branch, describing the bug or enhancement.

For participation and information in Linkit's roadmap, see #3345480: LinkIt Release Roadmap and Issue Prioritization.

Thanks, community, for you collaboration and consideration!

klidifia’s picture

I updated this issue with some code that will use the entity title (already obtained via Linkit) as the default link text for a brand new inserted link without a selection range: #3388565: Populate displayedText with entity title when left blank