Download & Extend

programmatically creating a new node type

Project:Drupal core
Version:x.y.z
Component:forms system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (works as designed)

Issue Summary

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) {
?>

Comments

#1

Status:active» closed (won't fix)

yes but you need to include that inc.

#2

Status:closed (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

Status:active» closed (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

Status:closed (won't fix)» active

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

#5

Status:active» closed (won't fix)

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

#6

Status:closed (won't fix)» closed (works as designed)

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';
?>