Description:

There are some troubles with the Linkit Module in combination with Module Inline Entity Form.

At inline editing the referenced Content in a Node - uploading a new image for example, the following error appears in the console:

Uncaught TypeError: Cannot read property 'fields' of undefined <strong>(Console in Chrome)</strong>

It's happening that "linkit" is not available in linkit_fields.js on line 12.

The solution is to check before if "settings.linkit" is undefined or not.

Please find attached a patch for this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anon’s picture

Ok, have you submitted a patch for this issue? I can't see it in here.

mahalo13’s picture

mahalo13’s picture

Title: settings.linkit is undefined when editing content with inline edit form » settings.linkit is undefined when editing content with Module Inline Entity Form
Issue summary: View changes
hefox’s picture

Status: Active » Needs work
+++ b/linkit/js/linkit.field.js
@@ -7,8 +7,13 @@
+    // Check if linkit is set.
...
     if (settings.linkit.fields == null) {

Can just combine this two one line

if (settings.linkit == undefned || settings.linkit.fields == null) {
..

hefox’s picture

Status: Needs work » Needs review
FileSize
422 bytes

also wasn't relative so couldn't apply it in make file

Status: Needs review » Needs work

The last submitted patch, 5: 2207651-linkit-undefined-fields-5.patch, failed testing.

hefox’s picture

Status: Needs work » Needs review
hefox’s picture

Patch is being used on a project with multiple testers/developers and has not presented any problems yet and has fixed the issue.

Test failures make no sense

Status: Needs review » Needs work

The last submitted patch, 5: 2207651-linkit-undefined-fields-5.patch, failed testing.

The last submitted patch, 2: js-error-linkit-undefined-2207651.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: 2207651-linkit-undefined-fields-5.patch, failed testing.

joelpittet’s picture

From what I understand, this happens when you have an HTML editor on the page with linkit support enabled but have not created a linkit profile for that editor if I understand correctly?

This just masks the error?

Another approach would be to create warning alert to the developer that they need to create a Linkit profile for this field or editor?

This approach seems reasonable and I'm marking as RTBC nevertheless and leave it to the maintainer to decide what they want to do in regards to dealing with the JS error.

joelpittet’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Status: Needs work » Reviewed & tested by the community
Agileware’s picture

Actually this can happen with fields that intentionally do not have linkit enabled, and the patch in #5 fixes that case.

  • Commit f769dc2 on 7.x-3.x authored by hefox, committed by anon:
    Fixed #2207651: by hefox, mahalo13 - settings.linkit is undefined
    
anon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patches, and for the testing.

The patch in 5 is now commited.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hessam61’s picture

This is still happening. I upgraded to latest version of ckeditor and linkit. Running jQuery 1.10

dpacassi’s picture

FileSize
626 bytes
anon’s picture

What version of Linkit?

dpacassi’s picture

I'm using linkit with the version 7.x-3.1.
Sorry, i had problems posting the text to my patch from before.
Hope that it comes now:

In addition to patch #5 (where I changed the if statement to):

if (typeof settings.linkit == 'undefined' || settings.linkit.fields == null)

I also had to update the linkit.dashboard.js file as followed (see included patch on #20):

  attach: function (context, settings) {
    if (typeof settings.linkit == 'undefined' || settings.linkit.fields == null) {
      return false;
    }

If you're using paragraphs, you might need to include these lines as well:

function MODULE_form_alter(&$form, &$form_state, $form_id) {
	if (arg(0) == 'node' && arg(2) == 'edit' && module_exists('linkit')) {
		$path = drupal_get_path('module', 'linkit');

		drupal_add_css($path . '/better-autocomplete/better-autocomplete.css', array('group' => CSS_THEME, 'weight' => 1001));
		drupal_add_css($path . '/css/linkit.css', array('group' => CSS_THEME, 'weight' => 1002));

		drupal_add_js($path . '/better-autocomplete/jquery.better-autocomplete.js', array('group' => JS_THEME, 'weight' => 1001));
		drupal_add_js($path . '/js/linkit.js', array('group' => JS_THEME, 'weight' => 1002));
		drupal_add_js($path . '/js/linkit.field.js', array('group' => JS_THEME, 'weight' => 1003));
		drupal_add_js($path . '/js/linkit.dashboard.js', array('group' => JS_THEME, 'weight' => 1004));
	}
}

Make sure to clear all your drupal caches after making these changes.
It should work afterwards (well, it did for me).

Cheers!