As also indicated in #1944318: Document security concerns of localStorage useage on module page, the way this module "integrates" Garlic is extremely minimal/superficial, and definitely suboptimal. It's a good first step though :)

Contrast that with the patch at #153313-118: ckeditor input is lost when using the browser's back button, which attempted to add Garlic.js to Drupal 8. It guarantees only appropriate form fields are saved, it guarantees that it works when multiple forms exist on the same page, it guarantees proper expiration when working with e.g. the node form.

Please learn and copy/paste code from that patch :) It'll make this module much more useful!

Comments

minoroffense’s picture

I can see what I can do. But that is a very large patch. Perhaps break it down into parts and individual tasks to make our lives easier for adding additional integration.

wim leers’s picture

That patch contains the library itself *and* tests. The relevant parts are very small, actually.

chellman’s picture

Issue summary: View changes
StatusFileSize
new3.93 KB

I've been investigating autosave, and hadn't heard of Garlic.js, let alone the D8 issue trying to integrate it. But I could really use this for Drupal 7, so here's an initial cut at backporting the goods from that D8 issue.

There's nothing in here to auto-connect any forms to Garlic - you still would need to hook_form_alter the ones you want to enable it on. If this actually works for other people, I wouldn't mind throwing in a settings screen to enable it on node edit forms by default, say.

There's also some extra work needed for Garlic to work on WYSIWYG-enabled textareas, but not much. The following worked for me, as long as you have CKEditor 4.2+ installed:

CKEDITOR.editorConfig = function( config ) {
	CKEDITOR.on('instanceReady', function (ev) {
		// when the content changes, update the underlying textarea
		ev.editor.on('change', function (ev) {
			ev.editor.updateElement();
		});
	});
}
chellman’s picture

Status: Active » Needs review
minoroffense’s picture

Priority: Critical » Normal
jbrown’s picture

$form_id = str_replace('_', '-', $form_id);

before passing to js.

plazik’s picture

Ckeditor code from #3 doesn't work for me.
Here is working code for 4.5:

Drupal.behaviors.ckeditorCustomConfig = {
  attach: function (context, settings) {
    if (typeof(CKEDITOR) != 'undefined') {
      CKEDITOR.on('instanceCreated', function(e) {
        e.editor.on('change', function (event) {
          e.editor.updateElement();
        });
      });
    }
  }
};

franz’s picture

StatusFileSize
new4.3 KB

Some updates here:

  1. Reverted library being added form (was causing garlic not to load)
  2. Addressed #6, but using the actual $form['#id'] which is the correct way (think about AJAX or multiple forms in page).
  3. Added #7, but had to add one more line to actually trigger garlic saving.
franz’s picture

I was using the garlic.js version in the make.example file.

franz’s picture

StatusFileSize
new4.31 KB

I was also having trouble with Autocomplete field + click + Chrome. Adding the "formUpdated" event to garlic options fixed.