programmatically creating a new node type

beginner - September 7, 2006 - 13:57
Project:Drupal
Version:x.y.z
Component:forms system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:by design
Description

Trying to programmatically create a new node type, I do:

<?php
$values
['name'] = 'node type test';
$values['type'] = 'node_type_test';
$values['description'] = 'my description.';
$values['comment'] = 0;
drupal_execute('node_type_form', $values);
?>

but I get:

warning: call_user_func_array(): First argumented is expected to be a valid
callback, 'node_type_form' was given in /includes/form.inc on line 181.

I am puzzle because the function does exist in modules/node/content_types.inc:

<?php
function node_type_form($type = NULL) {
?>

#1

chx - October 9, 2006 - 12:36
Status:active» won't fix

yes but you need to include that inc.

#2

beginner - October 9, 2006 - 14:59
Status:won't fix» active

with Drupal 5, we are supposed to be able to programmatically submit forms using drupal_execute(), and if you cannot do so, it is a bug.
I just don't understand the reason for this particular bug, yet.

#3

chx - October 9, 2006 - 16:26
Status:active» won't fix

the form you are submitting to is not included automatically on every page load, you need to do that by hand.

#4

beginner - October 10, 2006 - 03:10
Status:won't fix» active

So?
How do I programmatically submit a form to create a new node type?

#5

beginner - October 10, 2006 - 03:11
Status:active» won't fix

Oh! I see what you mean... let me try...

#6

beginner - October 10, 2006 - 03:20
Status:won't fix» by design

Now that you have shown me, TWICE, the solution, I find it's obvious and I kick myself for not having thought about it myself!!

I apologize for being so thick-headed!

The missing line:

<?php
include_once './'. drupal_get_path('module', 'node') .'/content_types.inc';
?>

 
 

Drupal is a registered trademark of Dries Buytaert.