Content type groups was designed to handle the use case when you need to populate select boxes or other interface elements with certain content types but not others. This module allows you to create an unlimited number of groups of content types through the UI. Once a group is created, it can be referenced in code using API functions and in Views.

Key Features

  • Unlimited content type groups
  • Integrates with Views filters
  • Ability to order content types within a group for display (in dev release)
  • API for managing groups programatically
  • Exporting using Features (dev release only)

Installation

  • Please see current README.txt.
  • Make sure to grant the "administer content types" permission.
  • Manage content type groups at Admin > Structure > Content types > Content type groups

Example

Let's say you're organizing your media collection. You have the following content types: book, movie, audio, article (for your blog about your collection), and page (for some static content).

Create a content type group called Media and add the book, movie and audio types. You have just created a logical grouping between the content types to show that they are related. This makes it easier for future developers to understand the relationship between various content types.

Now let's say you start collecting old magazines. You create a new content type called magazine and add it to the Media content type group. Any place where Media is referenced will automatically reflect the change; there is no need to track down all Views or lists.

Views Integration

Once enabled, this module exposes a filter for use in filtering nodes to those only of a type belonging to a given content type group. Let's walk through this with the Media content type group (see Example).

You have a View that shows all nodes and you want to filter it to only show nodes that are of your media content. The traditional way is to add a filter on Content: Type and select those types (i.e. book,movie, audio), but this means that every time you add a media content type, you have to remember to go back to your View and add that to the filter criteria.

Instead, we're going to tell the View to only show nodes that are in the Media content type group. Select content type groups from the Filter dropdown in the Filter Criteria section. Select the single option: Content type groups: Content type group. From the Options list, select Media, then save the filter.

You should see your list of nodes in the preview restricted to only those with a content type within the Media content type group. Now if you add a new content type to the Media group, the View will automatically update to show you the additional nodes.

API

This module provides a utility class ContentTypeGroup that can be used in your own custom module development. A common use case for this will be to fill the options of a form element such as a select list or checkboxes.

$group = new ContentTypeGroup('media'); // Get the content type group by its machine name
$form['my_element'] = array(
  '#title'   => t('Media Types'),
  '#type'    => 'checkboxes',
  '#options' => $group->typeList(), // Returns an array keyed as $content_type => $type
);

You can also use the class to programmatically create, edit and delete content type groups; see the in-module documentation for more information.

Version 2.x

This module is being rewritten to turn content type groups into entities, with a dependency on Entity API. The 2.x branch is heavily under development and not ready for any site use.

Project Information

Downloads