You are here

public function EntityDefaultMetadataController::entityPropertyInfo in Entity API 7

File

./entity.info.inc, line 68
Provides basic entity property info for entities provided via the CRUD API, as well as property info for all entity types defined by core. For that the respective modules/MODULE.info.inc files are included.

Class

EntityDefaultMetadataController
Default controller for generating some basic metadata for CRUD entity types.

Code

public function entityPropertyInfo() {
  $entity_label = drupal_strtolower($this->info['label']);

  // Provide defaults based on the schema.
  $info['properties'] = $this
    ->convertSchema();
  foreach ($info['properties'] as $name => &$property) {

    // Add a description.
    $property['description'] = t('@entity "@property" property.', array(
      '@entity' => drupal_ucfirst($entity_label),
      '@property' => $name,
    ));
  }

  // Set better metadata for known entity keys.
  $id_key = $this->info['entity keys']['id'];
  if (!empty($this->info['entity keys']['name']) && ($key = $this->info['entity keys']['name'])) {
    $info['properties'][$key]['type'] = 'token';
    $info['properties'][$key]['label'] = t('Machine-readable name');
    $info['properties'][$key]['description'] = t('The machine-readable name identifying this @entity.', array(
      '@entity' => $entity_label,
    ));
    $info['properties'][$id_key]['label'] = t('Internal, numeric @entity ID', array(
      '@entity' => $entity_label,
    ));
    $info['properties'][$id_key]['description'] = t('The ID used to identify this @entity internally.', array(
      '@entity' => $entity_label,
    ));
  }
  else {
    $info['properties'][$id_key]['label'] = t('@entity ID', array(
      '@entity' => drupal_ucfirst($entity_label),
    ));
    $info['properties'][$id_key]['description'] = t('The unique ID of the @entity.', array(
      '@entity' => $entity_label,
    ));
  }

  // Care for the bundle.
  if (!empty($this->info['entity keys']['bundle']) && ($key = $this->info['entity keys']['bundle'])) {
    $info['properties'][$key]['type'] = 'token';
    $info['properties'][$key]['options list'] = array(
      get_class($this),
      'bundleOptionsList',
    );
  }

  // Care for the label.
  if (!empty($this->info['entity keys']['label']) && ($key = $this->info['entity keys']['label'])) {
    $info['properties'][$key]['label'] = t('Label');
    $info['properties'][$key]['description'] = t('The human readable label.');
  }

  // Add a computed property for the entity URL and expose it to views.
  if (empty($info['properties']['url']) && !empty($this->info['uri callback'])) {
    $info['properties']['url'] = array(
      'label' => t('URL'),
      'description' => t('The URL of the entity.'),
      'getter callback' => 'entity_metadata_entity_get_properties',
      'type' => 'uri',
      'computed' => TRUE,
      'entity views field' => TRUE,
    );
  }
  return array(
    $this->type => $info,
  );
}