Posted by dropchew on January 2, 2010 at 4:55am
11 followers
| Project: | Dialog API |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Issue Summary
Hi,
I have use dialog_get_form on a simple FAPI form i built through a module and it works great. However it throws an "arg 2 not found error on node_form()" when i tried in on node add page.
Is there a example module that loads a node/add/edit page in dialog api, just like the one in modal_frame example module? My concern is more on the file attachment handling in Dialog, like user upload avatar through dialog.
Thanks!
Comments
#1
Can you show me the code you are using to invoke dialog_get_form? node_form() is particularly tricky, even with the standard drupal_get_form, since the actually form id is something like 'node_page_form'.
#2
Hi,
my code is similar as below. eg, I wanted to add a page node type.
<?phpfunction dialog_page_add_menu() {
$items['node/add/page/%ctools_js'] = array(
'page callback' => 'dialog_get_form',
'page arguments' => array('page_node_form', 3),
'type' => MENU_CALLBACK,
'file' => 'node.pages.inc',
'file path' => drupal_get_path('module', 'node'),
);
return $items;
}
?>
#3
check out how node_add (http://api.drupal.org/api/function/node_add/6) builds a dummy node to pass to drupal_get_form. you will need to do something similar.
#4
#5
Automatically closed -- issue fixed for 2 weeks with no activity.
#6
Hi folks,
I've been playing with this after Modal Frame API drove me crazy and thanks to Dialog goodness, I am nearly there. I have a content type Person which has a CCK field which node references an Address content type. I have got my person node add form popping up the dialog to create the address node (based on Roger's suggestion to build a dummy node above) and I include my code below in case it helps anyone. I think it is what the original requester asked for.
On my person add node form I have added an 'Add a new address' link to the following URL - node/add/address/nojs
Then I have a module called dialogforms which does the dialog stuff. The code is below, apologies if it looks ugly, I'm new to all of this.
One thing, be careful of the 'explode' call in the dialogforms_nodes_callback function as it is a sort of generic callback function and for me none of my content types have underscores in their names. If yours do, you'll have to modify it. It's a bit ugly I guess, but it's just a prototype to see if I could get it to work.
The only problem I have is that on submitting the form I reload the person add node form which is alright, but ideally I want to just reload the address CCK field in that form to include the address I just added, but I have no idea how to do that. In another issue I see Roger you say
I have created that function as you will see below, but is it limited to the ctools ajax functions? Is there a way to get them to just reload the CCK field? Or is there something else I can do. As I said, I'm new to this so swimming in the dark a bit and any help would be greatly appreciated. Thanks for a great module!
<?php
/**
* Implementation of hook_init().
*/
function dialogforms_init() {
dialog_add_js();
}
/**
* Implementation of hook_menu().
*/
function dialogforms_menu() {
$items['node/add/address/%ctools_js'] = array(
'page callback' => 'dialogforms_nodes_callback',
'page arguments' => array('address_node_form'),
'access callback' => 'user_access',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
'file' => 'node.pages.inc',
'file path' => drupal_get_path('module', 'node'),
);
return $items;
}
function dialogforms_nodes_callback($fid) {
global $user;
$type_arr = explode('_', $fid);
$node_type = $type_arr[0];
$types = node_get_types();
$node_type = isset($node_type) ? str_replace('-', '_', $node_type) : NULL;
// If a node type has been specified, validate its existence.
if (isset($types[$node_type]) && node_access('create', $node_type)) {
// Initialize settings:
$node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $node_type, 'language' => '');
drupal_set_title(t('Create @name', array('@name' => $types[$node_type]->name)));
$output = dialog_get_form($node_type .'_node_form', $node, $node);
}
return $output;
}
function address_node_form_dialog_success() {
$commands = array();
$commands[] = ctools_ajax_command_reload('node/add/person');
ctools_ajax_render($commands);
}
#7
i think we should add a generic node add/edit functionality.
This patch - a work in progress adds node-add as dialog. Patch also starts cleaning up dialog_example.
settings to needs review, to get early feedback.
#8
I expanded on Amitaibu's patch to add node edit functionality. I had issues with the whole adding files patching nonsense, so I am just uploading the whole module.
To use this module (or Amitaibu's patch) one needs to create their own links (this does not override the normal node add/edit pages).
E.G.
<?phpprint l('edit','dialog/node-edit/nojs/'.$nid,array('attributes'=>array('class'=>'ctools-use-dialog')));
print l('create','dialog/node-add/nojs/story',array('attributes'=>array('class'=>'ctools-use-dialog')));
?>
Also I am wondering how can I debug the $commands array. dpm($commands) watchdog(..), etc yield nothing if triggered after the $commands array is created. I am baffled?
#9
Looks like there's a module for this already: http://drupal.org/project/dialognode
Anyone disagree with the fixed status?
#10
That module is actually for viewing a node not add/ update.
But anyway, I'm not sure if this functionality is easily done with Dialog.
#11
Automatically closed -- issue fixed for 2 weeks with no activity.
#12
Any news on this?
#13
This is not fixed.
#14
I needed this functionality on a live site and tested and corrected the proposed patch. It's working fine.
Additionaly, there is now support for hierarchical select fields on the node form.
#15
I used the work in #8 and extended it quite a bit to support all node CRUD. I've been using the module for a few months.
http://drupal.org/sandbox/bangpound/1317400