Update 11/03/15
Discovered this seems to be to do with the module weights, hence working ok until caches get cleared (I guess). Patch attached in #2.

Original issue
I'm using features to copy wysiwyg editor settings from dev to live environments. This feature includes a default Linkit profile - I've attached the export of the profile - and all of the wysiwyg configuration.

I'm working with a patched version of WYSIWYG 7.x-2.2 and we're using TinyMCE 4.1.7 with Linkit 7.x-3.3, with Features 7.x-2.0.

When I enable the feature, the Linkit profile is created correctly, and I can access and use it when I first access a node edit page. However, when I refresh that page, a JavaScript error starts appearing: "TypeError: Drupal.settings.linkit.fields is undefined"

I've added the code suggested in #2358219 but that hasn't solved the problem.

The only way I've been able to solve this problem is to disable and re-enable the feature, which means I can only use it on the first page load again, or to manually export the profile and import it by hand (bypassing the feature entirely).

I'm currently looking at a separate install function to import this profile rather than relying on features but that's obviously not ideal!

Any help would be appreciated.

Comments

sophie.sk’s picture

As a further update to this, I tried moving the Linkit profile out of the feature and into a separate mymodule.linkit_profiles.inc file as suggested in https://www.drupal.org/node/2302815#comment-9006351

The same thing happened - my profile was created, but it unlinks itself from the WYSIWYG editor after I clear the caches.

It works ok if I create it manually but as this has to be rolled out over 50+ sites I don't fancy that in the slightest. I'm currently trawling the ctools issue queue to see if there's anything there, but so far nothing.

sophie.sk’s picture

Title: "Drupal.settings.linkit.fields is undefined" after adding profile through features » Update module weight so that process functions are added after dependent modules
Issue summary: View changes
StatusFileSize
new1.43 KB

Finally tracked it down.

In linkit_element_info_alter(), a pre-render function is added depending on which other pre-render functions are present/available. When using the WYSIWYG module, this should be hit:

  // Used when using wysiwyg module.
  if (isset($types['text_format']['#pre_render']) && is_array($types['text_format']['#pre_render'])) {
    if (in_array('wysiwyg_pre_render_text_format', $types['text_format']['#pre_render'])) {
      $types['text_format']['#process'][] = 'linkit_pre_render_editor_element';
    }
  }

But it seems that at the time this is run, there's no wysiwyg_pre_render_text_format pre-render callback in the array.

I solved this by updating the Linkit module weight to (wysiwyg module weight) + 5. Everything seems to be working smoothly now.

Attached is a patch that updates the module weight in hook_install() and an update function for existing installations.

Updating issue title and summary.

sophie.sk’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: update_module_weight-2429353-2.patch, failed testing.

anon’s picture

We use "linkit_module_implements_alter()" for some reason, and I can't remember why now. Stupid me didnt make a comment on that when I created the method.

But that also has something to do with the module weight.

sophie.sk’s picture

Hmm, interesting - I didn't spot that. Looking at the API page for that hook: https://api.drupal.org/api/drupal/modules!system!system.api.php/function... it suggests that hook_module_implements_alter() is not called if the module implementing it doesn't use hook_boot().

It looks like that call should do what I've done in the patch, but it's not. The internet suggests altering the weight of the module in that event.

eelkeblok’s picture

hook_boot is only indirectly connected to this problem. I've poured a considerable amount of time into finding out why hook_implements_alter was not being called for fences in one of my projects and ended up in this issue: https://www.drupal.org/node/1224956. I did end up with changing the module weight in that instance as well, which may be the only way until that issue is resolved.

anon’s picture

+++ b/linkit.install
@@ -81,6 +81,26 @@ function linkit_schema() {
+  if (module_exists('wysiwyg')) {
+    $wysiwyg_module_weight = db_select('system', 's')
+      ->fields('s', array('weight'))
+      ->condition('name', 'texting', '=')
+      ->execute()
+      ->fetchField();

texting? Shouldn't this be 'wysiwyg'?

sophie.sk’s picture

@anon Ha. Wow, not quite sure how I missed that :( I'll fix this in a short while.

mstrelan’s picture

Status: Needs work » Needs review
StatusFileSize
new922 bytes

Updated patch attached. I removed the check to see if the WYSIWYG module exists because it could be enabled after LinkIt is already installed. In that case the weight would still be 0. You could get around this by implementing hook_modules_enabled() but I think it would be safer if LinkIt always had the same weight. I also moved the logic to a separate function to reduce code reuse.

Status: Needs review » Needs work

The last submitted patch, 10: linkit-update_module_weight-2429353-10.patch, failed testing.

sophie.sk’s picture

StatusFileSize
new818 bytes
new966 bytes

@mstrelan, that seems sensible, although I'd put the helper function before the update functions. New patch attached, rolled against latest dev, and an interdiff for posterity.

I haven't actually used the Linkit module since I created this issue, so we may not need this feature anymore?

mark_fullmer’s picture

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

In order to help the community and the module maintainers focus work on the issues for this module that are most important to the Drupal community, I'm going to close this issue, as it is a feature request that does not have substantial work already and the issue hasn't been updated in many years.