First of all, my current setup is the 7.x-2.x-dev Wysiwig version using the CKEditor v4.5.11 plugin on a 7.50 Drupal installation(it seems that this is valid for higher versions too) with most recent versions of Workbench, Workbench Moderation and Workbench Email.

While editing some node's content, when changing the moderation state in the "Publishing Options" tab to Published I got an error duting the AJAX call as you can check:
Ajax error 1
Ajax error 2

The error is actually related to the implementation of Drupal.ajax.prototype.beforeSerialize in the wysiwyg.js file on line 864. After some research I found the implementation of this function in an older Drupal installation inside the misc/ajax.js on line 282 and the code was indeed similar, but as soon as I searched for the same file on my current Drupal setup, i found a difference as you can see (Ajax.js | Wysiwyg.js):
Code differences

This explains the error related to the drupal_html_id function expecting a string and receiving an array as the current wysiwyg.js code passes an [] together with the index on the data. Also you can confirm that this is the problem by checking the docs for the drupal_html_id function, where you can see it retrieving ajax_html_ids from the $POST superglobal instead of ajax_html_ids[]. We need a patch to fix that situation.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davic created an issue. See original summary.

davic’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
510 bytes

Just updated the Summary with the screenshots references. I also created a patch to fix the situation, can anyone please review the issue and the solution provided?

davic’s picture

Issue summary: View changes
FileSize
22.57 KB

Updating the size of the images on the summary and updated screenshot.

davic’s picture

Issue summary: View changes
davic’s picture

Issue summary: View changes
maikelfinck’s picture

Assigned: davic » maikelfinck
maikelfinck’s picture

To enable the AJAX validation when changing the value of "Moderation state" we also need to enable the module workbench_email.

maikelfinck’s picture

Issue summary: View changes
davic’s picture

Issue summary: View changes

As an update, i found out directly in the drupal.org docs for the drupal_html_id function that it expects the index 'ajax_html_ids' index instead of 'ajax_html_ids[]', as you can confirm on the documentation provided by looking for code>$_POST['ajax_html_ids'];

TwoD’s picture

Status: Needs review » Postponed (maintainer needs more info)

The screenshot comparing code is not from any Drupal version I know of. The relevant lines in misc/ajax.js have not been changed since 2010 and do use the same syntax as wysiwyg.js does.

drupal/misc/ajax.js lines 310-341:

Drupal.ajax.prototype.beforeSerialize = function (element, options) {
  // Allow detaching behaviors to update field values before collecting them.
  // This is only needed when field values are added to the POST data, so only
  // when there is a form such that this.form.ajaxSubmit() is used instead of
  // $.ajax(). When there is no form and $.ajax() is used, beforeSerialize()
  // isn't called, but don't rely on that: explicitly check this.form.
  if (this.form) {
    var settings = this.settings || Drupal.settings;
    Drupal.detachBehaviors(this.form, settings, 'serialize');
  }

  // Prevent duplicate HTML ids in the returned markup.
  // @see drupal_html_id()
  options.data['ajax_html_ids[]'] = [];
  $('[id]').each(function () {
    options.data['ajax_html_ids[]'].push(this.id);
  });

  // Allow Drupal to return new JavaScript and CSS files to load without
  // returning the ones already loaded.
  // @see ajax_base_page_theme()
  // @see drupal_get_css()
  // @see drupal_get_js()
  options.data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
  options.data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
  for (var key in Drupal.settings.ajaxPageState.css) {
    options.data['ajax_page_state[css][' + key + ']'] = 1;
  }
  for (var key in Drupal.settings.ajaxPageState.js) {
    options.data['ajax_page_state[js][' + key + ']'] = 1;
  }
};

PHP automatically turns multiple POST:ed keys with the same name ending in [] into an array once they've reached the server.

If the patch suggested here is applied it effectively adds a second parameter containing the filtered list of element ids, while leaving the original list untouched. That pretty much guarantees the server will reject the message due to the excessive amount of POST parameters, the very problem this mechanism is intended to alleviate. This is easily verified by looking at the ajax request's headers in the browser's developer tools.

Could you be more specific as to why you think Wysiwyg is involved in this, and perhaps figure out exactly how old that code sample from core was?