I'm not able to get pass the js piece to insert a link using the linkit button within CKEditor. The js script is able to perform search of nodes, but when I cliclk the "Insert Link", I get the following:
after insert_link

The following error shows in js inspector:
js errors

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mtaggart created an issue. See original summary.

anon’s picture

Category: Bug report » Support request
Priority: Major » Normal

This usually happens when there is a javascript error somewhere. It doesn't have to be linkit's fault.

Please check the browser console to see the error message.

gmclelland’s picture

Issue summary: View changes
FileSize
77.94 KB

I just ran into this problem as well.

This happens when I'm editing a node and click the linkit button and start typing in linkit's search field. It does show the files in the drop down list, but when you select it and choose insert it takes you to a page that just displays json.

I'm using the latest linkit 3.x-dev with the Ckeditor module with the latest Ckeditor library and Scald-1.x-dev.

This doesn't happen on every node which is strange.

Hope that helps

gmclelland’s picture

For me, the only difference between content types is that the content type that has a paragraph field(https://www.drupal.org/project/paragraphs) added to it is the one that has the problem. The other content type works fine.

anon’s picture

Status: Active » Closed (duplicate)
Related issues: +#2551287: Linkit / Paragraph module issue

So it seems to be a duplicate of #2551287: Linkit / Paragraph module issue

mtaggart’s picture

Priority: Normal » Major
Status: Closed (duplicate) » Needs review
FileSize
69.52 KB

I'm re-opening for further review. The PHP setting to increase max_input_vars did nothing. I'm attaching the js error when I get the json type response.

js error

Also, I'm seeing the error in that an anonymous function is being called. It's probably trying to call for the "insertLink" function and not finding where to get the definition for the function.

mtaggart’s picture

Issue summary: View changes
FileSize
66.92 KB
573.06 KB
anon’s picture

Status: Needs review » Active

The images tells me almost nothing.

Tell me about your setup instead. For example, do you have the paragraph module installed and enabled for that content type this error occurs with?

What did you set max_input_vars to?

mtaggart’s picture

max_input_vars is set to 5000. I am NOT using the paragraph module. I'm also able to use the LinkIt icon up to a certain point. Here's the step by step:

> Create a new post
> Select the LinkIt icon, gets the first JS error == Uncaught TypeError: Cannot read property 'afterInit' of undefined
> Searched for a node, successfully able to retrieve the node searched for
> Click "Insert Link", gets the second JS error == Uncaught TypeError: Cannot read property 'insertLink' of undefined
> I get JSON response, see jsonResponse

justindodge’s picture

I'm experiencing similar symptoms - when clicking 'insert link' I'm taken to the raw json page. When clicking 'cancel', nothing happens at all.

In my case, there are no javascript errors - the problem appears to be that the linkit JS and CSS files are not making it into the page. I see that they are in the #attached portion of the form in linkit_dashboard_form(), but it looks like there is something odd about the way that form is rendered which is perhaps causing them to not make it into the page.

For me, I was able to implement a workaround in a custom hook that simply involves loading these missing files on hook_init - then everything is good for me. I'm not certain if this is a separate issue from the posts above or not.

/**
 * Implements hook_init
 */
function custom_init() {
    // For node add and edit pages, load in linkit resources that don't seem to load in correctly when attached to
    // linkit_dashboard_form(). Appears to be related to this issue: https://www.drupal.org/node/2612820
    if (drupal_match_path(current_path(), "node/add/*\nnode/*/edit")) {
        drupal_add_js(drupal_get_path('module', 'linkit') . '/js/linkit.dashboard.js');
        drupal_add_library('linkit', 'bac');
        drupal_add_css(drupal_get_path('module', 'linkit') . '/css/linkit.css');
    }
}

anon’s picture

@mtaggart: Any other modules that can affect this?

@justindodge: Thanks but that solution is not going to be in the module. I won't add linkit assets on all requests.

justindodge’s picture

@anon My solution does not add the assets on all requests, it adds them on node/add/* and node/*/edit pages only.

Also, it is not at all intended to be introduced into the module's code base, but can potentially be used as a temporary workaround for those needing a quick solution to the issue and also as a demonstration that, at least in my case, the issue is actually caused by missing assets. So I'm not trying to offer a solution, but an insight into the problem.

anon’s picture

@justindodge: Sorry, my bad. Didn't see the matcher_path part.

mtaggart’s picture

@anon I can't think of anything that could affect the module but I won't say 100% that's true. But I'm using the following CKEditor module:
CKEditor module version: 7.x-1.16+9-dev
CKEditor Library version: 4.4.7

anon’s picture

just as a test, try create a new content type, with only the field using the editor. If that doesnt work, try that with a default template.

mtaggart’s picture

@anon I did create a new content type, with no progress/difference. I'm not sure what you mean by default template though.

anon’s picture

What I'm trying to say is that in order to find whats causing the issue, we need to find the failing component.

Default template could be any template in core, Bartik or Seven. If it works with one of them, its probably a theme issue in the custom theme you are using. If not, its something else.

This works on a clean install of drupal with just the required modules and setup, therefor its a combination of Linkit and something else.

We are now searching for the else part. Can it be the token module? Is that installed? Did you create a new content type with only 1 field that contains the editor? Can it be another custom editor plugin?

anon’s picture

Can you test the patch in #2249097: CKeditor dialogue works on one node type, broken on another and see if that helps

gmclelland’s picture

I tested the patch, but the patch didn't seem to work for me. I verified the file was patched correctly and that the browser was loading the patched js file. I didn't see any difference. When I clicked insert link, it showed a page with JSON. I tested this on a content type that has a paragraph field.

capogeannis’s picture

In the same boat. Using #10's workaround for now. Following this thread with keen interest.

capogeannis’s picture

I actually had to rollback the #10 workaround is it causes the following js error on edit forms with link fields that do not have linkit enabled (for me, at least):

Uncaught TypeError: Cannot set property 'requiredFieldsValidation' of undefined

elektrorl’s picture

In my case, it seems, LinkIt does not support the class applied to the button "Insert Link". I rewrote classes to adapt my theme to Foundation. If you do the same for a framework like Bootstrap, you might get this 'json' error.

elektrorl’s picture

linkit.dashboard.js >> replace .linkit-insert with #edit-linkit-insert. This should work with all themes.

gmclelland’s picture

Thanks @elektrorl, but it didn't work for me. I'm using the stock seven admin theme with the Paragraphs module.

anon’s picture

gmclelland’s picture

Try the patch in #2720373: Incompatibility between LinkIt with CKEditor and Scald. It fixed the problem for me.