Browse Source

Entities declarations. Admin UI not correct yet.

Frederic G. MARAND 11 years ago
parent
commit
9a84355ca4

+ 8 - 0
WingState.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingState extends Entity {
+
+  public function __construct(array $values, $entityType = NULL) {
+    parent::__construct($values, $entityType = NULL);
+  }
+}

+ 8 - 0
WingStateController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingStateController extends EntityAPIControllerExportable {
+
+  public function __construct($entityType) {
+    parent::__construct($entityType);
+  }
+}

+ 8 - 0
WingStateFeaturesController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingStateFeaturesController extends EntityDefaultFeaturesController {
+
+  public function __construct($type) {
+    parent::__construct($type);
+  }
+}

+ 8 - 0
WingStateUIController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingStateUIController extends EntityDefaultUIController {
+
+  public function __construct($entity_type, $entity_info) {
+    parent::__construct($entity_type, $entity_info);
+  }
+}

+ 8 - 0
WingStateViewsController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingStateViewsController extends EntityDefaultViewsController {
+
+  public function __construct($type) {
+    parent::__construct($type);
+  }
+}

+ 22 - 0
WingWorkflow.inc

@@ -0,0 +1,22 @@
+<?php
+
+class WingWorkflow extends Entity {
+
+  public function __construct(array $values, $entityType = NULL) {
+    parent::__construct($values, $entityType = NULL);
+  }
+
+  public function defaultUri() {
+    $ret = array(
+      'path' => 'admin/content/wing/workflow/' . $this->identifier(),
+    );
+    dsm($ret, __METHOD__);
+    return $ret;
+  }
+
+  public function defaultLabel() {
+    $ret = parent::defaultLabel();
+    dsm($ret, __METHOD__);
+    return $ret;
+  }
+}

+ 8 - 0
WingWorkflowController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingWorkflowController extends EntityAPIControllerExportable {
+
+  public function __construct($entityType) {
+    parent::__construct($entityType);
+  }
+}

+ 8 - 0
WingWorkflowFeaturesController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingWorkflowFeaturesController extends EntityDefaultFeaturesController {
+
+  public function __construct($type) {
+    parent::__construct($type);
+  }
+}

+ 8 - 0
WingWorkflowUIController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingWorkflowUIController extends EntityDefaultUIController {
+
+  public function __construct($entity_type, $entity_info) {
+    parent::__construct($entity_type, $entity_info);
+  }
+}

+ 8 - 0
WingWorkflowViewsController.inc

@@ -0,0 +1,8 @@
+<?php
+
+class WingWorkflowViewsController extends EntityDefaultViewsController {
+
+  public function __construct($type) {
+    parent::__construct($type);
+  }
+}

+ 5 - 0
wing.admin.inc

@@ -0,0 +1,5 @@
+<?php
+function wing_settings_form($form, &$form_state) {
+  dsm(get_defined_vars(), __FUNCTION__);
+  return array();
+}

+ 13 - 0
wing.info

@@ -2,3 +2,16 @@ name = Wing
 description = Workflow Improved Next Generation
 php = 5.3
 core = 7.x
+
+files[] = WingState.inc
+files[] = WingStateController.inc
+files[] = WingStateFeaturesController.inc
+files[] = WingStateUIController.inc
+files[] = WingStateViewsController.inc
+
+files[] = WingWorkflow.inc
+files[] = WingWorkflowController.inc
+files[] = WingWorkflowFeaturesController.inc
+files[] = WingWorkflowUIController.inc
+files[] = WingWorkflowViewsController.inc
+

+ 15 - 1
wing.install

@@ -148,4 +148,18 @@ function wing_schema() {
   );
 
   return $schema;
-}
+}
+
+/**
+ * Implements hook_uninstall().
+ *
+ * @see entity_test_uninstall() {
+ */
+function wing_uninstall() {
+  // FIXME: provide correct values.
+  $wing_state_types = array();
+
+  foreach ($wing_state_types as $name => $type) {
+    field_attach_delete_bundle('entity_test', $name);
+  }
+}

+ 227 - 2
wing.module

@@ -1,13 +1,163 @@
 <?php
