You are here

content_type_groups.module in Content type groups 7.2

Same filename and directory in other branches
  1. 7 content_type_groups.module

Module file for the Content type groups module.

File

content_type_groups.module
View source
<?php

/**
 * @file
 * Module file for the Content type groups module.
 */
define('CONTENT_TYPE_GROUPS_ENTITY_NAME', 'content_type_group');
define('CONTENT_TYPE_GROUPS_ADMIN_PATH', 'admin/structure/type/groups');

// ---------------------------------------
// HOOKS
// ---------------------------------------

/**
 * Implements hook_help().
 */
function content_type_groups_help($path, $arg) {
  if ($path == 'admin/help#content_type_groups') {
    $output = '<h3>' . t('About') . '</h3>';
    $output .= '<p>' . t("The Content type groups module allows you to create groups of content types for reference in forms and views") . '</p>';
    $output .= '<p>' . t("The module provides a configuration screen allowing administrators to define an unlimited amount of content type groups") . '</p>';
    return $output;
  }
}

/**
 * Implements hook_node_type_update().
 *
 * Changes the node type references for content type groups.
 */
function content_type_groups_node_type_update($info) {
  if (isset($info->old_type)) {
    ContentTypeGroup::renameContentType($info->old_type, $info->type);
  }
}

/**
 * Implements hook_node_type_delete().
 *
 * Removes the references for the content type being deleted.
 */
function content_type_groups_node_type_delete($info) {
  ContentTypeGroup::removeContentType($info->type);
}

/**
 * Implements hook_theme().
 */
function content_type_groups_theme() {
  return array(
    'content_type_groups_group_form' => array(
      'render element' => 'form',
      'file' => 'content_type_groups.theme.inc',
    ),
  );
}

/**
 * Implements hook_views_api().
 */
function content_type_groups_views_api() {
  return array(
    'api' => 2,
  );
}

/**
 * Implements hook_features_api().
 *
 * This hook tells features this component is available for export.
 */
function content_type_groups_features_api() {
  return array(
    'content_type_groups' => array(
      'name' => t('Content type groups'),
      'default_hook' => 'content_type_groups_features_default_settings',
    ),
  );
}

// ---------------------------------------
// ENTITY
// ---------------------------------------

/**
 * Implements hook_entity_info().
 */
function content_type_groups_entity_info() {
  return array(
    // Content Type Group entity definition
    'content_type_group' => array(
      'module' => 'content_type_groups',
      'label' => t('Content type group'),
      'base table' => 'content_type_groups_groups',
      'entity keys' => array(
        'id' => 'type',
      ),
      'entity class' => 'ContentTypeGroup',
      'controller class' => 'ContentTypeGroupController',
      'load hook' => 'content_type_groups_group_load',
      'label callback' => 'entity_class_label',
      'uri callback' => 'entity_class_uri',
      'admin ui' => array(
        'path' => 'admin/structure/types/groups',
        'file' => CONTENT_TYPE_GROUPS_ADMIN_PATH,
        'controller class' => 'ContentTypeGroupUIController',
      ),
    ),
  );
}

/**
 * Load a single record.
 *
 * @param $id
 *    The id representing the record we want to load.
 */
function content_type_groups_group_load($id, $reset = FALSE) {
  return array_shift(content_type_groups_group_load_multiple(array(
    $id,
  ), array(), $reset));
}

/**
 * Load multiple records.
 */
function content_type_groups_group_load_multiple($ids = array(), $conditions = array(), $reset = FALSE) {
  return entity_load(CONTENT_TYPE_GROUPS_ENTITY_NAME, $ids, $conditions, $reset);
}