I am getting this warning after uploading a new file:

Warning: json_encode(): recursion detected in drupal_json_encode() (line 4972 of /var/www/vlw/includes/common.inc).

Any help?
my setup is drupal 7.19, media 7.x-2.x dev, file entity 7.x-2.x dev.

thanks in advance

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gmclelland’s picture

This might be same thing as #1409068: Popup not closing I get this as well and haven't yet figured it out. I'll let the maintainers determine if this is a duplicate or a separate issue.

Let me know if you figure it out.

Jc Denton’s picture

Ok thanks.

This is happening when i upload a file and filling the custom fields i created for this file.

If i find anything i' ll post back

gmclelland’s picture

I was able to reproduce this on a fresh install with the following basic modules:

projects[ctools][version] = "1.x-dev"
projects[ctools][subdir] = "contrib"

projects[file_entity][version] = "2.x-dev"
projects[file_entity][subdir] = "contrib"

projects[media][version] = "2.x-dev"
projects[media][subdir] = "contrib"

projects[entity][version] = "1.x-dev"
projects[entity][subdir] = "contrib"

projects[views][version] = "3.x-dev"
projects[views][subdir] = "contrib"

Steps to reproduce:
1. Add a file field to the basic page content type change the widget to "Media file selector".
2. Create a basic page node and a file.
3. Save the node.
4. Edit the node.
5. Edit the file and change the "Alt" text.
6. Press save in the ctools modal dialog
7. Save the node
8. Error is shown on node view

After saving the node you will see the error message:
Warning: json_encode(): recursion detected in drupal_json_encode() (line 4972 of /home/quickstart/websites/media.dev/includes/common.inc).
Warning: json_encode(): recursion detected in drupal_json_encode() (line 4972 of /home/quickstart/websites/media.dev/includes/common.inc).

I'm getting this error in a mac environment and a ubuntu environment.

Hope that helps

gmclelland’s picture

I wonder if this is somehow related to the following past issues:

#1553114: Adding files should be a multi-step process
specifically see - http://drupal.org/node/1553114#comment-6624650
- sort of seems like the same issues

#1848034: Remove ctools edit form after uploading a new file in media browser

Dave Reid’s picture

Can someone help put in a debug to see what is getting passed into drupal_json_encode()?

gmclelland’s picture

I placed the debug($var);

on the first line of drupal_json_encode() in common.inc

When I click edit on the file field it pops up the ctools modal dialog. I then change the Alt text to something different and hit save.

Immediately I get a js error dialog that says the following and I can't close the dialog unless I click "Close Window":

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /media/44/edit/ajax
StatusText: n/a
ResponseText: Fatal error: Nesting level too deep - recursive dependency? in /home/quickstart/websites/media.dev/includes/common.inc on line 7430
Call Stack:
0.0000     367240   1. {main}() /home/quickstart/websites/media.dev/index.php:0
0.0382    2942004   2. menu_execute_active_handler() /home/quickstart/websites/media.dev/index.php:21
0.0384    2943252   3. call_user_func_array() /home/quickstart/websites/media.dev/includes/menu.inc:517
0.0384    2943632   4. drupal_get_form() /home/quickstart/websites/media.dev/includes/menu.inc:0
0.0384    2944468   5. drupal_build_form() /home/quickstart/websites/media.dev/includes/form.inc:131
0.0384    2947544   6. drupal_retrieve_form() /home/quickstart/websites/media.dev/includes/form.inc:339
0.0385    2948860   7. call_user_func_array() /home/quickstart/websites/media.dev/includes/form.inc:798
0.0385    2949304   8. media_file_edit_modal() /home/quickstart/websites/media.dev/includes/form.inc:0
0.5463    3661280   9. ajax_render() /home/quickstart/websites/media.dev/sites/all/modules/media/includes/media.pages.inc:77
0.5469    3668284  10. drupal_json_encode() /home/quickstart/websites/media.dev/includes/ajax.inc:301
0.5469    3668284  11. debug() /home/quickstart/websites/media.dev/includes/common.inc:4963
0.5469    3668460  12. var_export() /home/quickstart/websites/media.dev/includes/common.inc:7430
ReadyState: undefined

