You are here

function field_collection_entity_info in Field collection 7

Implements hook_entity_info().

File

./field_collection.module, line 67
Module implementing field collection field type.

Code

function field_collection_entity_info() {
  $return['field_collection_item'] = array(
    'label' => t('Field collection item'),
    'label callback' => 'entity_class_label',
    'uri callback' => 'entity_class_uri',
    'entity class' => 'FieldCollectionItemEntity',
    'controller class' => 'EntityAPIController',
    'base table' => 'field_collection_item',
    'revision table' => 'field_collection_item_revision',
    'fieldable' => TRUE,
    // For integration with Redirect module.
    // @see http://drupal.org/node/1263884
    'redirect' => FALSE,
    'entity keys' => array(
      'id' => 'item_id',
      'revision' => 'revision_id',
      'bundle' => 'field_name',
    ),
    'module' => 'field_collection',
    'view modes' => array(
      'full' => array(
        'label' => t('Full content'),
        'custom settings' => FALSE,
      ),
    ),
    'access callback' => 'field_collection_item_access',
    'deletion callback' => 'field_collection_item_delete',
    'metadata controller class' => 'FieldCollectionItemMetadataController',
    'translation' => array(
      'entity_translation' => array(
        'class' => 'EntityTranslationFieldCollectionItemHandler',
      ),
    ),
  );

  // Add info about the bundles. We do not use field_info_fields() but directly
  // use field_read_fields() as field_info_fields() requires built entity info
  // to work.
  foreach (field_read_fields(array(
    'type' => 'field_collection',
  )) as $field_name => $field) {
    $return['field_collection_item']['bundles'][$field_name] = array(
      'label' => t('Field collection @field', array(
        '@field' => $field_name,
      )),
      'admin' => array(
        'path' => 'admin/structure/field-collections/%field_collection_field_name',
        'real path' => 'admin/structure/field-collections/' . strtr($field_name, array(
          '_' => '-',
        )),
        'bundle argument' => 3,
        'access arguments' => array(
          'administer field collections',
        ),
      ),
    );
    $path = field_collection_field_get_path($field) . '/%field_collection_item';

    // Enable the first available path scheme as default one.
    if (!isset($return['field_collection_item']['translation']['entity_translation']['base path'])) {
      $return['field_collection_item']['translation']['entity_translation']['base path'] = $path;
      $return['field_collection_item']['translation']['entity_translation']['path wildcard'] = '%field_collection_item';
      $return['field_collection_item']['translation']['entity_translation']['default_scheme'] = $field_name;
    }
    else {
      $return['field_collection_item']['translation']['entity_translation']['path schemes'][$field_name] = array(
        'base path' => $path,
      );
    }
  }
  if (module_exists('entitycache')) {
    $return['field_collection_item']['field cache'] = FALSE;
    $return['field_collection_item']['entity cache'] = TRUE;
  }
  return $return;
}