You are here

function eck_schema_alter in Entity Construction Kit (ECK) 7.3

Same name and namespace in other branches
  1. 7.2 eck.module \eck_schema_alter()

Implements hook_schema_alter().

File

./eck.module, line 205

Code

function eck_schema_alter(&$schema) {
  if (db_table_exists('eck_entity_type')) {

    // When something requests an entity's info, the hook_schema is called to
    // get the information about the entity's table, so we need to provide that
    // information in the hook.
    // Get all the entity types that have been create
    // (all the rows in eck_entity_type table).
    foreach (EntityType::loadAll() as $entity_type) {

      // The function eck__entity_type__schema returns a schema for that
      // entity type given and entity_type object.
      $schema = array_merge($schema, array(
        "eck_{$entity_type->name}" => eck__entity_type__schema($entity_type),
      ));

      // Allow properties to modify the schema.
      $vars = array(
        'entity_type' => $entity_type,
        'schema' => $schema,
      );

      // The behavior hook should return its modifications in the same format
      // that they were sent to it. So we would be expecting an array with an
      // entity_type key, and a schema key.
      $vars = eck_property_behavior_invoke_plugin_alter($entity_type, 'schema', $vars);
      if (array_key_exists('schema', $vars) && isset($vars['schema'])) {
        $schema = array_merge($schema, $vars['schema']);
      }
    }
  }
}