@Dave Reid - Is that what you are looking for?

gmclelland’s picture

This is what is displayed when I click edit on the file field. The ctools edit file dialog is opened and this is what is shown.

Debug:
array (
  'basePath' => '/',
  'pathPrefix' => '',
  'ajaxPageState' => 
  array (
    'theme' => 'seven',
    'theme_token' => 'VxsnekP8l8MByL9mpR0FQi6exDL88KaInr3AYzl4ux0',
    'js' => 
    array (
      'misc/jquery.js' => 1,
      'misc/jquery.once.js' => 1,
      'misc/drupal.js' => 1,
      'misc/ui/jquery.ui.core.min.js' => 1,
      'misc/ui/jquery.ui.widget.min.js' => 1,
      'sites/all/modules/media/js/media.core.js' => 1,
      'misc/jquery.cookie.js' => 1,
      'misc/jquery.form.js' => 1,
      'misc/ui/jquery.ui.mouse.min.js' => 1,
      'misc/ui/jquery.ui.resizable.min.js' => 1,
      'misc/ui/jquery.ui.draggable.min.js' => 1,
      'misc/ui/jquery.ui.button.min.js' => 1,
      'misc/ui/jquery.ui.position.min.js' => 1,
      'misc/ui/jquery.ui.dialog.min.js' => 1,
      'sites/all/modules/views/js/jquery.ui.dialog.patch.js' => 1,
      'sites/all/modules/media/js/util/json2.js' => 1,
      'sites/all/modules/media/js/util/ba-debug.min.js' => 1,
      'misc/vertical-tabs.js' => 1,
      'misc/form.js' => 1,
      'misc/states.js' => 1,
      'misc/ajax.js' => 1,
      'sites/all/modules/admin_menu/admin_menu.js' => 1,
      'misc/progress.js' => 1,
      'sites/all/modules/ctools/js/modal.js' => 1,
      'sites/all/modules/media/js/media.popups.js' => 1,
      'sites/all/modules/media/js/media.js' => 1,
      'misc/textarea.js' => 1,
      'modules/field/modules/text/text.js' => 1,
      'modules/filter/filter.js' => 1,
      'misc/collapse.js' => 1,
      'modules/menu/menu.js' => 1,
      'modules/path/path.js' => 1,
      'modules/comment/comment-node-form.js' => 1,
      'misc/autocomplete.js' => 1,
      'modules/node/node.js' => 1,
    ),
    'css' => 
    stdClass::__set_state(array(
       'modules/system/system.base.css' => 1,
       'modules/system/system.menus.css' => 1,
       'modules/system/system.messages.css' => 1,
       'modules/system/system.theme.css' => 1,
       'modules/system/system.admin.css' => 1,
       'misc/ui/jquery.ui.core.css' => 1,
       'misc/ui/jquery.ui.theme.css' => 1,
       'misc/ui/jquery.ui.resizable.css' => 1,
       'misc/ui/jquery.ui.button.css' => 1,
       'misc/ui/jquery.ui.dialog.css' => 1,
       'sites/all/modules/media/css/media.css' => 1,
       'misc/vertical-tabs.css' => 1,
       'modules/comment/comment.css' => 1,
       'modules/field/theme/field.css' => 1,
       'modules/node/node.css' => 1,
       'modules/search/search.css' => 1,
       'modules/user/user.css' => 1,
       'sites/all/modules/views/css/views.css' => 1,
       'sites/all/modules/admin_menu/admin_menu.css' => 1,
       'sites/all/modules/admin_menu/admin_menu.uid1.css' => 1,
       'sites/all/modules/ctools/css/ctools.css' => 1,
       'sites/all/modules/ctools/css/modal.css' => 1,
       'modules/shortcut/shortcut.css' => 1,
       'modules/filter/filter.css' => 1,
       'themes/seven/reset.css' => 1,
       'themes/seven/style.css' => 1,
       'themes/seven/ie.css' => 1,
       'themes/seven/ie7.css' => 1,
       'themes/seven/ie6.css' => 1,
    )),
  ),
  'CToolsModal' => 
  array (
    'loadingText' => 'Loading...',
    'closeText' => 'Close Window',
    'closeImage' => '<img typeof="foaf:Image" src="http://media.dev/sites/all/modules/ctools/images/icon-close-window.png" alt="Close window" title="Close window" />',
    'throbber' => '<img typeof="foaf:Image" src="http://media.dev/sites/all/modules/ctools/images/throbber.gif" alt="Loading" title="Loading..." />',
  ),
  'media' => 
  array (
    'elements' => 
    array (
      'edit-field-media-und-0' => 
      array (
        'global' => 
        array (
          'types' => 
          array (
            'image' => 'image',
          ),
          'enabledPlugins' => 
          array (
            'upload' => 'upload',
            'media_default--media_browser_1' => 'media_default--media_browser_1',
            'media_default--media_browser_my_files' => 'media_default--media_browser_my_files',
            'media_internet' => 'media_internet',
          ),
          'schemes' => 
          array (
            'public' => 'public',
            'private' => 'private',
          ),
          'file_directory' => '',
          'file_extensions' => 'txt pdf doc docx xls xlsx jpg png gif',
          'max_filesize' => '50 MB',
          'uri_scheme' => 'public',
        ),
      ),
    ),
    'browserUrl' => '/media/browser?render=media-popup',
    'styleSelectorUrl' => '/media/-media_id-/format-form?render=media-popup',
  ),
  'tagmap' => 
  array (
  ),
  'states' => 
  array (
    '#edit-menu--2' => 
    array (
      'invisible' => 
      array (
        'input[name="menu[enabled]"]' => 
        array (
          'checked' => false,
        ),
      ),
    ),
    '#edit-revision' => 
    array (
      'checked' => 
      array (
        'textarea[name="log"]' => 
        array (
          'empty' => false,
        ),
      ),
    ),
  ),
  'anonymous' => 'Anonymous',
  'tableHeaderOffset' => 'Drupal.admin.height',
  'admin_menu' => 
  array (
    'destination' => 'destination=node/3/edit',
    'hash' => '44b4c3c5ca87ee9a904d48a9d42d5463',
    'basePath' => '/admin_menu',
    'margin_top' => 1,
    'position_fixed' => 1,
  ),
)
in drupal_json_encode() (line 4963 of /home/quickstart/websites/media.dev/includes/common.inc).
ParisLiakos’s picture

