You are here

civicrm_entity_metadata_controller.inc in CiviCRM Entity 7.2

Same filename and directory in other branches
  1. 7 civicrm_entity_metadata_controller.inc

Provides Entity metadata integration.

File

civicrm_entity_metadata_controller.inc
View source
<?php

/**
 * @file
 * Provides Entity metadata integration.
 */

/**
 * Extend the default CiviCRM membership metadata properties.
 */
class CivicrmEntityMetadataController extends EntityDefaultMetadataController {

  /**
   * Return a set of properties for an entity based on the schema definition.
   */
  protected function convertSchema() {
    if (empty($this->info['base table'])) {
      return array();
    }
    return civicrm_entity_metadata_convert_schema($this->info['base table']);
  }

}

/**
 * Converts schema info for table to property info.
 *
 * This is based on the CiviCRM get schema function and is a very
 * limited implementation.
 *
 * @param string $table
 *   The name of the table as used in hook_schema().
 *
 * @return array
 *   Property info suitable for hook_entity_property_info().
 */
function civicrm_entity_metadata_convert_schema($table) {
  $schema = civicrm_entity_get_schema($table);
  $properties = array();
  foreach ($schema['fields'] as $name => $info) {
    if ($type = _entity_metadata_convert_schema_type($info['type'])) {
      $properties[$name] = array(
        'type' => $type,
        'label' => drupal_ucfirst($name),
        'schema field' => $name,
      );
      if ($info['type'] == 'serial') {
        $properties[$name]['validation callback'] = 'entity_metadata_validate_integer_positive';
      }
    }
  }
  return $properties;
}

Functions

Namesort descending Description
civicrm_entity_metadata_convert_schema Converts schema info for table to property info.

Classes

Namesort descending Description
CivicrmEntityMetadataController Extend the default CiviCRM membership metadata properties.