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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | interdiff-2429353-10-12.txt | 966 bytes | sophie.sk |
| #12 | linkit-update_module_weight-2429353-12.patch | 818 bytes | sophie.sk |
Comments
Comment #1
sophie.skAs 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.
Comment #2
sophie.skFinally 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:But it seems that at the time this is run, there's no
wysiwyg_pre_render_text_formatpre-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.
Comment #3
sophie.skComment #5
anonWe 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.
Comment #6
sophie.skHmm, 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.
Comment #7
eelkeblokhook_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.
Comment #8
anontexting? Shouldn't this be 'wysiwyg'?
Comment #9
sophie.sk@anon Ha. Wow, not quite sure how I missed that :( I'll fix this in a short while.
Comment #10
mstrelan commentedUpdated 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.Comment #12
sophie.sk@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?
Comment #13
mark_fullmerIn 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.