Posted by kenorb on December 17, 2008 at 2:56pm
Jump to:
| Project: | Install Profile API |
| Version: | 6.x-2.x-dev |
| Component: | Documentation |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
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.
Comments
#1
Isn't this the status you mean?
#2
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
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
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
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
Actually I think not CCK, but Install Profile API.
#7
I'm very reluctant to add a function like
cck_install_content_dir()because it implies we should have a function like this for every Install Profile API helper function that imports objects from flat-file exports (views, node_export, taxonomy_export .. etc).On the other hand I agree that I use the
foreach (glob($path . '/*.inc') as $file) { ... }pattern way to much in my install profiles. Maybe a generic directory import function is what we need?