I'm running into a problem creating a node on a non-node page using drupal_execute();. Here's the error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given in C:\htdocs\drupal6\includes\form.inc on line 340.

I know that node_form(); can be found in the node.pages.inc file, which appears to not be included because:

  1. I'm not on a node/add or node/%node/edit page.
  2. Nothing is being themed (the error is generated in drupal_retrieve_form();)

So, my question is whether there's a way to get this file included without implicitly including it with something like:

require_once drupal_get_path('module', 'node') . '/node.pages.inc');

Should this re-classified as a bug?

-Fractile81

Comments

asimmonds’s picture

I think drupal_execute() is somewhat of a edge case at the moment, it works but you have to be somewhat aware of what other code is required for the form to work properly, anyways I'm successfully using drupal_execute() to create content from within my install profiles for 6.x.
I use:

module_load_include('', 'node', 'node.pages.inc');

then the usual:

drupal_execute('page_node_form', $form_state, $node);

to create the node.

mpare’s picture

I'm running into similar issues using drupal_get_form, also effecting node_add, node_page_edit, etc... I'm still looking to see if I'm doing something stupid or if there really is an issue here.

mpare’s picture

Version: 6.0-beta4 » 6.x-dev
fractile81’s picture

Version: 6.x-dev » 6.0-beta4

So, yeah, I suppose that's the question, do we:

1) Do the module_load_include(); as asimmonds suggests (I like that a lot better than how I did it), or
2) Should form functions, as a standard, be pulled into the main module function for the sake of drupal_execute();?

As D6 is now in RC1, it might be a little late in the game for #2 to happen, mandating #1 for now. However, this might be something good to push into the D7 arena. Any thoughts on this would be appreciated!

fractile81’s picture

Version: 6.0-beta4 » 6.x-dev

Oops, cross-posted.

mpare’s picture

Project: Drupal core » Documentation
Version: 6.x-dev »
Component: node system » Developer Guide
Status: Active » Closed (fixed)

I don't think that this is really a core issue but a documentation issue for d.o. I'm updating node 114774, Converting 5.x Modules... to reflect this necessary step for loading node forms from third party modules. I'm also changing the issue to reflect this. I think this is part of the new optimization practices implemented in D6 but can't say that with 100% confidence that's just the obvious explanation. Also a change to the above posted code.

<?php
  module_load_include('', 'node', 'node.pages.inc')
?>

should probably read

<?php
  module_load_include('inc', 'node', 'node.pages');
?>

According to the api docs and out of the simple fact that it doesn't work.

If the change of status of this issue is incorrect please feel free to revert.

-mpare

mpare’s picture

I've updated the Module Conversion guide to reflect these new changes, http://drupal.org/node/114774#module_load_include.

shunting’s picture

Thanks. This was driving me nuts.

mpare @7, a small editorial tweak?

Now:

A common use for this implementation is when a custom module needs to load a node form

Suggested:

A common use for this implementation is when a custom module needs to load a node form (for example, via drupal_execute) ...

Now drupal_execute will show up in a search....

shunting’s picture

But don't we have a documentation bug in form.inc? This definitely makes drupal_execute look like a normal thing to do, and not at the bleeding edge.

This:

 * // Create a new node
 * $form_state = array();
 * $node = array('type' => 'story');
 * $form_state['values']['title'] = 'My node';
 * $form_state['values']['body'] = 'This is the body text!';
 * $form_state['values']['name'] = 'robo-user';
 * $form_state['values']['op'] = t('Save');
 * drupal_execute('story_node_form', $form_state, $node);

Should become this?

 * // Create a new node
 * $form_state = array();
 * $node = array('type' => 'story');
 * $form_state['values']['title'] = 'My node';
 * $form_state['values']['body'] = 'This is the body text!';
 * $form_state['values']['name'] = 'robo-user';
 * $form_state['values']['op'] = t('Save');
 * // include node_form
 * module_load_include('inc', 'node', 'node.pages');
 * drupal_execute('story_node_form', $form_state, $node);
mpare’s picture

I don't really think there is a bug in that specific location. If there is a documentation bug in core for this issue I believe it is probably in CHANGELOG.txt and that's if there is one. See this issue is much broader than just forms or node functions it pertains to the entire drupal core anytime you are needing to use functionality contained in a specialized include file. I dare not dictate this issue alone and other feed back from others is more than welcome and even encouraged.

alanmackenzie’s picture

Component: Developer Guide » Correction/Clarification

subscribing.