Needs review
Project:
CKEditor Link
Version:
7.x-2.x-dev
Component:
User interface
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
21 Mar 2012 at 00:51 UTC
Updated:
10 Mar 2021 at 09:30 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
anrikun commentedNice idea :-)
I think this should be a separate submodule.
CKEditor Link exposes many hooks so that submodules like yours can be developed.
Read:
- the
ckeditor_link.api.phpfile that ships with the module- #1107954: New 6.x-2.x and 7.x-2.x: To developers who want to support CKEditor Link
If you feel that a hook or something else is missing, feel free to post a feature request here.
Comment #2
johnpitcairn commentedI've been thinking a bit more about this, and it seems to me that the ability to pass additional arguments to the target item would be a valuable addition to more than just contact forms. It would be nice to be able to pass arguments to views page displays, for example.
So my thinking is now that I should simply add a field to the ckeditor link popup, "Extra arguments". This would be url-sanitized and appended to the link generated by ckeditor_link. The user should be able to enter additional arguments in path format or in query format, ie:
contact/marketing/competition (for use with views or the contact_forms module)
contact?category=marketing&subject=competition (for use with custom implementations)
Comment #3
hyperglide commentedI have interest in this work.
Potential use is to add and iframe call at the end of the url. "?iframe=1" that is related to the lightbox module.
This would render the content region only and not a full page view.
Comment #4
johnpitcairn commentedSee also #912220: Allow to add anchor to a Drupal link...
Comment #5
johnpitcairn commentedCough ... some time later. I'm taking a look at this now, initially by just patching the module to provide a single additional field.
Handling appended query parameters and/or hash fragments doesn't look like it will be a problem, though security will need to be considered.
The difficulty with additional arguments is that the only thing that actually gets stored is the link url. Then the module has to parse that on plugin load to determine which link type to display, and reconstruct the human-readable title. There is no good way for the plugin to determine whether a url like
/foo/bar/arg1/arg2is a valid Drupal path as-is, or a valid path with additional arguments. The plugin would need to issue an additional ajax call to have the server load the menu router item and check.Comment #6
johnpitcairn commentedThe simplest way to approach this might simply be to stick with what we have, but allow the displayed field value to accept additional typed-in data, like:
Some node title (node/123/arg1/arg2)
Some node title (node/123#foo)
Some node title (node/123?param=value&something=false)
It's a little trickier for users because they have to add the extra data before the closing parenthesis, but it would really help avoid the problem of how to distinguish path arguments from user-added arguments when reverting the path.
Comment #7
johnpitcairn commentedI don't think it makes a great deal of sense to implement this as an add-on module. It turns out that very few changes are required to make this work, whereas an additional module would have to duplicate and maintain large chunks of code.
This patch allows the addition of query parameters and hash fragments to the displayed node and taxonomy paths (but not extra arguments, so you can't link to node/123/edit or taxonomy/term/456/edit), and the addition of extra arguments, query parameters and hash fragments to the displayed menu paths (so you can use views page arguments or exposed filter parameters).
Comment #8
johnpitcairn commentedAnd patch, duh.
Contrary to what I say above, it's worth noting that even without the patch, there is nothing stopping you from appending additional arguments to the path while in the dialog - the link will validate and be saved, and will work as expected. But when the dialog is reloaded, the extra arguments prevent switching to the "internal path" display, so you get "external url".
I think perhaps it is worth fully allowing extra arguments for node and taxonomy paths anyway, since it is already possible to link to things like node/123/edit? Then at least on reload, you'd get the expected internal path display, not external url. That's one less WTF for users. Opinions?
Comment #9
johnpitcairn commentedThis patch includes the patch at #8, but also allows any extra arguments added to node and taxonomy term links to display correctly as "internal url" on reload.
Comment #10
johnpitcairn commentedAnd one more. This patch provides an extra field for entry of arguments, query parameters and hash fragment (or any combination). This considerably improves the discoverability and usability.
The primary
ckeditor_link_revert()callback has been modified to load the router item from the supplied path, and returns that without any additional page arguments. This is compared to the full path on the client side, allowing the plugin to determine what the extra arguments are (if any).Hash fragment

Query parameters

Views argument

All at once

Comment #11
johnpitcairn commentedThat patch at #10 results in a trailing slash on the link URL if there are no additional arguments. This will prevent the ckeditor_link text filter from converting paths to aliases on output.
This updated patch adds an additional test for empty extra arguments before the plugin inserts the link in
content.commit().Comment #12
johnpitcairn commented... and another patch. This improves the ckeditor_link_path_strip_args() function by comparing the number of path arguments to the number of router item path arguments. It handles things like Views menu items more reliably.
This patch also allows the ckeditor_link filter to process node and term paths with extra arguments, supporting the (optional) use of the Sub-pathauto module.
Comment #13
johnpitcairn commentedThis patch fixes an illegal offset notice introduced in #12.
It also adds a setting at
admin/config/content/ckeditor_link, "Extra arguments field", which provides a way to globally enable/disable the extra field in the dialog. The default is OFF, which preserves the standard ckeditor_link behavior.I believe this is now almost ready to fly - it would be nice to get some feedback...
Comment #14
anrikun commentedHi John.
I really appreciate your effort and will try to review your patch as soon as I get some time.
Comment #15
johnpitcairn commentedAnyone care to review this? I've had it in production for 6 months now with users reporting no issues.
Comment #16
devin carlson commentedA simple patch to allow an $options array to be passed to
ckeditor_link_url()in addition to a $path and $langcode.This is needed by CKEditor Link File in order to link to a download of a file which requires a protective token. See #2154615: File entity link method Download or URL only links to file/fid.
Comment #17
berenddeboer commentedUsing this patch, very happy with it. Please add it.
Comment #18
johnpitcairn commented@bereddeboer, which patch? #13?
My intent was to provide a full UI to let users add additional path arguments, query parameters and hash fragments, but @Devin Carlson seems to have hijacked the thread a little. The patch at #16 just allows other code to call the
ckeditor_link_url()with an options array, and should either have been a separate issue, or supplied as a re-roll of the patch at #13.Comment #19
stefan.r commentedPosted the patch in #16 to #2369601: Allow options to be passed to ckeditor_link_url
Comment #20
anrikun commentedPatch moved to #2369601: Allow options to be passed to ckeditor_link_url was just committed.
Comment #21
johnpitcairn commentedThanks - so can we perhaps drag this thread back to my original intent, providing a UI so users can pass arguments etc? The patch at #13 is the one for review and has been in use on 6 of my sites for a year. Hiding the one at #16.
Comment #22
johnpitcairn commentedComment #23
johnpitcairn commentedComment #24
johnpitcairn commentedReroll against latest dev (just removes offsets).
Anyone remotely interested in reviewing this?
Comment #25
johnpitcairn commentedComment #26
bbu23subscribe
Comment #27
johnpitcairn commented@bbu23 - use the "follow" button at the top of posts.
If you need this feature it would be useful if you could apply the patch, and if it works for you, mark the issue as "reviewed and tested by the community". I can't do that because it is my patch.
Comment #28
jeffamThe last hunk in the patch from #24 didn't work for me for some reason, so here's a new patch that works for me against the latest dev version of the module.
Will test further and mark as reviewed and tested if it does what it says on the box.
Comment #29
jeffamWorks for me as expected. I only tested hash fragments with nodes, but that worked perfectly.
I really appreciate your dedicated efforts with this patch, John. I'm glad this patch was here when I needed it!
Comment #30
johnpitcairn commentedThanks for the re-roll, I've had this in use for so long now that I forget it isn't actually in the module.
Feedback I have had from clients indicates that it might be desirable to have separate argument, query and fragment fields, but that could perhaps be a follow-up improvement if this gets in.
Comment #31
stefan.r commentedRTBC+1 for #28
Comment #32
johnpitcairn commented@anikrun - we have RTBC, how about a commit?
Comment #33
johnpitcairn commentedPatch re-rolled for latest dev. No changes.
Comment #34
johnpitcairn commentedOops, dropped a line. Use this one.
Comment #35
johnpitcairn commentedAhem. Let's remove the debugger statement in plugin.js.
Comment #36
johnpitcairn commentedGrr. This one.
Comment #37
kpaxman commentedOne thing to note is that this isn't *quite* true:
With this off, internal links with extra parameters show as "internal" instead of "other" and the parameters are hidden as opposed to shown - so it doesn't quite match the old behaviour.
Comment #38
kpaxman commentedWe had just decided to put this patch into service - since as long as you enable the setting, it doesn't matter that the old behaviour is not exactly preserved - and discovered that when you saved a page and went back to edit it, the arguments field would include some of the URL as well. This seems to have come out of the code that generates the cache not taking into account that the base path is not always at the root. We use multisite, so all of our sites have different base paths.
An updated version of the previous patch is attached, with this fixed.
Comment #39
xorunaI had to manually apply the patch but it works nice.