I realize having autocomplete functionality was requested - #1169630: Linkit-style autocomplete widget - but my organization needs to have something in place sooner rather than later.

I've built out a (dev) module which adds autocomplete functionality to the "Title" of all link fields (at some point, it should be its own separate widget instead of altering the current link widget).

Selecting the node title will fill in the URL with "node/#" (we want to use "node/#" for internal links when possible, which avoids having broken links if a node's alias changes).

Eventually, supporting autocomplete for the URL field should be added, but a core bug (#93854: Allow autocompletion requests to include slashes) needs to be resolved before it will work.

I don't think this makes sense as its own module (I've just built it out this way for now), but it provides a starting point for adding autocomplete functionality.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ccarigna’s picture

FileSize
2.76 KB

Here's a .zip in case the .tar.gz file doesn't work.

Kvart’s picture

That's something I've also been trying to create. I need this as a separate widget, but I'm stuck with it. Let us know if you find a solution. Thanks for your work!

AdamGerthel’s picture

I would prefer to see the autocomplete be on the URL field instead. Having the title field for internal autocomplete and the URL field for external as well as internal URLs sounds confusing. Why not just let the URL field be an autocomplete field?

There's a module that does this for menu links: http://drupal.org/project/mpac

McReall’s picture

Hi! There are at least two solutions to the autocomplete functionality: CKEditor Link implements it well into CKEditor when looking for an internal path, and a NewCode Blog howto states having solved it for the CCK Link field (I have not verified that).
It would be nice if you could implement such a feature. Thanks.

Danny Englander’s picture

I was looking for this functionality and the module in #1 is almost perfect but I have a static title set so cannot see the autocomplete field as it's on the title field. Would there be a way to set the autocomplete field on the actual link field itself?. I think that would fit more use cases.

@cwc -- Do you have a Sandbox project for this started? Thanks!

askibinski’s picture

#1 is a great usability improvement!

It would be better the other way around indeed, having a autocomplete on the url, and populating the title field if available with the node title. Or - if this is hard - make a extra autocomplete field alltogether which populates the other fields.

dcoulombe’s picture

FileSize
3.81 KB

@cwc,

I added the capability for terms and selecting specific content types and vocabularies (or restrict them). So if you need to hide contents from the list, this version will do it:

dcoulombe’s picture

Me again, I switched the autocomplete from the title to the URL as recommended by askibinski.

dcoulombe’s picture

FileSize
3.81 KB

Oups... here the file.

lysander19’s picture

This autocomplete extension is very useful, exactly what we need, thank you!

sunchaser’s picture

Running Link 7.x-1.0
Installed link_autocomplete.zip module from #9

As soon as I start typing in the Link field I get this error :

An AJAX HTTP error occurred.
HTTP Result Code: 500
Debugging information follows.
/* some irrelevant parts omited */
ResponseText: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) 
LIMIT 10 OFFSET 0' at line 1: SELECT node.nid AS nid, node.title AS title
FROM 
{node} node
WHERE  (title LIKE :db_condition_placeholder_0 ESCAPE '\\') AND (type IN  ()) 
LIMIT 10 OFFSET 0; Array
(
[:db_condition_placeholder_0] => max%
)
jcfiala’s picture

If you can come up with this so it's it's own widget, we could work on adding it as an option to the link field, or see if there's a module to put it in.

Anonymous’s picture

FileSize
3.77 KB

I had the same issues as #11. I added a check on $where_node_type and $where_vocabulary to make sure they have items before adding that as a condition.

rooby’s picture

Any chance someone can make a patch file instead of a zip? It's way easier to review a patch.

This is definitely a useful feature since node reference fields give no control over the link text.

rooby’s picture

Status: Active » Needs review

Also, this should be needs review, not active.

Daniel Wentsch’s picture

Thanks dcoulombe and r_smylski for this useful helper. It works well and really has deserved a sandbox project imho!

korven’s picture

Subscribing!

jcfiala’s picture

Status: Needs review » Closed (won't fix)

Have you folks looked at the existing Advanced Link module? I link to it on the front page, and it provides autocomplete functionality already!

Due to that, I'm marking this 'Won't Fix' for now.

marcoka’s picture

thank you a thousand times for that example code.
FYI well advanced link does something different, you need to manuall add links to a textfield for external and it uses only internal links for autocomplete.

John Pitcairn’s picture

jlyon’s picture

@rsmylski: Thanks, this is a great little module. I tried advanced_link, but it didn't let me run autocomplete on the titles, and provided a lot of extra functionality that I did not need.

I took the liberty of creating a sandbox project: link_autocomplete. If you would like me to transfer ownership or make it a full project, just let me know.

harry_nc’s picture

Issue summary: View changes

Your best bet with this kind of issue is to use an entity reference field linked to a view that loads just the nodes you want available to be linked to.

rooby’s picture

Only if you want 2 separate fields for internal & external.
If you want a single field entity reference is no good.

The better solution is mentioned in #18, which is to use the advanced link module that is linked to from the link module project page.

rudiedirkx’s picture

Sandbox in #21 is perfect IF all your nodes are public, because no access check.

marcoka’s picture

an info for all of you guys trying to do this:
https://www.drupal.org/project/search_autocomplete
that module makes it possible for any field!

example view: http://root.artwaves.de/sharex/2015-04-07_17-23-05.png
example settings: http://root.artwaves.de/sharex/2015-04-07_17-23-24.png

Proteo’s picture

Thank you very much @rsmylski and @jlyon, the sandbox module is perfect for what I needed.