Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Recent changes, probably related to - https://www.drupal.org/node/2844466 - made the adding and editing a little less intuitive, as now the links are always show as /node/x or /media/x instead of being more friendly, say using the path alias instead.
Comment | File | Size | Author |
---|---|---|---|
#64 | linkit-2877535-64.patch | 3.46 KB | arthur.baghdasar |
#63 | linkit-2877535-62.patch | 4.05 KB | mark_fullmer |
#35 | 2877535-34.patch | 4.92 KB | SpadXIII |
#35 | interdiff-30-34.txt | 4.03 KB | SpadXIII |
#30 | interdiff.2877535.24-30.txt | 764 bytes | pixelwhip |
Issue fork linkit-2877535
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
Comment #2
singularoAttching patch to call the alias manager not just return the path.
Comment #3
Tsymi CreditAttribution: Tsymi at Axess Open Web Services commentedThanks, patch on #2 works for me and met to my need.
Comment #4
singularoHmm it looks like there is a tiny change required for sites running on a non '/' base path.
Comment #5
singularoComment #6
anonThanks for patch, we need a test for this tho.
Comment #7
thierry.beeckmans CreditAttribution: thierry.beeckmans at Dropsolid commentedUpdated patch for the 8.x-5.0-beta7 version.
Comment #8
simeShouldn't this be done in a text output filter?
Comment #9
simeOn that note, I think this needs to be an optional configuration if this gets applied. We don't want to all our content links breaking when aliases are updated.
Comment #10
dalemoore CreditAttribution: dalemoore commentedI just ran into this issue setting up my first D8 site. I was expecting this module to work similarly to CKEditor Link with D7, where it uses the node/id link but outputs the alias for the end-user, so that when aliases change (renaming a title, for instance) the path gets updated. Instead, all URLs break if the alias is updated...
EDIT: Scratch this, I updated to the 5.x-beta10 version, and it works now like I thought it should. I see now that you all were working to fix this on that branch.
Comment #11
marco-sI have updated from 4.3.0 to 5.0.0-beta10 and I was wondering why the links are shown as /node/x afterwards (that wasn't the case with 4.x). I found the filter 'Linkit URL converter' in the text formats settings, but this filter doesn't seem to work?! Patch #7 works for me for my current case. I also don't need the 'Linkit URL converter' filter with this patch. But I agree with slime that this variant doesn't recognize alias updates and you should use the patch deliberately.
Comment #12
pfrenssenPatch didn't apply any more, rebased on 8.x-5.x.
Comment #13
moshe weitzman CreditAttribution: moshe weitzman commentedPatch works for me. FWIW, the link already has durable reference to the linked entity (uuid) so perhaps its OK for this href to be a bit brittle? An example [a] tag when using this patch is
<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="66950305-f906-4f76-90e4-143a0eddc67e" href="/news/bulletin-2020-05-flexibility-in-the-issuance-and-administration-of-insurance-during-covid-19">dfdfdf</a>
Comment #14
marco-spath.alias_manager
in #12 needs to be changed topath_alias.manager
for D9 compatibility. This patch will now require Drupal >=8.8. (see https://www.drupal.org/node/3092086)Comment #15
marco-sThe patch #14 does not provide the url with a language prefix (because of 2772643).
I updated this patch for that case accordingly.
Comment #16
marco-sThe patch #15 does not consider a possible path prefix configuration. Updated it in this patch.
Comment #17
ciss CreditAttribution: ciss at yousign GmbH commentedComment #19
lukusI'm not sure I agree that this is a desirable feature.
- The `href`- will be replaced by the text input filter, once the text is filtered for display.
- The alias is subject to change.
- The system path is actually a true representation of the intended destination.
Comment #20
SimeonKesmev CreditAttribution: SimeonKesmev at manifesto commentedHello, I am having this feature requested as well, but I also disagree with the implementation as it introduces dependencies, tries to implement URL building by itself by requesting the path alias manager and breaks the logic by replacing the internal path with an alias which is not stable reference to the target. Here's my take on it where I'm modifying only the representation to the editors and not he saved input.
Comment #22
SimeonKesmev CreditAttribution: SimeonKesmev at manifesto commentedCorrections here.
Comment #23
kbrodej CreditAttribution: kbrodej at Agiledrop - Your Trusted Drupal Teammates commentedPatch from #16 worked for me. However did spot a few issues. Attached a patch with changes and interdiff from #16
If the language detection is domain based the path alias will still use language prefix:
- Added a explicit check if language negotiation source is
path_prefix
if path alias does not exist for given language it will use
/{entity_type}/{id}
:- Added a method to check the alias for current language and fallback to default langugage.
Comment #24
SimeonKesmev CreditAttribution: SimeonKesmev commentedHere's an updated patch with my approach which handles base_paths.
NOTE: It's a different approach from the patch in #23, summary in #20.
Comment #25
askibinski CreditAttribution: askibinski as a volunteer and at iO commented@SimeonKesmev I agree with your approach since we already have input format
LinkitFilter
which will transform the internalnode/#
url for visitors of the content to the alias.Remaining issue:
With patch#24 you will see the alias in the autocomplete, but after inserting in the editor the link label/text still is
node/#
(unless you select text before inserting the link).I think if no text is selected in the editor the default text to insert should be the node title.
Comment #26
dbielke1986 CreditAttribution: dbielke1986 commentedIs there a chance to port this patch to version 6.*?
Because Iam facing the same issue:
If you type in "
/node/<nid>"
and you do not select the search result - it will input<a href="/node/nid"....
and not the<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="<uuid>" href="/node/<nid>"...
which is a big issue. Not everyone is clicking at the search result, which leads to an issue on multilanguage sites.Comment #27
dbielke1986 CreditAttribution: dbielke1986 commentedI created a new issue for version 6.*
https://www.drupal.org/project/linkit/issues/3222939
Comment #28
mark_fullmerI agree with the approach stated in #20. The approach here should be **not** to overwrite the internal path with the URL alias, since the latter could change. The patch in #24 , which is the latest version of that implementation, works well but does not include logic for adjusting the autocomplete logic to properly query the internal url in parentheses. In other words, it successfully populates the input area, but upon triggering a subsequent autocomplete search by clicking the input area, the autocomplete query fails because it's trying to match
[alias] ([internal-url])
, rather than[internal-url]
.The attached patch accounts for that, and is otherwise identical to #24.
(I'm not quite clear what #25 is referring to, so I didn't address that.)
Comment #29
tvalimaa CreditAttribution: tvalimaa commented#28 fix my issue so node/xxx links are working now as aliases
Comment #30
pixelwhip CreditAttribution: pixelwhip at Aten Design Group for City of Raleigh commentedHere's a re-roll of #28. That patch had some extra changes related to the license file that did not look intentional and were not represented in the interdiff.
After fixing that, I was able to apply this patch via composer to 6.0.0-beta3.
Comment #31
Sutharsan CreditAttribution: Sutharsan at LimoenGroen commentedJust checking, is this variable name
$patch_match
intended or was it supposed to be$path_match
.Comment #32
SpadXIII CreditAttribution: SpadXIII at SIM commentedI tried the patch in #30 and it seems to work, except that the wrong value is saved to the database. The alias (as internal url) is saved instead of the internal path. When selecting a node path, the form field shows "/alias-to-node" and the database contains "internal:/alias-to-node" instead of "entity:node/".
Here's a different patch that uses the #30 as starting point, but makes sure the correct value is saved to the database.
Comment #33
SpadXIII CreditAttribution: SpadXIII at SIM commentedI seem to have uploaded a patch that doesn't apply. Here's a fresh one.
Comment #35
SpadXIII CreditAttribution: SpadXIII at SIM commentedAnd I seem to have copied the deprecated service name :(
Fixed in new patch.
Comment #37
akhoury CreditAttribution: akhoury commentedThis patch adds a configurable option to use alias instead of internal path navigate to
/admin/config/content/linkit/manage/{linkit_profile}/matchers/{plugin_instance_id}
and check "use alias" checkboxThe autocomplete value and href attribute will contain the alias.
Comment #38
rossidrup CreditAttribution: rossidrup commentedwhy dont you hardcode it into latest release?
Comment #39
pghaemim CreditAttribution: pghaemim commentedmaking the #12 D9 compatible.
Comment #40
seanBLinking duplicate issues.
Comment #41
Leon Kessler CreditAttribution: Leon Kessler commentedLots going on this issue. Three separate patches in #35, #37 and #39. Very confusing.
I'm hiding patch #39 and #37, as they go against the agreed approach of storing the internal (node/id) url in the unprocessed text.
I tested patch from #35, all looks good. Except you still see the internal node/id url immediately after selecting the link. After closing the dialog and re-opening to edit, you then see the url alias. This seems a bit broken to me, the value should be consistent so the behaviour is predictable to the user.
After having a look into the patch, I realised that the added code in
Drupal\linkit\Element::valueCallback
means that the internal url will always be used when submitting the form. This means it's safe to use always use the alias on the suggestions.Patch attached updates the matches to always use the alias.
Also, I've wrapped the use of
\Drupal::service('path_alias.manager')
in a check for the installation of thepath_alias
module. As otherwise we would need to add a hard dependency to this module. Also this should hopefully make the tests pass.Comment #43
GasparM CreditAttribution: GasparM commentedHad the issue on linkit 6.0.x-dev, patch #41 works for me. I'm on PHP 8.1, drupal core 9.5.1
Comment #44
mark_fullmerNote: Linkit 6.0.0-beta4 was released on 5 March 2023. The patch from #41 still applies to the latest changes.
However, this only works with CKEditor 4 currently. CKEditor 5 support would need to be added.
Comment #45
mark_fullmerI take it back! This *does* work with CKEditor 5 as-is (I was expecting a different display output, but the aliased path is what is displayed in the CKEditor 5 context, which makes sense based on what the change is targeting).
This should still be "Needs work" since the failing tests need to be addressed. Also, I think it makes more sense to classify this as a "Feature" rather than a "Task."
Comment #48
jds1Rerolled #41 against 6.0.x https://git.drupalcode.org/project/linkit/-/merge_requests/16. Everything passes. Patch applies cleanly locally against both 6.0.x-dev and 6.0.0-beta4. Tested locally and now I'm getting aliases instead of node URLs! Marking as "Needs Review" – thank you!
Comment #50
DamienMcKennaThe merge request in patch format.
Comment #51
lxpcfly CreditAttribution: lxpcfly commentedThe linkit-n2877535-50.patch is successfully changed the URL Link field from "node/xxx" to URL Alias, but it still needs to do extra work, as the saved URL is still "node/xxx" rather than saved as its path alias, 'canonical' is not active.
eg:
1. put node/xxx into the link field and click save straight away without selecting the autocomplete result, it only saves node/xxx .
2. edit link, you can see the node/xxx has changed to its path alias, save as is, it is not changing the url, the url link on the mouse hover is still node/xxx.
Comment #52
DamienMcKennaIt's ok that the saved value is "node/xxx" because it's converted to the correct URL when the content is rendered; it's a feature.
Comment #53
lxpcfly CreditAttribution: lxpcfly commentedThank you Damien, but I think once it has the path alias also it appears in the Link field, it should save as path alias with canonical active.
Comment #54
DamienMcKennaThat would need to be a separate discussion.
Comment #55
vladt CreditAttribution: vladt commentedI'm encountering an issue after applying patch #50 to Linkit 6.0.0-rc1 (as well as Linkit 5.0-beta 13), the data-entity-substitution, data-entity-type, data-entity-uuid attributes are no longer being added to the link, so the LinkitFilter is no longer working.
This seems to be happening because
$href !== $href_dirty_check
on line 129 of linkit.module is unsetting the values.Comment #56
moshe weitzman CreditAttribution: moshe weitzman commentedSounds like this is right status.
Comment #57
moshe weitzman CreditAttribution: moshe weitzman commentedIn my instance, that check is preventing the values from being unset, not unsetting them. Changing status after my review.
Comment #58
mark_fullmerComment #59
R_H-L CreditAttribution: R_H-L as a volunteer commentedTesting this in 9.5, #50 breaks the a tag extra attributes. The tag gets put in as just the bare '/node/x' without any data attributes.
Comment #60
mark_fullmerAddressing the comments in #51, #53, and #59, all of which are suggesting that the URL alias is what should be saved to the database, rather than the internal route, I agree with Damien McKenna's statement in #52:
Comment #61
mark_fullmerAfter testing to confirm, I take back my comment. Using the latest patch, the comments in #51, #52, and #59 are effectively pointing out a problem -- not that the internal URL is what is saved (that's fine), but that when the resulting page is rendering, the internal URL is what is rendered to the end-user, rather than the URL alias.
Changing status to "Needs work" to address this. I'm also surprised that there is apparently no test coverage to catch this. I'd like to add test coverage for this going forward: the URL alias should be rendered on the page after save.
Comment #62
moshe weitzman CreditAttribution: moshe weitzman commentedThis patch no longer applies to the most recent release (Sep 30) :(
Comment #63
mark_fullmerHere's a revised patch that replicates verbatim what was in the patch in #50, and which will apply to the current development release for 6.0.x and 6.1.x.
Noting that the comments from #51, #52, and #59 still need to be addressed: when the resulting page is rendered, the internal URL should not be rendered to the end-user. The URL alias should. Test coverage needs to be added for this, too. Leaving status as "Needs work."
Comment #64
arthur.baghdasar CreditAttribution: arthur.baghdasar commentedIve removed this part from the patch everything seems to be working fine for me.
In the code below $input variable comes with an Alias and I don't understand why we should get the $path from it.
In My case the $path variable is converted back to the node/[nid] which is then being set to be the new input.
Comment #65
DamienMcKennaComment #66
kthullPatch from #64 applied to 6.1.2 for me and solved the generic node path on D10.1.5
Comment #67
greenSkin CreditAttribution: greenSkin as a volunteer commentedThe LinkitFilter doesn't look to work with the patch. I'm not seeing the additional attributes getting added to the tag.
Comment #68
SpadXIII CreditAttribution: SpadXIII at SIM commentedI tried to get something working, but did not succeed.
My goal was to use the alias during editing and store the node-url in the database. The link would then show the node alias in the editor, but in the database the node/ was stored. By adding another data-property (data-entity-path) I tried adding a editorDowncast and dataDowncast in the plugin, but that didn't work correctly: it would create a new a-tag wrapping the one that was being made by the base link plugin.
By adding a general upcast conversion, the href is changed to the alias:
But I failed trying to move the other way around. I tried adding a dataDowncast (which would set the path back to the href), and an editorDowncast (which would use the alias as href). This didn't work, because when creating an element with the same attribute, would add another element to the html instead of merging them (effectively overwriting the href-attribute)
I also tried using a data downcastDispatcher, but that doesn't seem to be able to get the correct viewElement (or rather, it couldn't find any element at all).
ps. there are some other code changes required as well to not only pass but also use the alias and path in the links.
Comment #69
mrweiner CreditAttribution: mrweiner commentedFor anybody who needs a quick and dirty fix for this, I'm handling it in hook_preprocess_field() with:
Note that this was generated by chatgpt, so I'm not sure that all of the args in $dom->loadHTML() are needed, but it seems to do the trick for me.