With modules like CCK and Views developers rapidly create solutions with little custom module development. What if you need to deploy the same configuration of content types and views on multiple sites? The following example takes the power of the Views and CCK to create a sort of mashup module packaging your views and content type. I find this helpful time saver when having to repeat the same configuration on multiple sites.

The content types used in this example were created in Drupal using the "Add content type" menu (yoursite.com/admin/content/types/add) and exported using the content export feature (yoursite.com/admin/content/types/export .) Copy the code that the export produces in to the mashup/content/ folder as a file called CONTENTTYPE.cck, replacing CONTENTTYPE with the name of your content type.

The views are created in a similar fashion. Use the views UI to create your view and use the views export feature to produce the views code to use in the mashup. Copy the produced code into a a file named VIEWNAME.view, replacing VIEWNAME with your view name, in the mashup/views folder.

For a full example see the download attached at the bottom of the post.

Loading content types:
Used in mashup.install

/**
* Implementation of hook_enable().
*/
function mashup_enable() {
// Get the files content
$files = file_scan_directory(drupal_get_path('module', 'mashup'). '/content', '.cck');
foreach ($files as $path => $file) {
// Build form state
$content = implode ('', file ($path));
$form_state = array(
'values' => array(
'type_name' => '',
'macro' => $content,
),
);
drupal_execute("content_copy_import_form", $form_state);
}
}

Loading views:
Used in mashup/mashup.views_default.inc

**
* Implementation of hook_views_default_views().
* a neat trick from Lullabot to load views in a folder
*/
function mashup_views_default_views() {
$files = file_scan_directory(drupal_get_path('module', 'mashup'). '/views', '.view');
foreach ($files as $path => $file) {
require $path;
$views[$file->name] = $view;
}
return $views;
}

Load the views API:
Used in mashup/mashup.module

function mashup_views_api() {
return array('api' => 2, );
}

  1. Term Papers (not verified) on Wed, 12/23/2009 - 05:01
  2. Term Papers (not verified) on Wed, 12/23/2009 - 05:00

    This is cool, I would love to see more and a link back to your blog of course.
    Keep up this good work of helping others. Two thumbs for you.

    Term papers

  3. Term Papers (not verified) on Fri, 12/18/2009 - 05:06

    I'm very thankful to the author for posting such an amazing development post. Continuing to the post, This is a fantastic survey, very nice write up,Thanks you for sharing.

  4. Post new comment

    The content of this field is kept private and will not be shown publicly.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • Lines and paragraphs break automatically.

    More information about formatting options