Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
I'm not sure I understand exactly what your problem is.
Do you want to dynamically create new content types, say by letting users fill in a form or something similar?
If all you need is to create one new content type, you simply write a new module defining the new content type, see How to define content (node) types.
Thank's all,
but how can I create new content type with functionality same as CCK,
I try explain what I want.
So, I have drupal 5.1, many modules and among them CCK. I create 15 content type with different field form.
I know that when I will configure next site I must also create same content types. So I decide write module which add new content types in data base automaticly.
Please tell me how You decide this problem.
Thanks.
Wiith Drupal 5 you can export content types, this includes both content types created using CCK and even "extensions" to existing content types. Once exported you can import the information into the other instance of Drupal.
I'm currently working on a small module which use CCK content types. To make an nice installation, i wanted to include the creation of the content types in the .install file.
I saw 2 possibilities to do it.
The first possibility i have try was to look at the database after creating the content types and reflect the changes done by CCK as MySQL statements. It hasn't work yet but i think i was close to succeed.
After few tries i thought i was losing time and it would be better to use the export/import process (available using content_copy module) but Murphy was in the place (sorry for the small joke, i'm a little bit tired...).
The export/import process has work fine for me most of times (on other works), but sometimes, i wasn't able to export the content types i have created.
For example, a content type where i use a user reference field (which is called "client") returns me this message on export:
* client : Invalid user.
* The default value is invalid.
That's a little bit annoying, and it's only the beginning (unfortunately), because if i un-check the this field at export the other fields are exported correctly but in the import process i will also have some errors... (and i don't know if it is a bug or a feature)
Conclusion:
I think i will go back to the first possibility and look twice at the database changes. But i still think that for some developers it would be helpful to have a simple and concise "HOW-TO: create content types in your .install file".
PS: if i succeed and the way i did it doesn't look too crappy, i'll try to made the "HOW-TO", but if someone have already see something like that in the documentation, blame me (twice) and please give us a link ;)
Comments
Dynamically create new content types?
I'm not sure I understand exactly what your problem is.
Do you want to dynamically create new content types, say by letting users fill in a form or something similar?
If all you need is to create one new content type, you simply write a new module defining the new content type, see How to define content (node) types.
hook_node_info
Hi ibragim,
You need to write a new module. A node type basic info looks like that.
/**
* Implementation of hook_node_info()
*
* - create default "kontakt_datengraphy" node type
*/
function your node type_node_info() {
// The default node type is simple so we'll just use node as the base.
if (variable_get('kontakt_daten_nodetype', 'kontakt_daten') == 'kontakt_daten') {
return array('kontakt_daten' => array(
'name' => t('kontakt_daten'),
'module' => 'node',
'has_title' => TRUE,
'has_body' => TRUE,
'custom' => TRUE,
'modified' => TRUE,
'locked' => FALSE,
));
}
}
Dirk
.
Thank's all,
but how can I create new content type with functionality same as CCK,
I try explain what I want.
So, I have drupal 5.1, many modules and among them CCK. I create 15 content type with different field form.
I know that when I will configure next site I must also create same content types. So I decide write module which add new content types in data base automaticly.
Please tell me how You decide this problem.
Thanks.
Simplier approach
Wiith Drupal 5 you can export content types, this includes both content types created using CCK and even "extensions" to existing content types. Once exported you can import the information into the other instance of Drupal.
.
Can you explain how export content type more detail?
Exporting content definitions
With CCK installed this will work,
Goto ''Adminster' -> 'Content management' -> 'Content types'
On the pages will be a set of tabs, including 'export', click the tab
Select a content type to export and click 'Submit'
That works fine, sometimes...
I'm currently working on a small module which use CCK content types. To make an nice installation, i wanted to include the creation of the content types in the .install file.
I saw 2 possibilities to do it.
The first possibility i have try was to look at the database after creating the content types and reflect the changes done by CCK as MySQL statements. It hasn't work yet but i think i was close to succeed.
After few tries i thought i was losing time and it would be better to use the export/import process (available using content_copy module) but Murphy was in the place (sorry for the small joke, i'm a little bit tired...).
The export/import process has work fine for me most of times (on other works), but sometimes, i wasn't able to export the content types i have created.
For example, a content type where i use a user reference field (which is called "client") returns me this message on export:
* client : Invalid user.
* The default value is invalid.
That's a little bit annoying, and it's only the beginning (unfortunately), because if i un-check the this field at export the other fields are exported correctly but in the import process i will also have some errors... (and i don't know if it is a bug or a feature)
Conclusion:
I think i will go back to the first possibility and look twice at the database changes. But i still think that for some developers it would be helpful to have a simple and concise "HOW-TO: create content types in your .install file".
PS: if i succeed and the way i did it doesn't look too crappy, i'll try to made the "HOW-TO", but if someone have already see something like that in the documentation, blame me (twice) and please give us a link ;)
.
thanks all
create new content type
create new content type (drupal 6):
http://drupal.org/node/231019