You are here

function newsletter_template_entity_info in Newsletter 7.2

Implements hook_entity_info().

File

modules/template/newsletter_template.module, line 60
Module for the Newsletter Template Entity

Code

function newsletter_template_entity_info() {
  $entities['newsletter_template'] = array(
    'label' => t('Newsletter template'),
    'entity class' => 'NewsletterTemplate',
    'controller class' => 'NewsletterTemplateController',
    'base table' => 'newsletter_template',
    'revision table' => 'newsletter_template_revision',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'template_id',
      'revision' => 'revision_id',
      'bundle' => 'type',
    ),
    // Bundles are defined by the subscriber types below.
    'bundles' => array(),
    'bundle keys' => array(
      'bundle' => 'type',
    ),
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'creation callback' => 'newsletter_template_create',
    'access callback' => 'newsletter_template_access',
    'module' => 'newsletter_template',
    // The information below is used by the NewsletterTemplateUIController.
    'admin ui' => array(
      'path' => 'admin/config/media/newsletter/templates',
      'file' => 'includes/newsletter_template.admin.inc',
      'controller class' => 'NewsletterTemplateUIController',
      'menu wildcard' => '%newsletter_template',
    ),
  );

  // Add bundle info but bypass entity_load() as we cannot use it here.
  $types = db_select('newsletter_template_type', 'ns')
    ->fields('ns')
    ->execute()
    ->fetchAllAssoc('type');
  foreach ($types as $type => $info) {
    $entities['newsletter_template']['bundles'][$type] = array(
      'label' => $info->name,
      'admin' => array(
        'path' => 'admin/structure/newsletter-template-types/manage/%newsletter_template_type',
        'real path' => 'admin/structure/newsletter-template-types/manage/' . $type,
        'bundle argument' => 4,
        'access arguments' => array(
          'administer newsletter template types',
        ),
      ),
    );
  }

  // The entity that holds information about the entity types.
  $entities['newsletter_template_type'] = array(
    'label' => t('Newsletter template type'),
    'entity class' => 'NewsletterTemplateType',
    'controller class' => 'NewsletterTemplateTypeController',
    'base table' => 'newsletter_template_type',
    'fieldable' => FALSE,
    'bundle of' => 'newsletter_template',
    'exportable' => TRUE,
    'entity keys' => array(
      'id' => 'id',
      'name' => 'type',
      'label' => 'name',
    ),
    'access callback' => 'newsletter_template_type_access',
    'module' => 'newsletter_template',
    // Enable the entity API's admin UI.
    'admin ui' => array(
      'path' => 'admin/structure/newsletter-template-types',
      'file' => 'includes/newsletter_template.admin.inc',
      'controller class' => 'NewsletterTemplateTypeUIController',
    ),
  );
  return $entities;
}