Closed (fixed)
Project:
Chaos Tool Suite (ctools)
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 May 2012 at 19:08 UTC
Updated:
11 Jun 2012 at 16:51 UTC
I have custom content type that is basically a NID. My add form collects NID, my render callback renders node from NID. I would like my edit form to show node edit form from NID. I get a form to display, but got problems with image field. After ajax request it throws errors.
Very simplified code that adds node edit form to my edit form. Image content type has image field.
<?php
global $user;
module_load_include('inc', 'node', 'node.pages');
$node = (object) array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => 'image', 'language' => LANGUAGE_NONE);
$form += node_form($form, $form_state, $node);
?>
Comments
Comment #1
henrijs.seso commentedNotice: Undefined index: maga_pane_content_type_edit_form in drupal_retrieve_form() (line 760 of ...includes\form.inc).
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'maga_pane_content_type_edit_form' was given in drupal_retrieve_form() (line 795 of ...includes\form.inc).
Notice: Undefined index: field_image_image in file_ajax_upload() (line 271 of ...modules\file\file.module).
Notice: Undefined index: #suffix in file_ajax_upload() (line 280 of...modules\file\file.module).
Comment #2
merlinofchaos commentedYou need to add the file you're including to the form state. Use form_load_include() instead.
Comment #3
henrijs.seso commentedIm sorry, I still cannot seem to get it. Below is bare minimum of code that shows new image node form and still fails on upload button.
I looked at ctools and see ctools_form_include() and ctools_form_include_file(), could these help? I looked at Fieldable panels panes code, which seemed recent and dealt with field forms. In both modules i see in comments "module_load_include uses an unfortunately annoying syntax to work..." and then I see some arrays like $form_state['build_info']['files']["$module:$name.$type"]. Should I build such array for node form? Which "files" needs to be included? In short, what would be approximate code or workflow to get this to work?
May be related: I also noticed that code above works for 'add form' in plugin defined as function ctools_node_content_type_content_types($plugin) (it uses ctools node content_type?), but not in my custom $plugin array. Also noticed that fieldable_panels_panes defines plugin as function instead of $plugin array, with following comment: "We have to use this because the form here can be loaded via form caching and if this .inc file is loaded before the plugin is requested, the $plugin = array() notation doesn't work." Could this be a problem? Or (more likely) code above is shitty.
Comment #4
henrijs.seso commentedI managed my node edit forms to work by cloning, hacking and adapting fieldable_panels_panes. It looks like following code makes the difference (in add form, before calling
form_load_include($form_state, 'inc', 'node', 'node.pages');)I wonder if this is already somewhere in ctools module?
Comment #5
swentel commentedAs merlinofchaos pointed out, use form_load_include(). Subtle detail however: you changed the module_load_include to form_load_include() to include the node.pages.inc file, but what you should actually include is the file of your custom content type.