You are here

function _entity_info_add_metadata in Entity API 7

Adds metadata and callbacks for core entities to the entity info.

1 call to _entity_info_add_metadata()
entity_entity_info_alter in ./entity.module
Implements hook_entity_info_alter().

File

./entity.module, line 1503

Code

function _entity_info_add_metadata(&$entity_info) {

  // Set plural labels.
  $entity_info['node']['plural label'] = t('Nodes');
  $entity_info['user']['plural label'] = t('Users');
  $entity_info['file']['plural label'] = t('Files');

  // Set descriptions.
  $entity_info['node']['description'] = t('Nodes represent the main site content items.');
  $entity_info['user']['description'] = t('Users who have created accounts on your site.');
  $entity_info['file']['description'] = t('Uploaded file.');

  // Set access callbacks.
  $entity_info['node']['access callback'] = 'entity_metadata_no_hook_node_access';
  $entity_info['user']['access callback'] = 'entity_metadata_user_access';

  // File entity has it's own entity_access function.
  if (!module_exists('file_entity')) {
    $entity_info['file']['access callback'] = 'entity_metadata_file_access';
  }

  // CRUD function callbacks.
  $entity_info['node']['creation callback'] = 'entity_metadata_create_node';
  $entity_info['node']['save callback'] = 'node_save';
  $entity_info['node']['deletion callback'] = 'node_delete';
  $entity_info['node']['revision deletion callback'] = 'node_revision_delete';
  $entity_info['user']['creation callback'] = 'entity_metadata_create_object';
  $entity_info['user']['save callback'] = 'entity_metadata_user_save';
  $entity_info['user']['deletion callback'] = 'user_delete';
  $entity_info['file']['save callback'] = 'file_save';
  $entity_info['file']['deletion callback'] = 'entity_metadata_delete_file';

  // Form callbacks.
  $entity_info['node']['form callback'] = 'entity_metadata_form_node';
  $entity_info['user']['form callback'] = 'entity_metadata_form_user';

  // URI callbacks.
  if (!isset($entity_info['file']['uri callback'])) {
    $entity_info['file']['uri callback'] = 'entity_metadata_uri_file';
  }

  // View callbacks.
  $entity_info['node']['view callback'] = 'entity_metadata_view_node';
  $entity_info['user']['view callback'] = 'entity_metadata_view_single';
  if (module_exists('comment')) {
    $entity_info['comment']['plural label'] = t('Comments');
    $entity_info['comment']['description'] = t('Remark or note that refers to a node.');
    $entity_info['comment']['access callback'] = 'entity_metadata_comment_access';
    $entity_info['comment']['creation callback'] = 'entity_metadata_create_comment';
    $entity_info['comment']['save callback'] = 'comment_save';
    $entity_info['comment']['deletion callback'] = 'comment_delete';
    $entity_info['comment']['view callback'] = 'entity_metadata_view_comment';
    $entity_info['comment']['form callback'] = 'entity_metadata_form_comment';
  }
  if (module_exists('taxonomy')) {
    $entity_info['taxonomy_term']['plural label'] = t('Taxonomy terms');
    $entity_info['taxonomy_term']['description'] = t('Taxonomy terms are used for classifying content.');
    $entity_info['taxonomy_term']['access callback'] = 'entity_metadata_taxonomy_access';
    $entity_info['taxonomy_term']['creation callback'] = 'entity_metadata_create_object';
    $entity_info['taxonomy_term']['save callback'] = 'taxonomy_term_save';
    $entity_info['taxonomy_term']['deletion callback'] = 'taxonomy_term_delete';
    $entity_info['taxonomy_term']['view callback'] = 'entity_metadata_view_single';
    $entity_info['taxonomy_term']['form callback'] = 'entity_metadata_form_taxonomy_term';
    $entity_info['taxonomy_vocabulary']['plural label'] = t('Taxonomy vocabularies');
    $entity_info['taxonomy_vocabulary']['description'] = t('Vocabularies contain related taxonomy terms, which are used for classifying content.');
    $entity_info['taxonomy_vocabulary']['access callback'] = 'entity_metadata_taxonomy_access';
    $entity_info['taxonomy_vocabulary']['creation callback'] = 'entity_metadata_create_object';
    $entity_info['taxonomy_vocabulary']['save callback'] = 'taxonomy_vocabulary_save';
    $entity_info['taxonomy_vocabulary']['deletion callback'] = 'taxonomy_vocabulary_delete';
    $entity_info['taxonomy_vocabulary']['form callback'] = 'entity_metadata_form_taxonomy_vocabulary';

    // Token type mapping.
    $entity_info['taxonomy_term']['token type'] = 'term';
    $entity_info['taxonomy_vocabulary']['token type'] = 'vocabulary';
  }
}