Quellcode durchsuchen

First commit: define the entity types and transition field.

Frederic G. MARAND vor 11 Jahren
Commit
b1e1c50330
3 geänderte Dateien mit 208 neuen und 0 gelöschten Zeilen
  1. 4 0
      wing.info
  2. 151 0
      wing.install
  3. 53 0
      wing.module

+ 4 - 0
wing.info

@@ -0,0 +1,4 @@
+name = Wing
+description = Workflow Improved Next Generation
+php = 5.3
+core = 7.x

+ 151 - 0
wing.install

@@ -0,0 +1,151 @@
+<?php
+/**
+ * @file
+ * Install file for W.NG
+ */
+
+/**
+ * Helper for entity exportability.
+ *
+ * May not use entity_exportable_schema_fields() directly.
+ *
+ * @see entity_exportable_schema_fields()
+ */
+function _wing_exportable_schema_fields($entity) {
+  $t = get_t();
+  $arg = array('@entity' => $entity);
+  $ret = array(
+    'machine_name' => array(
+      'description' => $t('The machine name of the @entity.', $arg),
+      'type' => 'varchar',
+      'length' => 255,
+      'not null' => TRUE,
+      'default' => '',
+    ),
+    'title' => array(
+      'description' => $t('The human name of the @entity.', $arg),
+      'type' => 'varchar',
+      'length' => 255,
+      'not null' => TRUE,
+      'default' => '',
+    ),
+    'created' => array(
+      'description' => $t('The Unix timestamp when the @entity was created.', $arg),
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0,
+    ),
+    'changed' => array(
+      'description' => t('The Unix timestamp when the @entity was most recently saved.', $arg),
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0,
+    ),
+    'status' => array(
+      'description' => $t('The exportable status of the @entity.', $arg),
+      'type' => 'int',
+      'not null' => TRUE,
+      // Set the default to ENTITY_CUSTOM without using the constant as it is
+      // not safe to use it at this point.
+      'default' => 0x01,
+      'size' => 'tiny',
+    ),
+    'module' => array(
+      'description' => $t('The name of the providing module if the @entity has been defined in code.', $arg),
+      'type' => 'varchar',
+      'length' => 255,
+      'not null' => FALSE,
+    ),
+  );
+
+  return $ret;
+}
+
+
+function wing_field_schema($field) {
+  $schema = array(
+    'columns' => array(
+      'rid' => array(
+        'description' => 'The id of the role performing the transition.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'sid' => array(
+        'description' => 'The id of the state at the end of the transition.',
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+    ),
+    'indexes' => array(
+      'target_id' => array('rid', 'sid'),
+    ),
+    'foreign keys' => array(
+      'role' => array(
+        'table' => 'role',
+        'columns' => array('rid' => 'rid'),
+      ),
+      'next_state' => array(
+        'table' => 'wing_state',
+        'columns' => array('sid' => 'sid'),
+      ),
+    ),
+  );
+
+  return $schema;
+}
+
+/**
+ * Implements hook_schema().
+ *
+ * - wing_state
+ * - wing_workflow
+ */
+function wing_schema() {
+  $schema = array(
+    'wing_state' => array(
+      'description' => 'The base table for Wing State entities',
+      'fields' => array(
+        'sid' => array(
+          'type' => 'serial',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          ),
+        'workflow' => array(
+          'description' => 'The {wing_workflow}.machine_name of this state.',
+          'type' => 'varchar',
+          'length' => 32,
+          'not null' => TRUE,
+          'default' => '',
+        ),
+      ) + _wing_exportable_schema_fields('wing_state'),
+      'primary key' => array('sid'),
+      'indexes' => array(
+        'workflow' => array('workflow'),
+      ),
+      'unique keys' => array('machine_name' => array('machine_name')),
+      'foreign keys' => array(
+        'workflow' => array(
+          'table' => 'wing_workflow',
+          'columns' => array('workflow' => 'wid'),
+        ),
+      ),
+    ),
+
+    'wing_workflow' => array(
+      'description' => 'The base table for Wing Workflow entities',
+      'fields' => array(
+        'wid' => array(
+          'type' => 'serial',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+        ),
+      ) + _wing_exportable_schema_fields('wing_workflow'),
+      'primary key' => array('wid'),
+      'unique keys' => array('machine_name' => array('machine_name')),
+    ),
+  );
+
+  return $schema;
+}

+ 53 - 0
wing.module

@@ -0,0 +1,53 @@
+<?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
+ * - Any entity type can be subject to a workflow: association is represented by
+ *   an entityreference field with specific widget/formatter.
+ */
+function wing_field_info() {
+  $ret = array(
+    'wing_transition' => array(
+      'label' => t('Wing: Transition'),
+      'description' => t('Store access from one workflow state to another.'),
+      'settings' => array(),
+      'instance_settings' => array(),
+      'default_widget' => 'text_textfield',
+      'default_formatter' => 'text_default',
+//       'default_widget' => 'wing_transition_widget',
+//       'default_formatter' => 'wing_transition_default',
+//      'no_ui' => FALSE,
+    ),
+  );
+dsm($ret);
+  return $ret;
+}
+
+function wing_field_widget_info() {
+  $ret = array(
+    'text_textfield' => array(
+      'label' => t('Text field'),
+      'field types' => array('text'),
+      'settings' => array('size' => 60),
+      'behaviors' => array(
+        'multiple values' => FIELD_BEHAVIOR_DEFAULT,
+        'default value' => FIELD_BEHAVIOR_DEFAULT,
+      ),
+    ),
+  );
+
+  return $ret;
+}
+
+/**
+ * Implements hook_field_widget_info_alter().
+ */
+function wing_field_widget_info_alter(&$info) {
+  if (module_exists('text')) {
+    $info['text_textfield']['field types'][] = 'wing_transition';
+  }
+}