View source
<?php
function services_entity_test_entity_info() {
$return = array(
'services_entity_test' => array(
'label' => t('Services Test Entity'),
'plural label' => t('Services Test Entities'),
'description' => t('An entity type used by the Services Entity tests.'),
'entity class' => 'ServicesEntityClass',
'controller class' => 'EntityAPIController',
'base table' => 'services_entity_test',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'eid',
'bundle' => 'type',
),
'label callback' => 'entity_class_label',
'uri callback' => 'entity_class_uri',
'access callback' => 'services_entity_test_access',
'bundles' => array(
'alpha' => array(
'label' => t('Alpha'),
),
'beta' => array(
'label' => t('Beta'),
),
),
'module' => 'services_entity_test',
),
);
return $return;
}
function services_entity_test_access($op, $entity, $account, $entity_type) {
$permission_string = "{$op} services_entity_test entities";
return user_access($permission_string, $account);
}
function services_entity_test_permission() {
return array(
'create services_entity_test entities' => array(
'title' => t('View'),
),
'view services_entity_test entities' => array(
'title' => t('View'),
),
'update services_entity_test entities' => array(
'title' => t('View'),
),
'delete services_entity_test entities' => array(
'title' => t('View'),
),
);
}
class ServicesEntityClass extends Entity {
public function __construct(array $values = array(), $entityType = NULL) {
parent::__construct($values, 'services_entity_test');
}
protected function defaultLabel() {
return $this->name;
}
protected function defaultURI() {
return array(
'path' => 'services_entity_test/' . $this
->identifier(),
);
}
}