Title: ctools_modal_form_wrapper returns form array instead of ajax_commands array » json encode warning
Project: Chaos Tool Suite (ctools) » D7 Media
Version: 7.x-1.x-dev » 7.x-2.x-dev
Component: Modal » Media Browser

well debugged this a bit, and to me it seems the problem is in ctools.

in media_file_edit_modal, ctools_modal_form_wrapper returns a form build array instead of ajax commands..this shouldnt happen, cause media actually sends this array to ajax_render, which guess what..it expects ajax commands^^
dunno, what the reason for that is, and i am not a ctools expert, but imo ctools_modal_form_wrapper does something wrong.....or media needs extra check on what the array is before sending it over to ajax_render?

ParisLiakos’s picture

Title: json encode warning » ctools_modal_form_wrapper returns form render array instead of ajax_commans array
Project: D7 Media » Chaos Tool Suite (ctools)
Version: 7.x-2.x-dev » 7.x-1.x-dev
Component: Media Browser » Modal

lets ask folks over there

ParisLiakos’s picture

Title: ctools_modal_form_wrapper returns form render array instead of ajax_commans array » ctools_modal_form_wrapper returns form array instead of ajax_commands array
gmclelland’s picture

Title: json encode warning » ctools_modal_form_wrapper returns form array instead of ajax_commands array
Project: D7 Media » Chaos Tool Suite (ctools)
Version: 7.x-2.x-dev » 7.x-1.x-dev
Component: Media Browser » Modal

