install content type during module install

kenorb - December 17, 2008 - 14:56
Project:Install Profile API
Version:6.x-2.x-dev
Component:Documentation
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Following function will help to install content types related to module during the module install hook:

/**
* Helper function to import a CCK content type definition from specified directory.
*
* @param $module
* @param $dir
*   The module which containing the CCK definitions.
* @param $ext
*   Extension
*/
function cck_install_content_dir($module, $dir = 'content_types', $ext = 'content') {
    $content_types = content_types();
    $files = file_scan_directory(drupal_get_path('module', $module) . '/' . $dir, "\.${ext}$");
    foreach ($files as $file) {
        module_load_include('inc', 'install_profile_api', 'contrib/content_copy');
        install_content_copy_import_from_file($file->filename);
    }
}

In example:

/**
* Implementation of hook_install().
*/

function my_module_install() {
    cck_install_content_dir('my_module');
}

Content files you should put into content_types/ directory into your module dir.

#1

dww - December 19, 2008 - 08:11
Component:Documentation» CRUD functions and includes
Category:support request» feature request
Status:fixed» active

Isn't this the status you mean?

#2

kenorb - December 19, 2008 - 10:18
Status:active» fixed

It was problem, but was fixed by my self.
Because Install Profile API is used for profiles, but I couldn't find solution for using it normally during module install.

#3

dww - December 19, 2008 - 16:51
Project:Install Profile API» Documentation
Version:6.x-1.x-dev» <none>
Component:CRUD functions and includes» New documentation
Category:feature request» task
Status:fixed» active

Oh, sorry, I missed the during the module install hook part of your post.

Anyway, a lone issue in the Install profile API queue isn't going to be a very useful or visible place for this information/code example. ;) I suggest you make it a handbook page somewhere in an appropriate "snippet" area of the d.o documentation.

#4

kenorb - December 19, 2008 - 18:23
Assigned to:kenorb» Anonymous

First place where I'm trying to find and solve my problem is the Issue tracking section:) Because people have a problem, and other people solve them.

But it's good idea to add cck_install_content_dir() into this module, it will help install the whole dir of contents without specifying each file.
But line with module_load_include('inc', 'install_profile_api', 'contrib/content_copy') should be moved outside foreach or if it will be integrated with module, can be deleted.

#5

jhodgdon - May 18, 2009 - 19:54
Project:Documentation» Content Construction Kit (CCK)
Version:<none>» 6.x-2.x-dev
Component:New documentation» General
Category:task» feature request

I think this person was trying to get a function added to the CCK module.

So I am moving this issue to the CCK queue. If I have misunderstood, please feel free to move it back, but I don't believe this is a request for new documentation, but instead a request that a function be added to the CCK module.

I'm also not sure which component it belongs in or which version it was requested for. Hopefully the orginal poster is watching and will clarify.

#6

KarenS - May 18, 2009 - 20:14
Project:Content Construction Kit (CCK)» Install Profile API
Version:6.x-2.x-dev» 6.x-2.x-dev
Component:General» Documentation

Actually I think not CCK, but Install Profile API.

 
 

Drupal is a registered trademark of Dries Buytaert.