+
 /**
  * @file
  * Workflow - New Generation
  *
  * - States are entities
  * - Worfklows are the bundle entities of states
- * - Transitions are specific fields from state to role_id+state
+ * - Transitions are fields on states, storing a (rid, sid) pair per item
  * - Any entity type can be subject to a workflow: association is represented by
- *   an entityreference field with specific widget/formatter.
+ *   an entityreference field whose widget uses a specific view to list the
+ *   relevant states
+ * - Workflow access is handled by field access using the permission associated
+ *   with a state, one "view" or "edit" permission per state entity
+ *
+ * URL structure admin/structure/wing/...
+ * /: dashboard
+ * /settings: module settings
+ * /add: workflow creation form
+ * /workflow[/list]: list of workflows
+ * /workflow/add: state creation form
+ * /workflow/<wname>[/info]: info on workflow with list of states
+ * /workflow/<wname>/edit|clone|delete|export: workflow operations form
+ * /workflow/<wname>/fields: field UI for workflow as state bundle
+ * /workflow/<wname>/fields: view modes for workflow as state bundle
+ * /state[/list]: list of states
+ * /state/<sname>[/info]: info on state, with list of previous/next states
+ *   and list of entities in state
+ * /state/<sname>/edit|clone|delete|export
+ *   state operations form. Main point of interest is the transitions subform
+ */
+
+/**
+ * Implements hook_entity_info().
+ */
+function wing_entity_info() {
+  $ret = array();
+  $ret['wing_workflow'] = array(
+    'access callback' => 'wing_workflow_access',
+    'admin ui' => array(
+      'controller class' => 'WingWorkflowUIController',
+      // 'file' => '',
+      // 'file path' => '',
+      'menu wildcard' => '%entity_object',
+      'path' => 'admin/content/wing/workflow'
+    ),
+    'base table' => 'wing_workflow',
+    'bundle of' => 'wing_state',
+    'controller class' => 'WingWorkflowController',
+    'entity class' => 'WingWorkflow',
+    'entity keys' => array(
+      'id' => 'wid',
+      'label' => 'title',
+      'module' => 'module',
+      'name' => 'name',
+      'status' => 'status',
+    ),
+    'export' => array(
+      'default hook' => 'default_wing_workflows',
+    ),
+    'exportable' => TRUE,
+    'features controller class' => 'WingWorkflowFeaturesController',
+    'fieldable' => FALSE,
+    'label' => t('Wing: Workflow'),
+    'label callback' => 'entity_class_label',
+    'load hook' => 'wing_workflow_load', // Enable hook_workflow_load().
+    'module' => 'wing',
+    'uri callback' => 'entity_class_uri',
+    'view modes' => array(
+      'full' => array(
+        'label' => t('Full'),
+        'custom settings' => FALSE,
+      ),
+      'summary' => array(
+        'label' => t('Summary'),
+        'custom settings' => FALSE,
+      ),
+      'simple' => array(
+        'label' => t('Simple'),
+        'custom settings' => FALSE,
+      ),
+    ),
+    'views controller class' => 'WingWorkflowViewsController',
+  );
+
+  $ret['wing_state'] = array(
+    'access callback' => 'wing_state_access',
+    'admin ui' => array(
+      'controller class' => 'WingStateUIController',
+      // 'file' => '',
+      // 'file path' => '',
+      'menu wildcard' => '%entity_object',
+      'path' => 'admin/content/wing/state/%entity_object'
+    ),
+    'base table' => 'wing_state',
+    'bundle keys' => array('bundle' => 'workflow'),
+    'bundles' => array(),
+    'controller class' => 'WingStateController',
+    'entity class' => 'WingState',
+    'entity keys' => array(
+      'id' => 'sid',
+      'bundle' => 'workflow',
+      'label' => 'title',
+      'module' => 'module',
+      'name' => 'name',
+      'status' => 'status',
+    ),
+    'export' => array(
+      'default_hook' => 'default_wing_states',
+    ),
+    'exportable' => TRUE,
+    'features controller class' => 'WingStateFeaturesController',
+    'fieldable' => TRUE,
+    'label' => t('Wing: State'),
+    'label callback' => 'entity_class_label',
+    'load hook' => 'wing_state_load',
+    'module' => 'wing',
+    'uri callback' => 'entity_class_uri',
+    'view modes' => array(
+      'full' => array(
+        'label' => t('Full'),
+        'custom settings' => FALSE,
+      ),
+      'summary' => array(
+        'label' => t('Summary'),
+        'custom settings' => FALSE,
+      ),
+      'simple' => array(
+        'label' => t('Simple'),
+        'custom settings' => FALSE,
+      ),
+    ),
+    'views controller class' => 'WingStateViewsController',
+  );
+
+  // Add bundle info but bypass entity_load() as we cannot use it here.
+  $workflows = db_select('wing_workflow', 'ww')
+    ->fields('ww')
+    ->execute()
+    ->fetchAllAssoc('name');
+
+  foreach ($workflows as $workflow_name => $workflow) {
+    $ret['wing_state']['bundles'][$workflow_name] = array(
+      'label' => $workflow->title,
+      'admin' => array(
+        'path' => 'admin/content/wing/workflow/%entity_object',
+        'real path' => 'admin/content/wing/workflow/' . $workflow_name,
+        'bundle argument' => 4,
+        'access arguments' => array('administer wing'),
+      ),
+    );
+  }
+
+  return $ret;
+}
+
+/**
+ * Implements hook_field_info().
+ *
+ * Define "wing_transition" as a UI-less field.
  */
 function wing_field_info() {
   $ret = array(
@@ -27,6 +177,9 @@ dsm($ret);
   return $ret;
 }
 
+/**
+ * Implements hook_field_widget_info().
+ */
 function wing_field_widget_info() {
   $ret = array(
     'text_textfield' => array(
@@ -51,3 +204,75 @@ function wing_field_widget_info_alter(&$info) {
     $info['text_textfield']['field types'][] = 'wing_transition';
   }
 }
+
+/**
+ * Implements hook_menu().
+ */
+function wing_menu() {
+  $items = array();
+  $items['admin/content/wing'] = array(
+    'title' => 'Wing',
+    'access arguments' => array('administer wing'),
+    'page callback' => 'wing_overview',
+    'file' => 'wing.pages.inc',
+  );
+  $items['admin/content/wing/info'] = array(
+    'title' => 'Info',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+  );
+  $items['admin/content/wing/settings'] = array(
+    'title' => 'Settings',
+    'type' => MENU_LOCAL_TASK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('wing_settings_form'),
+    'file' => 'wing.admin.inc',
+    'access arguments' => array('administer wing'),
+  );
+  return $items;
+}
+
+/**
+ * Implements hook_permission().
+ */
+function wing_permission() {
+  $ret = array(
+    'administer wing' =>  array(
+      'title' => t('Administer Wing'),
+      'description' => t('Perform administration tasks for Wing.'),
+    ),
+  );
+
+  return $ret;
+}
+
+/**
+ * Entity access callback for wing_state.
+ *
+ * @param string $op
+ *   'create', 'update', 'delete' or 'view'
+ * @param WingState $entity
+ * @param stdClass $account
+ * @param string $entity_type
+ *
+ * @return boolean
+ */
+function wing_state_access($op, $entity, $account, $entity_type) {
+  dsm(get_defined_vars(), __FUNCTION__);
+  return TRUE;
+}
+
+/**
+ * Entity access callback for wing_workflow.
+ *
+ * @param string $op
+ *   'create', 'update', 'delete' or 'view'
+ * @param WingWorkflow $entity
+ * @param stdClass $account
+ * @param string $entity_type
+ *
+ * @return boolean
+ */
+function wing_workflow_access($op, $entity, $account, $entity_type) {
+  dsm(get_defined_vars(), __FUNCTION__);
+  return TRUE;
+}

+ 12 - 0
wing.pages.inc

@@ -0,0 +1,12 @@
+<?php
+function wing_overview() {
+  $ret = <<<TXT
+          <ul>
+            <li><a href="wing-workflow.html">2 Workflows</a></li>
+            <li><a href="wing-state.html">6 States</a></li>
+            <li><a href="wing-workflow.html">8 entity types under control</a></li>
+            <li><a href="wing-state.html">3152 Entities</a></li>
+            </ul>
+TXT;
+  return $ret;
+}