Thank you @rootatwc for checking into this. Just to note: I did try this with ctools-1.x-dev, 1.2, and 1.1 just to see if the problem was introduced by a new version. Unfortunately the bug is showing in all those versions.

shaisamuel’s picture

Thank you @gmclelland. Your #3 process is where I have the same error, using:

  • D7.20
  • File entity 7.x-2.0-unstable7+43-dev
  • Media 7.x-2.0-unstable7+34-dev
gmclelland’s picture

@rootatwc - I just tested a clean install with the following:

Media 2.0-unstable7
File Entity 2.0-unstable7
Ctools 1.2

I'm not getting any errors with this setup. That's one step closer to finding the problem.

gmclelland’s picture

@rootatwc - It took me a long time, but I think I found the problem.

The last File Entity module commit that works without errors is http://drupalcode.org/project/file_entity.git/commit/cffe49222253e0426e6...

Starting with this commit, the errors start appearing http://drupalcode.org/project/file_entity.git/commit/2fec0d7ce40fd3fee5f...

Hope that helps

Maybe this issue should be moved to the file_entity issue queue?

At the moment, I'm also testing with Media-2.x 0d2eefc

ParisLiakos’s picture

nope. that commit just exposed the ctools bug i think

merlinofchaos’s picture

Ok, I agree that the doxy for ctools_modal_form_wrapper is out of date, and reflects the Drupal 6 state of form api. In today's world, if successfully executed, it will still return a render array. This did not used to be available.

However, there's still a bug, I think, in the media code:

  $output = ctools_modal_form_wrapper('file_entity_edit', $form_state);

  if ($js) {
    $commands = $output;

    if ($form_state['executed']) {
      $commands[] = ctools_modal_command_dismiss(t('File saved'));
    }

    print ajax_render($commands);
    exit();
  }

Even if you take CTools at its word, if the form is executed, $output should be NULL.

That makes $commands[] = ... still invaliad, because you're adding an array to NULL which isn't legal. If $form_state['executed'] is set to TRUE, then $commands should be re-built from scratch. This is especially true because now FAPI will still return a render array which I won't throw away. So CTools function documentation should be adjusted to reflect that it will return the raw render array which you can then do with what you will. (Probably throw away, but there have been times when I've found it *very* useful upon form execution, since data can be stored in it).

I believe changing the $commands[] = to $commands = array(

should be sufficient to fix media.

gmclelland’s picture

Project: Chaos Tool Suite (ctools) » D7 Media
Version: 7.x-1.x-dev » 7.x-2.x-dev
Component: Modal » Code
Status: Active » Needs review
FileSize
490 bytes

Yay! That fixes it. Great catch @merlinofchaos.

Here is the patch against the Media module-2x-dev.

Moving this back to Media issue queue.

ParisLiakos’s picture

Project: D7 Media » Chaos Tool Suite (ctools)
Version: 7.x-2.x-dev » 7.x-1.x-dev
Component: Code » Documentation
Category: bug » task

awesome, thanks for the quick patch
Committed and pushed
http://drupalcode.org/project/media.git/commit/5c497f5

Back to ctools, for documentation fix

Status: Needs review » Needs work

The last submitted patch, 17: media-fix-ctools-modal-form-file-editing-1909408.patch, failed testing.

mrjmd’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.6 KB

From my reading of this issue, all that's left is a documentation update to ctools function ctools_modal_form_wrapper(). I've rolled and attached a patch.

DamienMcKenna’s picture

Status: Needs review » Reviewed & tested by the community

Good to go.

mrjmd’s picture

japerry’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +SprintWeekend2015

Looks good to me. Committed.

  • japerry committed c5ac9bf on 7.x-1.x authored by mrjmd
    Issue #1909408 by gmclelland, mrjmd: ctools_modal_form_wrapper returns...

Status: Fixed » Closed (fixed)

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