You are here

function message_entity_info in Message 7

Implements hook_entity_info().

File

./message.module, line 154
API functions to manipulate messages.

Code

function message_entity_info() {
  $items['message_type_category'] = array(
    'label' => t('Message type category'),
    'controller class' => 'EntityAPIControllerExportable',
    'entity class' => 'MessageTypeCategory',
    'base table' => 'message_type_category',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'id',
      'label' => 'description',
      'name' => 'category',
      'language' => 'language',
    ),
    'exportable' => TRUE,
    'export' => array(
      'default hook' => 'default_message_type_category',
    ),
    'bundle of' => 'message_type',
    'module' => 'message',
    'access callback' => 'message_type_category_access',
  );
  $items['message_type'] = array(
    'label' => t('Message type'),
    'controller class' => 'EntityAPIControllerExportable',
    'entity class' => 'MessageType',
    'base table' => 'message_type',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'id',
      'label' => 'description',
      'name' => 'name',
      'bundle' => 'category',
      'language' => 'language',
    ),
    'bundles' => array(
      'message_type' => array(
        'label' => t('Message type'),
      ),
    ),
    'bundle keys' => array(
      'bundle' => 'category',
    ),
    'exportable' => TRUE,
    'export' => array(
      'default hook' => 'default_message_type',
    ),
    'bundle of' => 'message',
    'module' => 'message',
    'access callback' => 'message_type_access',
    'entity cache' => module_exists('entitycache'),
    // Enable the entity API's admin UI.
    'admin ui' => array(
      'path' => 'admin/structure/messages',
      'file' => 'includes/message.admin.inc',
      'controller class' => 'MessageTypeUIController',
    ),
  );
  if (module_exists('locale')) {
    $items['message_type']['translation']['locale'] = TRUE;
  }

  // Add bundle info but bypass entity_load() as we cannot use it here.
  if (db_table_exists('message_type_category')) {
    $message_categories = db_select('message_type_category', 'mtc')
      ->fields('mtc')
      ->execute()
      ->fetchAllAssoc('category');
    foreach ($message_categories as $category_name => $category) {
      $items['message_type']['bundles'][$category_name] = array(
        'label' => $category->category,
      );
    }
  }
  $items['message'] = array(
    'label' => t('Message'),
    'controller class' => 'EntityAPIController',
    'entity class' => 'Message',
    'base table' => 'message',
    'fieldable' => TRUE,
    'access callback' => 'message_access',
    'entity keys' => array(
      'id' => 'mid',
      // The message has no label.
      'label' => FALSE,
      'bundle' => 'type',
      'language' => 'language',
    ),
    'bundles' => array(),
    'bundle keys' => array(
      'bundle' => 'name',
    ),
    'view modes' => array(
      'full' => array(
        'label' => t('Full'),
        'custom settings' => FALSE,
      ),
    ),
    'module' => 'message',
    'metadata controller class' => 'MessageMetadataController',
    'views controller class' => 'MessageViewsController',
    'entity cache' => module_exists('entitycache'),
  );

  // Add bundle info but bypass entity_load() as we cannot use it here.
  if (db_table_exists('message_type')) {
    $message_types = db_select('message_type', 'mt')
      ->fields('mt')
      ->execute()
      ->fetchAllAssoc('name');
  }
  foreach ($message_types as $type_name => $type) {
    $items['message']['bundles'][$type_name] = array(
      'label' => $type->description,
      'admin' => array(
        'path' => 'admin/structure/messages/manage/%message_type',
        'real path' => 'admin/structure/messages/manage/' . $type->name,
        'bundle argument' => 4,
        'access arguments' => array(
          'administer message types',
        ),
      ),
    );
  }
  return $items;
}