You are here

function data_entity_entity_info in Data 7

Implements hook_entity_info().

Declare every data table as an entity.

@todo Add an admin UI to request tables for this rather than do all.

File

data_entity/data_entity.module, line 50
data_entity.module TODO: Enter file description here.

Code

function data_entity_entity_info() {
  $tables = data_entity_get_entity_tables();
  $info = array();
  foreach ($tables as $table_name => $table) {
    data_entity_meta_add_defaults($table->meta);
    $meta = $table
      ->get('meta');
    if (empty($meta['is_entity_type'])) {
      continue;
    }
    $entity_type = 'data_' . $table_name;
    $info[$entity_type] = array(
      'label' => $table->title,
      'controller class' => 'DataEntityController',
      'base table' => $table_name,
      'fieldable' => TRUE,
      'entity keys' => array(
        'id' => $meta['entity_id'],
      ),
      'bundles' => array(
        $entity_type => array(
          'label' => $table->title,
          'admin' => array(
            'path' => 'admin/structure/data/edit/' . $table_name,
            'access arguments' => array(
              'administer data tables',
            ),
          ),
        ),
      ),
      'view modes' => array(),
      'uri callback' => 'data_entity_uri',
      // Entity API properties.
      'module' => 'data_entity',
      'views controller class' => FALSE,
    );

    // Use label if specified
    if (isset($table->meta['label_field'])) {
      $info[$entity_type]['entity keys']['label'] = $table->meta['label_field'];
    }
    else {
      $info[$entity_type]['label callback'] = 'data_entity_label';
    }
  }
  return $info;
}