summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoachim Noreiko2013-04-21 08:49:35 (GMT)
committer Joachim Noreiko2013-04-21 08:49:35 (GMT)
commit95ad4a458cbc3265cc3ca018f93df38370c07256 (patch)
treedeeeb60e689939dfbf0075e6a5b94321fd4a0c68
parent7f60269be13eaef3dcd62d1eb79dc42a5deee5d5 (diff)
by joachim: Added example module.7.x-1.0-beta2
-rw-r--r--example_entity/example_entity.info5
-rw-r--r--example_entity/example_entity.install51
-rw-r--r--example_entity/example_entity.module149
3 files changed, 205 insertions, 0 deletions
diff --git a/example_entity/example_entity.info b/example_entity/example_entity.info
new file mode 100644
index 0000000..01fd8dd
--- /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 0000000..f1b8be5
--- /dev/null
+++ b/example_entity/example_entity.install
@@ -0,0 +1,51 @@
+<?php
+/**
+ * @file example_entity.install
+ * Contains install hooks.
+ */
+
+/**
+ * Implements hook_schema().
+ */
+function example_entity_schema() {
+ $schema['example_entity'] = array(
+ 'description' => '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 0000000..f72eb0f
--- /dev/null
+++ b/example_entity/example_entity.module
@@ -0,0 +1,149 @@
+<?php
+/**
+ * @file example_entity.module
+ * Contains core hooks.
+ */
+
+/**
+ * Implements hook_entity_info().
+ */
+function example_entity_entity_info() {
+ $return = array(
+ 'example_entity' => 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;
+}