You are here

function pollim_entity_info in Poll Improved 7

Implement hook_entity_info().

We define two entities here - the actual entity that will hold our domain specific information and an entity that holds information about the different types of entities. See here: http://drupal.org/node/977380 for a discussion on this choice.

File

./pollim.module, line 18
Module for the Pollim Entity - a starting point to create your own Entity and associated administration interface

Code

function pollim_entity_info() {
  $return['pollim'] = array(
    'label' => t('Pollim'),
    // The entity class and controller class extend the classes provided by the
    // Entity API
    'entity class' => 'Pollim',
    'controller class' => 'PollimController',
    'base table' => 'pollim',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'pollim_id',
      'bundle' => 'type',
    ),
    // Bundles are defined by the pollim types below
    'bundles' => array(),
    // Bundle keys tell the FieldAPI how to extract information from the bundle objects
    'bundle keys' => array(
      'bundle' => 'type',
    ),
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'creation callback' => 'pollim_create',
    'access callback' => 'pollim_access',
    'module' => 'pollim',
    // The information below is used by the PollimUIController (which extends the EntityDefaultUIController)
    'admin ui' => array(
      'path' => 'admin/content/pollims',
      'file' => 'pollim.admin.inc',
      'controller class' => 'PollimUIController',
      'menu wildcard' => '%pollim',
    ),
  );

  // The entity that holds information about the entity types
  $return['pollim_type'] = array(
    'label' => t('Pollim Type'),
    'entity class' => 'PollimType',
    'controller class' => 'PollimTypeController',
    'base table' => 'pollim_type',
    'fieldable' => FALSE,
    'bundle of' => 'pollim',
    'exportable' => TRUE,
    'entity keys' => array(
      'id' => 'id',
      'name' => 'type',
      'label' => 'label',
    ),
    'access callback' => 'pollim_type_access',
    'module' => 'pollim',
    // Enable the entity API's admin UI.
    'admin ui' => array(
      'path' => 'admin/structure/pollim_types',
      'file' => 'pollim_type.admin.inc',
      'controller class' => 'PollimTypeUIController',
    ),
  );
  $return['pollim_vote'] = array(
    'label' => t('Pollim Vote'),
    'entity class' => 'PollimVote',
    'controller class' => 'EntityAPIController',
    'base table' => 'pollim_vote',
    'fieldable' => FALSE,
    'entity keys' => array(
      'id' => 'vote_id',
    ),
  );
  return $return;
}