I have a node view page with a list of related nodes on it. When I create a bunch of nodes that appear in the list of related nodes, and then view my page, I get an AJAX error from Edit:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /edit/attachments
StatusText: OK
ResponseText:
( ! ) Fatal error: Call to a member function getAttachments() on a non-object in /.../www/sites/all/modules/contrib/edit/includes/EditEditorSelector.php on line 90
Call Stack
#TimeMemoryFunctionLocation
10.0000715312{main}( )../index.php:0
20.05116040848menu_execute_active_handler( ???, ??? )../index.php:21
30.05146043432call_user_func_array
( string(16), array(0) )../menu.inc:517
40.05146043800edit_attachments( )../menu.inc:0
50.05176050584EditEditorSelector->getEditorAttachments( array(1) )../pages.inc:105

When I examine the POST array, I see a null editor being passed in:

Array
(
    [editors] => Array
        (
            [0] => 
        )

    [ajax_html_ids] => Array
        (
            [0] => skip-link
            [1] => toolbar
            [2] => toolbar-home
            ...

And it looks like EditEditSelector::getEditorAttachments() assumes that it will get a valid editor object back from _edit_get_editor_plugin(), which in this case it cannot possibly. The editor loading should handle the case where editors don't load.

This error really only appears when there are a bunch of new things in the list of related nodes--adding one new thing won't trigger it--and there is a separate error for each new related node.

Patch attached.

Comments

danepowell’s picture

Status: Active » Needs review

I was getting the same error and can confirm this patch fixes the problem, but I haven't investigated the cause or whether it's the best approach.

danepowell’s picture

Hmm... now I get a "request terminated abnormally" AJAX error. I wonder if that's in spite of or because of this patch?

wim leers’s picture

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

How can you get Edit to post array('editors' => array(0 => '')) to edit/attachments? Because that is the root cause, and I'd love to fix that. We need to fix the JS, not make the PHP schizophrenic :)

If you could post steps to reproduce, that'd be great!

danepowell’s picture

For me the problem occurs whenever I navigate away from a page containing Edit capabilities (either an individual node, or a view containing nodes) before the page finishes loading.

wim leers’s picture

I can't reproduce this. Which browser? Is your site very slow maybe?

danepowell’s picture

It only appears to happen in Chrome. I just tried in Firefox and did not get any errors. It has nothing to do with speed of the site I think, this is running on localhost :)

becw’s picture

StatusFileSize
new351 bytes

Well, I wouldn't call it "schizophrenic" to handle bad user input (ie, POST data that doesn't correspond to an editor_id, for one reason or another)--and perhaps throwing an exception would be a better solution for you? That said, fixing this at the javascript level too makes sense.

I get this error in both Chrome and Firefox. Our site is fairly slow, even on localhost, and it does seem like it is a race condition; when I add 4+ nodes that are listed alongside the primary node, and then visit that primary node, I get the error for each new listed node, but when I add just one new listed node, I don't get the error. I tried, but haven't been able to duplicate this error on a fresh drupal site.

As far as the javascript goes... the loadMissingEditors function in edit.js is called several times (once for each node displayed on the page). When this error happens, maybe the field models aren't fully loaded? I'm not sure why it looks like array('') at the PHP level, because when I look at what's being sent by the javascript it is just an array with length 0. The code checks for this case and calls the final callback immediately, but the AJAX commands are still run. Maybe the attached patch will illustrate this better--this change also prevents the error, for me.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Active
becw’s picture

I've been thinking about this and am wondering... generally (when this error isn't thrown) Edit posts an array of "missing" editors to the edit/attachments path like ['plain_text', 'form'] for each node that is rendered on the page. Is there a reason why this should happen for each node? Are editors re-used on the page, or do the editor attachments have to be loaded separately for each separate node?

danepowell’s picture

Patch in #7 (combined with OP) doesn't seem to stop this error:

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /oia/edit/attachments
StatusText: error
ResponseText: 
ReadyState: 0

Again, this happens any time I navigate to page with the Edit editor enabled and then navigate away quickly (in Chrome).

adriankremer’s picture

im getting the same errors. the patches didnt solve this error. i came across the same issue report but the fix focuses on drupal 8-dev: https://drupal.org/node/1941288 and it seems that this is an core issue (ajaxpagestate).

formatC'vt’s picture

this patch fix error

Fatal error: Call to a member function getAttachments() on a non-object in /.../www/sites/all/modules/contrib/edit/includes/EditEditorSelector.php on line 90

for me, but if you try to call edit mode via code described in this issue #2172989: Is it possible to print a custom link to quick edit? you get an error(when null editor being passed) in javascript TypeError: Drupal.edit.collections.entities.findWhere(...) is undefined. Another way to call edit mode is jQuery('#node-1 .quick-edit > a').click(); and this code always work fine.

wim leers’s picture

Title: AJAX error when nonexistent editor passed to edit/attachments » AJAX error when nonexistent editor passed to edit/attachments (and: multiple in-place editor attachment requests)
Project: Edit » Quick Edit
Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Fixed
Related issues: +#2324211: Multiple requests to /quickedit/attachments when only one should happen

We need to fix the JS, not make the PHP schizophrenic :)

Reading this again, I can see how this can easily be read as attacking. Apologies, because that's not what I meant to say!

That being said, I don't want the PHP to silently fail — I consider it great that you got a fatal error, because the JS POSTed an incorrect request to the server. Hence it's only appropriate that you're seeing a Fatal.

But, as you've already uncovered, the problem definitely lies in the JS: those multiple requests definitely shouldn't occur! You got close in #7 to explaining why that happened, but the cause and solution was slightly different yet. Your change in #7 is part of the solution, but it didn't address the fact yet that loadedEditors didn't include the editors that we've already requested previously. Doing that as well completely fixes the problem :)
That being said, your patch in #7 did completely and correctly fix the problem described in the issue title.

#7's investigation basically expanded the scope. I've opened a D8 issue, fixed it in D8 (#2324211: Multiple requests to /quickedit/attachments when only one should happen) and backported it to D7. I'm crediting you for the patch I rolled, because without #7, this would've gone unnoticed for a while longer!

Thank you very much!

  • Wim Leers committed 571d67e on 7.x-1.x authored by becw
    Issue #2191281 by becw: Fixed AJAX error when nonexistent editor passed...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Håvard’s picture

I´m getting the same error when using the WYSIWYG module instead of the CKeditor module. Not sure if Quickedit is supposed to work with WYSIWYG, but perhaps this is useful information.