View source
<?php
function efq_views_test_entity_info() {
$info = array(
'efq_views_test' => array(
'label' => t('EFQ Views test'),
'base table' => 'efq_views_test',
'entity class' => 'EFQViewsTestEntityClass',
'controller class' => 'EntityAPIController',
'uri callback' => 'entity_class_uri',
'load hook' => 'example_task_load',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'eid',
'bundle' => 'ebundle',
'label' => 'elabel',
),
'bundle keys' => array(
'bundle' => 'bundle',
),
'bundles' => array(),
),
);
$info['efq_views_test']['bundles']['bundle1']['label'] = t('Bundle 1');
$info['efq_views_test']['bundles']['bundle2']['label'] = t('Bundle 2');
return $info;
}
function efq_views_test_entity_property_info_alter(&$info) {
$properties =& $info['efq_views_test']['properties'];
$properties['language'] = array(
'type' => 'token',
'setter callback' => 'entity_property_verbatim_set',
'options list' => 'entity_metadata_language_list',
'schema field' => 'language',
) + $properties['language'];
$properties['test_boolean']['type'] = 'boolean';
$properties['test_decimal']['type'] = 'decimal';
$properties['test_decimal']['getter callback'] = 'efq_views_test_decimal';
$properties['test_duration']['type'] = 'duration';
$properties['test_date']['type'] = 'date';
}
function efq_views_test_bundles() {
return array(
'test1',
'test2',
);
}
function efq_views_test_decimal($entity, array $options, $name) {
return $entity->test_decimal / 100;
}
class EFQViewsTestEntityClass extends Entity {
public function __construct(array $values = array(), $entityType = NULL) {
parent::__construct($values, 'efq_views_test');
}
public function buildContent($view_mode = 'full', $langcode = NULL) {
$content['user'] = array(
'#markup' => "User: " . format_username(user_load($this->uid)),
);
return entity_get_controller($this->entityType)
->buildContent($this, $view_mode, $langcode, $content);
}
protected function defaultLabel() {
$type = entity_test_get_types($this->name);
return $type->label;
}
protected function defaultURI() {
return array(
'path' => 'custom/' . $this
->identifier(),
);
}
}
function efq_views_test_query_test_query_tag_alter($query) {
global $efq_test_query;
$efq_test_query = $query;
}