Hi. Does anyone know if WYSIWYG has an option to cache the current form on button-press before running the invoke for the plugin? Alternatively, does anyone know how I could do this? :-)

I'm writing a plugin to launch a modal form allowing the user to select things to put stuff back into the editor. Currently it passes the form cache id into the modal form so it can access form data from the node form but this is only up-to-date when an AJAX call has been made or when the node is saved.

What i'd really like is to have a 'cache form' option I can set to true in the plugin hook so that I always have the latest form data available. Does this sounds worthwhile as a feature request or is it too specialised?



TwoD’s picture

Short answer; no. That sounds a bit out of scope for Wysiwyg module itself. You could trigger a dummy AJAX request when your plugin button is clicked, wait for the response, and then assume the form has been cached, if that helps.

But, I don't understand what you need from the cache at all, and how does that help you interact with the editor? The editor is all clientside and doesn't have a clue about the serverside cache... If you need to access the editor from within scripts loaded in the modal, don't you already have direct access to the main document's editor instances?

very_random_man’s picture

Fair enough. Thanks for the quick response.

The form embedded in my modal is using the form cache to get information about the state of the main node form, such as the number of values of a field using a specific formatter that I'm using. The module I'm writing combines functionality from the Field Injector and WYSIWYG modules.

TwoD’s picture

That is interesting, I've not seen that module before.

Would you mind if I could have a look at the code you have so far? I would like to get a better picture of how it works, or is supposed to work, and see if there maybe is something I could do from the perspective of Wysiwyg.

very_random_man’s picture

I've abandoned my original idea now as it was proving to be too time-consuming and I wasn't actually sure if it was possible anyway. ;-)

Here's a summary of how it was working FYI:

  • WYSIWYG toolbar button spawns a modal window
  • populated with an ajax request that returns a form from my module
  • the form is passed the original node form build id so it can load it from cache
  • a combination of this cached form and the field api is used to show a selection of fields that can be injected into the WYSIWYG
  • field and field collection previews are rendered with a custom view mode provided by my module so field formatters and templates are applied

This worked fine in principle but the previews were only up-to-date after the node was saved. I was hoping that if I could cache the form when the button was pressed, the rest of the module would work with whatever values were in the form. I tried a few things (e.g. POSTing the form) but it was chewing up too much time and I wasn't getting the kind of results I was looking for.

I chose a front-end solution in the end (i.e. modal form is build in jQuery and not with an AJAX request) which has the advantages of speed and always using the typed values in the form, regardless of saved state. The disadvantage is that fields aren't pushed through the standard rendering system so markup is different but previews can be approximately styled with just css.

It's working quite nicely for my current project. I'm hoping to get time to develop it further and contribute it.

TwoD’s picture

Status: Active » Closed (won't fix)

Ah, I understand now, and see why you abandoned it.

I'll close this then, if you don't mind.

Btw, be careful rendering the field previews, you don't want to create security holes by not filtering the values before rendering. ;)