|
@@ -1,14 +1,15 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
+use Drupal\wing\Plugin\Core\Entity\State;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @file
|
|
* @file
|
|
* Workflow - New Generation
|
|
* Workflow - New Generation
|
|
*
|
|
*
|
|
* - States are entities
|
|
* - States are entities
|
|
- * - Worfklows are the bundle entities of states
|
|
|
|
* - Transitions are fields on states, storing a (rid, sid) pair per item
|
|
* - 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
|
|
* - Any entity type can be subject to a workflow: association is represented by
|
|
- * an entityreference field whose widget uses a specific view to list the
|
|
+ * an entity_reference field whose widget uses a specific view to list the
|
|
* relevant states
|
|
* relevant states
|
|
* - Workflow access is handled by field access using the permission associated
|
|
* - Workflow access is handled by field access using the permission associated
|
|
* with a state, one "view" or "edit" permission per state entity
|
|
* with a state, one "view" or "edit" permission per state entity
|
|
@@ -30,13 +31,225 @@
|
|
* state operations form. Main point of interest is the transitions subform
|
|
* state operations form. Main point of interest is the transitions subform
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Implements hook_entity_bundle_info().
|
|
|
|
+ */
|
|
|
|
+function wing_entity_bundle_info() {
|
|
|
|
+ $bundles = array();
|
|
|
|
+ foreach (wing_get_workflows() as $workflow => $title) {
|
|
|
|
+ $bundles['wing_state'][$type] = array(
|
|
|
|
+ 'label' => $title,
|
|
|
|
+ 'admin' => array(
|
|
|
|
+ // Place the Field UI paths for comments one level below the
|
|
|
|
+ // corresponding paths for nodes, so that they appear in the same set
|
|
|
|
+ // of local tasks. Note that the paths use a different placeholder name
|
|
|
|
+ // and thus a different menu loader callback, so that Field UI page
|
|
|
|
+ // callbacks get a comment bundle name from the node type in the URL.
|
|
|
|
+ // See comment_node_type_load() and comment_menu_alter().
|
|
|
|
+ 'path' => 'admin/content/wing/manage/%wing_workflow',
|
|
|
|
+ 'bundle argument' => 4,
|
|
|
|
+ 'real path' => 'admin/content/wing/manage/' . $workflow. '/comment',
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ return $bundles;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Implements hook_entity_view_mode().
|
|
|
|
+ */
|
|
|
|
+function wing_entity_view_mode_info() {
|
|
|
|
+ $ret = array(
|
|
|
|
+ 'wing_state' => 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,
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+dsm($ret, __FUNCTION__);
|
|
|
|
+ return $ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Implements hook_field_extra_fields().
|
|
|
|
+ */
|
|
|
|
+function wing_field_extra_fields() {
|
|
|
|
+ $ret = array();
|
|
|
|
+ foreach (wing_get_workflows() as $workflow => $title) {
|
|
|
|
+ $ret['wing_state'][$workflow]['workflow'] = array(
|
|
|
|
+ 'display' => array(
|
|
|
|
+ 'label' => t('Workflow name'),
|
|
|
|
+ 'description' => t('The workflow to which the state belongs'),
|
|
|
|
+ 'weight' => -9,
|
|
|
|
+ 'visible' => FALSE,
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ dsm($ret, __FUNCTION__);
|
|
|
|
+ return $ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Helper to retrive the list or workflows or a specific workflow.
|
|
|
|
+ *
|
|
|
|
+ * @param string $workflow
|
|
|
|
+ */
|
|
|
|
+function wing_get_workflows($workflow = NULL) {
|
|
|
|
+ $workflows = config('wing')->get('workflows');
|
|
|
|
+ if (isset($workflow)) {
|
|
|
|
+ $ret = isset($workflows[$workflow]) ? $workflows[$workflow] : FALSE;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ $ret = (array) $workflows;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dsm($ret, __FUNCTION__ . "($workflow)");
|
|
|
|
+ return $ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Implements hook_help().
|
|
|
|
+ */
|
|
|
|
+function wing_help($path, $arg) {
|
|
|
|
+ switch ($path) {
|
|
|
|
+ case 'admin/help#wing':
|
|
|
|
+ $ret = '<h3>' . t('About') . '</h3>'
|
|
|
|
+ . t('Wing is a new workflow system redesigned from the ground up for Drupal 8.
|
|
|
|
+States are entities, Workflows are their bundles, and any fieldable entity type
|
|
|
|
+(not just nodes) can be subjected to a workflow by adding an entity_reference to
|
|
|
|
+a Wing state field to its field list.');
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ $ret = NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Implements hook_menu().
|
|
|
|
+ */
|
|
|
|
+function wing_menu() {
|
|
|
|
+ $items = array();
|
|
|
|
+ $items['admin/content/wing'] = array(
|
|
|
|
+ 'access arguments' => array('administer wing'),
|
|
|
|
+ 'description' => 'Report general Wing information',
|
|
|
|
+ 'file' => 'wing.admin.inc',
|
|
|
|
+ 'page callback' => 'wing_page_info',
|
|
|
|
+ 'title' => 'Wing',
|
|
|
|
+ 'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
|
|
|
|
+ 'weight' => 23, // 'W'
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ // Tabs begin here.
|
|
|
|
+ $items['admin/content/wing/info'] = array(
|
|
|
|
+ 'title' => 'Info',
|
|
|
|
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
|
|
|
|
+ );
|
|
|
|
+ $items['admin/content/wing/overview'] = array(
|
|
|
|
+ 'title' => 'States',
|
|
|
|
+ 'access arguments' => array('administer wing'),
|
|
|
|
+ 'description' => 'List and edit workflow states',
|
|
|
|
+ 'file' => 'wing.pages.inc',
|
|
|
|
+ 'page callback' => 'wing_overview',
|
|
|
|
+ 'title' => 'Wing',
|
|
|
|
+ 'type' => MENU_LOCAL_TASK,
|
|
|
|
+ );
|
|
|
|
+ $items['admin/content/wing/%wing_state'] = array(
|
|
|
|
+ 'access arguments' => array('administer wing'),
|
|
|
|
+ 'page arguments' => array(3),
|
|
|
|
+ 'page callback' => 'wing_state_page',
|
|
|
|
+ 'title' => 'State permalink',
|
|
|
|
+ );
|
|
|
|
+ $items['admin/content/wing/%wing_state/view'] = array(
|
|
|
|
+ 'title' => 'View state',
|
|
|
|
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
|
|
|
|
+ );
|
|
|
|
+ $items['admin/content/wing/%wing_state/edit'] = array(
|
|
|
|
+ 'title' => 'Edit',
|
|
|
|
+ 'page callback' => 'wing_state_edit_page',
|
|
|
|
+ 'page arguments' => array(3),
|
|
|
|
+ 'access callback' => 'wing_state_access',
|
|
|
|
+ 'access arguments' => array('edit', 3),
|
|
|
|
+ 'type' => MENU_LOCAL_TASK,
|
|
|
|
+ );
|
|
|
|
+ $items['admin/content/wing/%wing_state/delete'] = array(
|
|
|
|
+ 'title' => 'Delete',
|
|
|
|
+ 'page callback' => 'wing_state_confirm_delete_page',
|
|
|
|
+ 'page arguments' => array(3),
|
|
|
|
+ 'access arguments' => array('administer wing'),
|
|
|
|
+ 'type' => MENU_LOCAL_TASK,
|
|
|
|
+ 'file' => 'wing.admin.inc',
|
|
|
|
+ 'weight' => 20,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ $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'),
|
|
|
|
+ 'weight' => 99,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ return $items;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * TODO implement
|
|
|
|
+ *
|
|
|
|
+ * @param string $op
|
|
|
|
+ * @param Drupal\wing\Plugin\Core\Entity\State $state
|
|
|
|
+ *
|
|
|
|
+ * @return boolean
|
|
|
|
+ */
|
|
|
|
+function wing_state_access($op, State $state) {
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Entity URI callback.
|
|
|
|
+ */
|
|
|
|
+function wing_uri(State $state) {
|
|
|
|
+ return array(
|
|
|
|
+ 'path' => 'admin/content/wing/' . $state->id(),
|
|
|
|
+ );
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Menu loader for workflow.
|
|
|
|
+ *
|
|
|
|
+ * @param string $workflow
|
|
|
|
+ *
|
|
|
|
+ * @return boolean
|
|
|
|
+ */
|
|
|
|
+function wing_workflow_load($workflow) {
|
|
|
|
+ $ret = wing_get_workflows($workflow);
|
|
|
|
+ dsm($ret, __FUNCTION__);
|
|
|
|
+ return $ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function WIPWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWww() {}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Implements hook_entity_info().
|
|
* Implements hook_entity_info().
|
|
*
|
|
*
|
|
* Workflow is the bundle entity for state, but this concept is obsolete in D8,
|
|
* Workflow is the bundle entity for state, but this concept is obsolete in D8,
|
|
* so we ignore it.
|
|
* so we ignore it.
|
|
*/
|
|
*/
|
|
-function wing_entity_info() {
|
|
+function Zwing_entity_info() {
|
|
$defaults = array(
|
|
$defaults = array(
|
|
'entity keys' => array(
|
|
'entity keys' => array(
|
|
'label' => 'title',
|
|
'label' => 'title',
|
|
@@ -49,20 +262,6 @@ function wing_entity_info() {
|
|
'label callback' => 'entity_class_label',
|
|
'label callback' => 'entity_class_label',
|
|
'module' => 'wing',
|
|
'module' => 'wing',
|
|
'uri callback' => 'entity_class_uri',
|
|
'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,
|
|
|
|
- ),
|
|
|
|
- ),
|
|
|
|
);
|
|
);
|
|
|
|
|
|
$ret = array();
|
|
$ret = array();
|
|
@@ -108,24 +307,6 @@ function wing_entity_info() {
|
|
'views controller class' => "{$class}ViewsController",
|
|
'views controller class' => "{$class}ViewsController",
|
|
), $defaults);
|
|
), $defaults);
|
|
|
|
|
|
- // Add bundle info but bypass entity_load() as we cannot use it here.
|
|
|
|
- $workflows = db_select('wing_workflow', 'ww')
|
|
|
|
- ->fields('ww')
|
|
|
|
- ->execute()
|
|
|
|
- ->fetchAllAssoc('machine_name');
|
|
|
|
-
|
|
|
|
- foreach ($workflows as $workflow_name => $workflow) {
|
|
|
|
- $ret[$type]['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;
|
|
return $ret;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -134,7 +315,7 @@ function wing_entity_info() {
|
|
*
|
|
*
|
|
* Sort initial Wing entity info keys for easier debugging.
|
|
* Sort initial Wing entity info keys for easier debugging.
|
|
*/
|
|
*/
|
|
-function wing_entity_info_alter(&$info) {
|
|
+function Zwing_entity_info_alter(&$info) {
|
|
ksort($info['wing_state']);
|
|
ksort($info['wing_state']);
|
|
ksort($info['wing_workflow']);
|
|
ksort($info['wing_workflow']);
|
|
}
|
|
}
|
|
@@ -144,7 +325,7 @@ function wing_entity_info_alter(&$info) {
|
|
*
|
|
*
|
|
* Define "wing_transition" as a UI-less field.
|
|
* Define "wing_transition" as a UI-less field.
|
|
*/
|
|
*/
|
|
-function wing_field_info() {
|
|
+function Zwing_field_info() {
|
|
$ret = array(
|
|
$ret = array(
|
|
'wing_transition' => array(
|
|
'wing_transition' => array(
|
|
'label' => t('Wing: Transition'),
|
|
'label' => t('Wing: Transition'),
|
|
@@ -165,7 +346,7 @@ dsm($ret, __FUNCTION__);
|
|
/**
|
|
/**
|
|
* Implements hook_field_widget_info().
|
|
* Implements hook_field_widget_info().
|
|
*/
|
|
*/
|
|
-function wing_field_widget_info() {
|
|
+function Zwing_field_widget_info() {
|
|
$ret = array(
|
|
$ret = array(
|
|
'text_textfield' => array(
|
|
'text_textfield' => array(
|
|
'label' => t('Text field'),
|
|
'label' => t('Text field'),
|
|
@@ -184,43 +365,16 @@ function wing_field_widget_info() {
|
|
/**
|
|
/**
|
|
* Implements hook_field_widget_info_alter().
|
|
* Implements hook_field_widget_info_alter().
|
|
*/
|
|
*/
|
|
-function wing_field_widget_info_alter(&$info) {
|
|
+function Zwing_field_widget_info_alter(&$info) {
|
|
if (module_exists('text')) {
|
|
if (module_exists('text')) {
|
|
$info['text_textfield']['field types'][] = 'wing_transition';
|
|
$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'),
|
|
|
|
- 'weight' => 9,
|
|
|
|
- );
|
|
|
|
- return $items;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Implements hook_permission().
|
|
* Implements hook_permission().
|
|
*/
|
|
*/
|
|
-function wing_permission() {
|
|
+function Zwing_permission() {
|
|
$ret = array(
|
|
$ret = array(
|
|
'administer wing' => array(
|
|
'administer wing' => array(
|
|
'title' => t('Administer Wing'),
|
|
'title' => t('Administer Wing'),
|
|
@@ -242,7 +396,7 @@ function wing_permission() {
|
|
*
|
|
*
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
-function wing_state_access($op, $entity, $account, $entity_type) {
|
|
+function Zwing_state_access($op, $entity, $account, $entity_type) {
|
|
// dsm(get_defined_vars(), __FUNCTION__);
|
|
// dsm(get_defined_vars(), __FUNCTION__);
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
@@ -250,7 +404,7 @@ function wing_state_access($op, $entity, $account, $entity_type) {
|
|
/**
|
|
/**
|
|
* Implements hook_view_api().
|
|
* Implements hook_view_api().
|
|
*/
|
|
*/
|
|
-function wing_views_api() {
|
|
+function Zwing_views_api() {
|
|
$path = drupal_get_path('module', 'wing');
|
|
$path = drupal_get_path('module', 'wing');
|
|
$ret = array(
|
|
$ret = array(
|
|
'api' => 3,
|
|
'api' => 3,
|
|
@@ -271,7 +425,7 @@ function wing_views_api() {
|
|
*
|
|
*
|
|
* @return boolean
|
|
* @return boolean
|
|
*/
|
|
*/
|
|
-function wing_workflow_access($op, $entity, $account, $entity_type) {
|
|
+function Zwing_workflow_access($op, $entity, $account, $entity_type) {
|
|
$s_entity = isset($entity) ? "$entity" : 'NULL';
|
|
$s_entity = isset($entity) ? "$entity" : 'NULL';
|
|
$s_account = isset($account) ? $account->uid : "'<anonymous>'";
|
|
$s_account = isset($account) ? $account->uid : "'<anonymous>'";
|
|
|
|
|
|
@@ -279,7 +433,7 @@ function wing_workflow_access($op, $entity, $account, $entity_type) {
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
-function wing_workflow_exists($machine_name) {
|
|
+function Zwing_workflow_exists($machine_name) {
|
|
$ret = entity_load_multiple_by_name('wing_workflow', array($machine_name));
|
|
$ret = entity_load_multiple_by_name('wing_workflow', array($machine_name));
|
|
dsm($ret, __FUNCTION__);
|
|
dsm($ret, __FUNCTION__);
|
|
return $ret;
|
|
return $ret;
|