diff --git a/example_entity/example_entity.info b/example_entity/example_entity.info new file mode 100644 index 0000000000000000000000000000000000000000..01fd8ddd4c01bdf531c2d27dcf71f1dc40ddff76 --- /dev/null +++ b/example_entity/example_entity.info @@ -0,0 +1,5 @@ +name = Entity Operations Example +description = Provides an example entity type using Entity Operations. +package = Example modules +dependencies[] = entity_operations +core = 7.x diff --git a/example_entity/example_entity.install b/example_entity/example_entity.install new file mode 100644 index 0000000000000000000000000000000000000000..f1b8be501f82296a02a3190365c75a10d208357e --- /dev/null +++ b/example_entity/example_entity.install @@ -0,0 +1,51 @@ + 'The base table for example_entity entity.', + 'fields' => array( + 'eid' => array( + 'description' => 'The primary identifier for a example_entity.', + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'title' => array( + 'description' => 'The title of this entity, always treated as non-markup plain text.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'status' => array( + 'description' => 'Boolean indicating whether the entity is published (visible to non-administrators).', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 1, + ), + 'uid' => array( + // Note this won't get set by the generic form handlers; but we have + // this anyway to demonstrate the 'set owner' operation. + 'description' => 'The {users}.uid who owns this entity.', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'indexes' => array( + ), + 'unique keys' => array( + ), + 'foreign keys' => array( + ), + 'primary key' => array('eid'), + ); + return $schema; +} diff --git a/example_entity/example_entity.module b/example_entity/example_entity.module new file mode 100644 index 0000000000000000000000000000000000000000..f72eb0f16033b87546a3a8b6d9e1c96a3fb5a588 --- /dev/null +++ b/example_entity/example_entity.module @@ -0,0 +1,149 @@ + array( + 'label' => t('Example Entity'), + 'plural label' => t('Example Entities'), + // Use the Entity API controller. + 'controller class' => 'EntityAPIController', + 'base table' => 'example_entity', + // Generic callback: one less callback to define. + 'uri callback' => 'entity_operations_entity_uri', + 'fieldable' => TRUE, + 'entity keys' => array( + 'id' => 'eid', + 'label' => 'title', + ), + 'bundle keys' => array( + ), + 'bundles' => array( + 'example_entity' => array( + 'label' => t('Example Entity'), + 'admin' => array( + 'path' => 'admin/structure/example_entity/', + // TODO: access callback! + ), + ), + ), + 'view modes' => array( + 'full' => array( + 'label' => t('Full content'), + 'custom settings' => FALSE, + ), + ), + // Entity API properties. + 'module' => 'example_entity', + 'entity class' => 'Entity', + 'access callback' => 'example_entity_access', + 'admin ui' => array( + 'path' => 'admin/structure/example_entity', + // We need our own controller for this, because we're using generic + // entity form operations. + 'controller class' => 'EntityOperationsDefaultAdminUIController', + ), + // Entity Operations API + 'operations ui' => array( + // The base path for your entities. This is the same as your entity's URI + // but without the ID suffix. (In fact, you can set + // entity_operations_entity_uri() as your URI callback, which will use the + // value here). + 'path' => 'example_entity', + ), + ), + ); + + return $return; +} + +/** + * Implements hook_entity_operation_info(). + */ +function example_entity_entity_operation_info() { + $info = array( + 'example_entity' => array( + 'add' => array( + 'handler' => 'EntityOperationsOperationAddGeneric', + 'provision' => array( + 'menu' => TRUE, + ), + ), + 'view' => array( + // Or try EntityOperationsOperationEntityViewOperations! + 'handler' => 'EntityOperationsOperationEntityView', + 'provision' => array( + 'menu' => array( + 'default' => TRUE, + ), + 'views field' => TRUE, + ), + ), + 'edit' => array( + 'handler' => 'EntityOperationsOperationEditGeneric', + 'provision' => array( + 'menu' => TRUE, + 'views field' => TRUE, + ), + ), + 'devel/devel' => array( + 'handler' => 'EntityOperationsOperationDevel', + 'provision' => array( + 'menu' => array( + 'default secondary' => TRUE, + ), + ), + ), + 'devel/token' => array( + // Note this only shows if you have Entity Token module enabled. + 'handler' => 'EntityOperationsOperationToken', + 'provision' => array( + 'menu' => TRUE, + ), + ), + 'devel/metadata' => array( + 'handler' => 'EntityOperationsOperationMetadata', + 'provision' => array( + 'menu' => TRUE, + ), + ), + 'publish' => array( + 'handler' => 'EntityOperationsOperationPublish', + 'provision' => array( + 'menu' => array( + ), + 'entity view' => TRUE, + ), + ), + 'unpublish' => array( + 'handler' => 'EntityOperationsOperationUnPublish', + 'provision' => array( + 'menu' => TRUE, + 'entity view' => TRUE, + ), + ), + 'author' => array( + 'handler' => 'EntityOperationsOperationSetOwner', + 'provision' => array( + 'menu' => TRUE, + //'entity view' => TRUE, + ), + ), + ), + ); + return $info; +} + +/** + * Implements callback_entity_access(). + */ +function example_entity_access($op, $entity, $account, $entity_type) { + // TODO: add access control here. + return TRUE; +}