Download & Extend

Add dialog_node functionliaty

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

Status:active» postponed (maintainer needs more info)

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.

<?php
function 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

Status:postponed (maintainer needs more info)» active

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

Status:active» fixed

#5

Status:fixed» closed (fixed)

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

If a function exists following the format of [form_id]_dialog_success, it will be called and should return the appropriate ajax commands array. This is very similar to creating a [form_id]_submit function, but only gets called when in an ajax context.

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

Title:dialog_get_form on node add/edit page » Add dialog_node functionliaty
Category:support request» feature request
Status:closed (fixed)» needs review

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.

AttachmentSize
node-add-dialog.patch 5.51 KB

#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.

<?php
print 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?

AttachmentSize
dialog_node.zip 1.8 KB

#9

Status:needs review» fixed

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

Status:fixed» closed (fixed)

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

#12

Any news on this?

#13

Status:closed (fixed)» active

This is not fixed.

#14

Status:active» reviewed & tested by the community

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.

AttachmentSize
dialog_node_form_api.patch 4.39 KB

#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