Commit 11e99a7c authored by fago's avatar fago

generate some basic entity metadata out of the schema information

parent e90eee9d
......@@ -5,5 +5,6 @@ core = 7.x
files[] = entity.controller.inc
files[] = entity.db.inc
files[] = entity.db_faces.inc
files[] = entity.info.inc
files[] = entity.rules.inc
files[] = entity.test
<?php
// $Id$
/**
* @file
* Provides Entity metadata integration for entities provided via the CRUD API.
*/
/**
* Default controller for generating Rules integration.
*/
class EntityDefaultMetadataController {
protected $type, $info;
public function __construct($type) {
$this->type = $type;
$this->info = entity_get_info($type);
}
public function entityPropertyInfo() {
$info['properties'] = entity_metadata_convert_schema($this->info['base table']);
foreach ($info['properties'] as $name => &$property) {
// Try to come up with better default labels.
$property['label'] = t('@entity @property', array('@entity' => $this->info['label'], '@property' => $name));
}
return array($this->type => $info);
}
}
/**
* Implements hook_entity_property_info().
*/
function entity_entity_property_info() {
$items = array();
foreach (entity_crud_get_info() as $type => $info) {
$info += array('metadata controller class' => 'EntityDefaultMetadataController');
$controller = new $info['metadata controller class']($type);
$items += $controller->entityPropertyInfo();
}
return $items;
}
......@@ -146,6 +146,19 @@ function entity_export($entity_type, $entity) {
}
}
/**
* Returns an array of entity info for the entity types provided via the entity CRUD API.
*/
function entity_crud_get_info() {
$types = array();
foreach (entity_get_info() as $type => $info) {
if (isset($info['controller class']) && in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
$types[$type] = $info;
}
}
return $types;
}
/**
* Export a variable. Copied from ctools.
*
......
......@@ -69,12 +69,10 @@ class EntityDefaultRulesController {
*/
function entity_rules_event_info() {
$items = array();
foreach (entity_get_info() as $type => $info) {
if (isset($info['controller class']) && in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
$info += array('rules controller class' => 'EntityDefaultRulesController');
$controller = new $info['rules controller class']($type);
$items += $controller->eventInfo();
}
foreach (entity_crud_get_info() as $type => $info) {
$info += array('rules controller class' => 'EntityDefaultRulesController');
$controller = new $info['rules controller class']($type);
$items += $controller->eventInfo();
}
return $items;
}
......
......@@ -474,8 +474,12 @@ function entity_metadata_convert_schema($table) {
$properties[$name] = array(
'type' => $type,
'label' => $name,
'setter callback' => 'entity_metadata_verbatim_set'
'setter callback' => 'entity_metadata_verbatim_set',
'query callback' => 'entity_metadata_table_query',
);
if ($type == 'serial') {
$properties[$name]['validation callback'] = 'entity_metadata_validate_integer_positive';
}
}
}
return $properties;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment