Browse Source

Drop use of EntityAPI Admin UI: it does not match the D8 API.

Frederic G. MARAND 11 years ago
parent
commit
bcfdb89b06
9 changed files with 307 additions and 77 deletions
  1. 39 0
      WingBase.inc
  2. 6 1
      WingState.inc
  3. 17 2
      WingWorkflow.inc
  4. 17 0
      WingWorkflowUIController.inc
  5. 83 0
      views/wing-workflow_overview.view.inc
  6. 21 0
      views/wing.views.inc
  7. 41 1
      wing.admin.inc
  8. 2 0
      wing.info
  9. 81 73
      wing.module

+ 39 - 0
WingBase.inc

@@ -0,0 +1,39 @@
+<?php
+
+abstract class WingBase extends Entity {
+
+  public $changed = REQUEST_TIME;
+  public $created = REQUEST_TIME;
+  public $machine_name;
+  public $module = 'wing';
+  public $status = 0;
+  public $title = '';
+
+  public $entityType;
+  public $entityInfo;
+
+  public function __construct(array $values = array(), $entityType = NULL) {
+    parent::__construct($values, $entityType);
+  }
+
+  public function editForm() {
+    $form = array();
+    dsm($this);
+    $form['title'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Title'),
+      '#default_value' => $this->title,
+    );
+
+    $form['machine_name'] = array(
+      '#type' => 'machine_name',
+      '#machine_name' => array(
+        'exists' => "{$this->entityType}_exists",
+        'source' => array('title'),
+      ),
+      '#default_value' => $this->machine_name,
+    );
+
+    return $form;
+  }
+}

+ 6 - 1
WingState.inc

@@ -1,8 +1,13 @@
 <?php
 
-class WingState extends Entity {
+class WingState extends WingBase {
+
+  public $sid;
 
   public function __construct(array $values, $entityType = NULL) {
+    if (!isset($entityType)) {
+      $entityType = 'wing_state';
+    }
     parent::__construct($values, $entityType = NULL);
   }
 }

+ 17 - 2
WingWorkflow.inc

@@ -1,9 +1,24 @@
 <?php
 
-class WingWorkflow extends Entity {
+class WingWorkflow extends WingBase {
+
+  public $wid;
 
   public function __construct(array $values, $entityType = NULL) {
-    parent::__construct($values, $entityType = NULL);
+    if (!isset($entityType)) {
+      $entityType = 'wing_workflow';
+    }
+    dsm($values, __METHOD__);
+    parent::__construct($values, $entityType);
+  }
+
+  public function __toString() {
+    $ret = $this->label();
+    if (empty($ret)) {
+      $ret = "<empty>";
+    }
+    dsm($ret, __METHOD__);
+    return $ret;
   }
 
   public function defaultUri() {

+ 17 - 0
WingWorkflowUIController.inc

@@ -3,6 +3,23 @@
 class WingWorkflowUIController extends EntityDefaultUIController {
 
   public function __construct($entity_type, $entity_info) {
+    dsm(__METHOD__);
     parent::__construct($entity_type, $entity_info);
   }
+
+//   public function __call($method, $args) {
+//     dsm(func_get_args(), __METHOD__);
+//   }
+
+  public function hook_forms() {
+    $ret = parent::hook_forms();
+    dsm(get_defined_vars(), __METHOD__);
+    return $ret;
+  }
+
+  public function hook_menu() {
+    $ret = parent::hook_menu();
+    dsm(get_defined_vars(), __METHOD__);
+    return $ret;
+  }
 }

+ 83 - 0
views/wing-workflow_overview.view.inc

@@ -0,0 +1,83 @@
+<?php
+
+$view = new view();
+$view->name = 'wing_workflows';
+$view->description = 'Workflow overview page';
+$view->tag = 'Wing';
+$view->base_table = 'wing_workflow';
+$view->human_name = 'Wing: Workflows';
+$view->core = 7;
+$view->api_version = '3.0';
+$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+
+/* Display: Master */
+$handler = $view->new_display('default', 'Master', 'default');
+$handler->display->display_options['title'] = 'Wing: Workflows';
+$handler->display->display_options['use_more_always'] = FALSE;
+$handler->display->display_options['access']['type'] = 'perm';
+$handler->display->display_options['access']['perm'] = 'administer wing';
+$handler->display->display_options['cache']['type'] = 'none';
+$handler->display->display_options['query']['type'] = 'views_query';
+$handler->display->display_options['exposed_form']['type'] = 'basic';
+$handler->display->display_options['pager']['type'] = 'full';
+$handler->display->display_options['pager']['options']['items_per_page'] = '10';
+$handler->display->display_options['style_plugin'] = 'table';
+$handler->display->display_options['style_options']['columns'] = array(
+  'machine_name' => 'machine_name',
+  'wid' => 'wid',
+  'title' => 'title',
+);
+$handler->display->display_options['style_options']['default'] = 'title';
+$handler->display->display_options['style_options']['info'] = array(
+  'machine_name' => array(
+    'sortable' => 1,
+    'default_sort_order' => 'asc',
+    'align' => '',
+    'separator' => '',
+    'empty_column' => 0,
+  ),
+  'wid' => array(
+    'sortable' => 1,
+    'default_sort_order' => 'asc',
+    'align' => '',
+    'separator' => '',
+    'empty_column' => 0,
+  ),
+  'title' => array(
+    'sortable' => 1,
+    'default_sort_order' => 'asc',
+    'align' => '',
+    'separator' => '',
+    'empty_column' => 0,
+  ),
+);
+/* Field: Wing: Workflow: Machine-readable name */
+$handler->display->display_options['fields']['machine_name']['id'] = 'machine_name';
+$handler->display->display_options['fields']['machine_name']['table'] = 'wing_workflow';
+$handler->display->display_options['fields']['machine_name']['field'] = 'machine_name';
+$handler->display->display_options['fields']['machine_name']['alter']['make_link'] = TRUE;
+$handler->display->display_options['fields']['machine_name']['alter']['path'] = 'admin/content/wing/workflow/[machine_name]';
+/* Field: Wing: Workflow: Internal, numeric wing: workflow ID */
+$handler->display->display_options['fields']['wid']['id'] = 'wid';
+$handler->display->display_options['fields']['wid']['table'] = 'wing_workflow';
+$handler->display->display_options['fields']['wid']['field'] = 'wid';
+$handler->display->display_options['fields']['wid']['label'] = 'Workflow ID';
+$handler->display->display_options['fields']['wid']['alter']['make_link'] = TRUE;
+$handler->display->display_options['fields']['wid']['alter']['path'] = 'admin/content/wing/workflow/[machine_name]';
+/* Field: Wing: Workflow: Label */
+$handler->display->display_options['fields']['title']['id'] = 'title';
+$handler->display->display_options['fields']['title']['table'] = 'wing_workflow';
+$handler->display->display_options['fields']['title']['field'] = 'title';
+$handler->display->display_options['fields']['title']['alter']['make_link'] = TRUE;
+$handler->display->display_options['fields']['title']['alter']['path'] = 'admin/content/wing/workflow/[machine_name]';
+
+/* Display: Page */
+$handler = $view->new_display('page', 'Page', 'page');
+$handler->display->display_options['display_comment'] = 'Workflow overview page.';
+$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
+$handler->display->display_options['path'] = 'admin/content/wing/workflow';
+$handler->display->display_options['menu']['type'] = 'tab';
+$handler->display->display_options['menu']['title'] = 'Workflows';
+$handler->display->display_options['menu']['weight'] = '0';
+$handler->display->display_options['menu']['name'] = 'management';
+$handler->display->display_options['menu']['context'] = 0;

+ 21 - 0
views/wing.views.inc

@@ -0,0 +1,21 @@
+<?php
+/**
+ * @file
+ * Views hooks for Wing.
+ */
+
+/**
+ * Implements hook_views_default_views().
+ */
+function wing_views_default_views() {
+  $path = drupal_get_path('module', 'wing') . '/views';
+  $di = new DirectoryIterator($path);
+  $views = array();
+  foreach ($di as $file) {
+    if ($file->isFile() && preg_match('/^wing-.*\.view\.inc$/', $file->getFilename())) {
+      require $file->getPathname();
+      $views[$view->name] = $view;
+    }
+  }
+  return $views;
+}

+ 41 - 1
wing.admin.inc

@@ -1,5 +1,45 @@
 <?php
+/**
+ * @file
+ * Administrative functions for Wing.
+ */
+
+/**
+ * Form builder for Workflow add/edit.
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param WingWorkflow $entity
+ * @param string $op
+ * @param string $entity_type
+ *   Should be 'wing_workflow'
+ */
+function wing_workflow_form($form, &$form_state, $entity, $op, $entity_type) {
+  dsm(func_get_args(), __FUNCTION__);
+  field_attach_form($entity_type, $entity, $form, $form_state);
+
+  $form = array_merge($form, $entity->editForm());
+
+  $form['actions'] = array('#type' => 'actions');
+
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit'),
+  );
+
+  return $form;
+}
+
+function wing_workflow_form_submit($form, &$form_state) {
+  $workflow = entity_ui_form_submit_build_entity($form, $form_state);
+  $workflow->status |= ENTITY_CUSTOM;
+  $workflow->save();
+  dsm($workflow, 'Post save');
+  $path = $workflow->entityInfo['admin ui']['path'];
+  $form_state['redirect'] = $path;
+}
+
 function wing_settings_form($form, &$form_state) {
   dsm(get_defined_vars(), __FUNCTION__);
   return array();
-}
+}

+ 2 - 0
wing.info

@@ -3,6 +3,8 @@ description = Workflow Improved Next Generation
 php = 5.3
 core = 7.x
 
+files[] = WingBase.inc
+
 files[] = WingState.inc
 files[] = WingStateController.inc
 files[] = WingStateFeaturesController.inc

+ 81 - 73
wing.module

@@ -32,38 +32,21 @@
 
 /**
  * Implements hook_entity_info().
+ *
+ * Workflow is the bundle entity for state, but this concept is obsolete in D8,
+ * so we ignore it.
  */
 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',
+  $defaults = array(
     'entity keys' => array(
-      'id' => 'wid',
       'label' => 'title',
       'module' => 'module',
-      'name' => 'name',
+      'name' => 'machine_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(
@@ -80,80 +63,82 @@ function wing_entity_info() {
         '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'
+  $ret = array();
+
+  $type = 'wing_workflow';
+  $class = 'WingWorkflow';
+  $ret[$type] = array_merge_recursive(array(
+    'access callback' => "{$type}_access",
+    'base table' => $type,
+    'controller class' => "{$class}Controller",
+    'entity class' => $class,
+    'entity keys' => array(
+      'id' => 'wid',
     ),
-    'base table' => 'wing_state',
+    'export' => array(
+      'default hook' => "default_{$type}s",
+    ),
+    'features controller class' => "{$class}FeaturesController",
+    'label' => t('Wing: Workflow'),
+    'load hook' => "{$type}_load", // Enable hook_wing_workflow_load().
+    'views controller class' => "{$class}ViewsController",
+  ), $defaults);
+
+  $type = 'wing_state';
+  $class = 'WingState';
+  $ret[$type] = array_merge_recursive(array(
+    'access callback' => '{$type}_access',
+    'base table' => $type,
     'bundle keys' => array('bundle' => 'workflow'),
     'bundles' => array(),
-    'controller class' => 'WingStateController',
-    'entity class' => 'WingState',
+    'controller class' => "{$class}Controller",
+    'entity class' => $class,
     'entity keys' => array(
       'id' => 'sid',
       'bundle' => 'workflow',
-      'label' => 'title',
-      'module' => 'module',
-      'name' => 'name',
-      'status' => 'status',
     ),
     'export' => array(
-      'default_hook' => 'default_wing_states',
+      'default_hook' => "default_{$type}s",
     ),
-    'exportable' => TRUE,
-    'features controller class' => 'WingStateFeaturesController',
-    'fieldable' => TRUE,
+    'features controller class' => "{$class}FeaturesController",
     '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',
-  );
+    'load hook' => "{$type}_load", // Enable hook_wing_state_load().
+    'views controller class' => "{$class}ViewsController",
+  ), $defaults);
 
   // Add bundle info but bypass entity_load() as we cannot use it here.
   $workflows = db_select('wing_workflow', 'ww')
     ->fields('ww')
     ->execute()
-    ->fetchAllAssoc('name');
+    ->fetchAllAssoc('machine_name');
 
   foreach ($workflows as $workflow_name => $workflow) {
-    $ret['wing_state']['bundles'][$workflow_name] = array(
+    $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'),
-      ),
+//       '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_entity_info_alter().
+ *
+ * Sort initial Wing entity info keys for easier debugging.
+ */
+function wing_entity_info_alter(&$info) {
+  ksort($info['wing_state']);
+  ksort($info['wing_workflow']);
+}
+
 /**
  * Implements hook_field_info().
  *
@@ -173,7 +158,7 @@ function wing_field_info() {
 //      'no_ui' => FALSE,
     ),
   );
-dsm($ret);
+dsm($ret, __FUNCTION__);
   return $ret;
 }
 
@@ -227,6 +212,7 @@ function wing_menu() {
     'page arguments' => array('wing_settings_form'),
     'file' => 'wing.admin.inc',
     'access arguments' => array('administer wing'),
+    'weight' => 9,
   );
   return $items;
 }
@@ -257,10 +243,23 @@ function wing_permission() {
  * @return boolean
  */
 function wing_state_access($op, $entity, $account, $entity_type) {
-  dsm(get_defined_vars(), __FUNCTION__);
+  // dsm(get_defined_vars(), __FUNCTION__);
   return TRUE;
 }
 
+/**
+ * Implements hook_view_api().
+ */
+function wing_views_api() {
+  $path = drupal_get_path('module', 'wing');
+  $ret = array(
+    'api' => 3,
+    'path' =>  "$path/views",
+    'template path' => "$path/themes",
+  );
+  return $ret;
+}
+
 /**
  * Entity access callback for wing_workflow.
  *
@@ -273,6 +272,15 @@ function wing_state_access($op, $entity, $account, $entity_type) {
  * @return boolean
  */
 function wing_workflow_access($op, $entity, $account, $entity_type) {
-  dsm(get_defined_vars(), __FUNCTION__);
+  $s_entity = isset($entity) ? "$entity" : 'NULL';
+  $s_account = isset($account) ? $account->uid : "'<anonymous>'";
+
+  // dsm(__FUNCTION__ . "('$op', $s_entity, $s_account, '$entity_type')");
   return TRUE;
 }
+
+function wing_workflow_exists($machine_name) {
+  $ret = entity_load_multiple_by_name('wing_workflow', array($machine_name));
+  dsm($ret, __FUNCTION__);
+  return $ret;
+}