diff --git a/workflow_fields.info b/workflow_fields.info
index ecc220f..ba33c1a 100644
--- a/workflow_fields.info
+++ b/workflow_fields.info
@@ -1,6 +1,6 @@
 name = Workflow Fields
 description = Adds per-field settings to each workflow state.
 package = Workflow
-dependencies[] = content 
+dependencies[] = field
 dependencies[] = workflow
-core = 6.x
+core = 7.x
diff --git a/workflow_fields.install b/workflow_fields.install
index b9ca074..a6a76d7 100644
--- a/workflow_fields.install
+++ b/workflow_fields.install
@@ -1,11 +1,5 @@
 <?php
 
-function workflow_fields_install() {
-  // Set the weight to be greater than fieldgroup's weight.
-  db_query("UPDATE {system} SET weight = 10 WHERE name = 'workflow_fields'");
-  drupal_install_schema('workflow_fields');
-}
-
 function workflow_fields_update_1() {
   $ret = array();
 
@@ -75,10 +69,6 @@ function workflow_fields_update_6004() {
   return $ret;
 }
 
-function workflow_fields_uninstall() {
-  drupal_uninstall_schema('workflow_fields');
-}
-
 function workflow_fields_schema() {
   $schema['workflow_fields'] = array(
     'fields' => array(
@@ -95,4 +85,3 @@ function workflow_fields_schema() {
   );
   return $schema;
 }
-
diff --git a/workflow_fields.js b/workflow_fields.js
index 2579c75..74ab05d 100644
--- a/workflow_fields.js
+++ b/workflow_fields.js
@@ -1,27 +1,28 @@
 
-Drupal.workflowFields = {};
-
-Drupal.workflowFields.select = function(selector, group) {
-  switch (selector) {
-  case 'all':
-    $('.workflow-fields-table input[type=checkbox][id*='+group+']').attr('checked', 'true');
-    break;
-  case 'none':
-    $('.workflow-fields-table input[type=checkbox][id*='+group+']').removeAttr('checked');
-    break;
-  case 'toggle':
-    $('.workflow-fields-table input[type=checkbox][id*='+group+']').each(function() {
-      if (this.checked) $(this).removeAttr('checked');
-      else this.checked = true;
-    });
-    break;
-  default:
-    // Match against selectors (role ids) in the form '-'+rid 
-    // but not '--'+rid to differentiate between rid=1 and rid=-1
-    $('.workflow-fields-table input[type=checkbox][id$=-'+selector+'][id*='+group+']:not([id$=--'+selector+'])').each(function() {
-      if (this.checked) $(this).removeAttr('checked');
-      else this.checked = true;
-    });
+(function($){
+  Drupal.workflowFields = {
+    select: function(selector, group) {
+      switch (selector) {
+        case 'all':
+          $('.workflow-fields-table input[type=checkbox][id*='+group+']').attr('checked', 'true');
+          break;
+        case 'none':
+          $('.workflow-fields-table input[type=checkbox][id*='+group+']').removeAttr('checked');
+          break;
+        case 'toggle':
+          $('.workflow-fields-table input[type=checkbox][id*='+group+']').each(function() {
+            if (this.checked) $(this).removeAttr('checked');
+            else this.checked = true;
+          });
+          break;
+        default:
+          // Match against selectors (role ids) in the form '-'+rid 
+          // but not '--'+rid to differentiate between rid=1 and rid=-1
+          $('.workflow-fields-table input[type=checkbox][value='+selector+'][id*='+group+']').each(function() {
+            if (this.checked) $(this).removeAttr('checked');
+            else this.checked = true;
+          });
+      }
+    }
   }
-}
-
+})(jQuery);
\ No newline at end of file
diff --git a/workflow_fields.module b/workflow_fields.module
index 9c0e9c2..bb10c92 100644
--- a/workflow_fields.module
+++ b/workflow_fields.module
@@ -2,9 +2,10 @@
 
 /**
  * @file
- * This module adds to workflow.module the ability to specify, for each state, which node fields should be visible and/or editable.
- * It is a useful feature when workflows demand that certain information be hidden or read-only to certain roles.
- *
+ * This module adds to workflow.module the ability to specify, for each state,
+ * which node fields should be visible and/or editable. It is a useful feature
+ * when workflows demand that certain information be hidden or read-only to
+ * certain roles.
  */
 
 define("FIELD_ROLE_AUTHOR", -1);
@@ -15,7 +16,7 @@ define("FIELD_ROLE_AUTHOR", -1);
 function workflow_fields_help($section) {
   switch ($section) {
     case 'admin/modules#description':
-      return t('Add per-state CCK field settings to workflows. <em>Note: Requires both workflow.module and content.module</em>.');
+      return t('Add per-state field settings to workflows.');
   }
 }
 
@@ -23,39 +24,29 @@ function workflow_fields_help($section) {
  * Implementation of hook_perm().
  */
 function workflow_fields_perm() {
-  return array('bypass field restrictions');
-}
-
-/**
- * Implementation of hook_form_alter().
- * Hook on both any CCK node form and on the workflow state form.
- *
- * @param object &$node
- * @return array
- */
-function workflow_fields_form_alter(&$form, $form_state, $form_id) {
-  if (isset($form['type']) && @$form['type']['#value'] .'_node_form' == $form_id) {
-    _workflow_fields_node_form_alter($form, $form_state, $form_id);
-  }
-  elseif ('workflow_state_add_form' == $form_id) {
-    _workflow_fields_state_form_alter($form, $form_state, $form_id);
-  }
+  return array(
+    'bypass field restrictions' => array(
+      'title' => t('Bypass Field Restrictions'),
+      'description' => t('Ignore field restrictions configured with Workflow Fields module.'),
+    ),
+  );
 }
 
 /**
  * Helper functino to alter the workflow state form.
  * Add a table listing the fields for workflow's content type.
  */
-function _workflow_fields_state_form_alter(&$form, $form_state, $form_id) {
+function workflow_fields_form_workflow_admin_ui_state_add_form_alter(&$form, $form_state, $form_id) {
   $wid = $form['wid']['#value'];
   $sid = isset($form['sid']) ? $form['sid']['#value'] : 0;
 
   // Get all types that are mapped to this workflow.
-  $types = db_query("SELECT type FROM {workflow_type_map} WHERE wid=%d", $wid);
+  $types = workflow_get_workflow_type_map_by_wid($wid);
   if (empty($types)) return;
 
   // Fix some fields if dealing with creation state.
-  if (WORKFLOW_CREATION == db_result(db_query("SELECT sysid FROM {workflow_states} WHERE sid=%d", $sid))) {
+  $state = workflow_get_workflow_states_by_sid($sid);
+  if ($state->sysid == WORKFLOW_CREATION) {
     $form['sysid'] = array('#type' => 'value', '#value' => WORKFLOW_CREATION);
     $form['weight'] = array('#type' => 'value', '#value' => WORKFLOW_CREATION_DEFAULT_WEIGHT);
     $form['state'] = array('#type' => 'value', '#value' => t('(creation)'));
@@ -70,51 +61,53 @@ function _workflow_fields_state_form_alter(&$form, $form_state, $form_id) {
   );
 
   // Gather role ids.
-  $rids = array(FIELD_ROLE_AUTHOR => t('author'));
-  $result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name");
-  while ($obj = db_fetch_object($result)) {
-    $rids[$obj->rid] = $obj->name;
-  }
+  $rids = array(FIELD_ROLE_AUTHOR => t('author')) + user_roles();
   $userrefs = array();
+  
+  $results = db_query(
+    "SELECT type, name, visible_roles, editable_roles
+    FROM {workflow_fields} WHERE sid = :sid",
+    array(':sid' => $sid)
+  );
+  $permissions = array();
+  foreach ($results as $row) {
+    $permissions[$row->type][$row->name] = array(
+      'visible_roles' => explode(',', $row->visible_roles),
+      'editable_roles' => explode(',', $row->editable_roles),
+    );
+  }
 
   // For each type, find out all the fields.
-  while ($values = db_fetch_array($types)) {
-    $type = $values['type'];
-    $content = content_types($type);
+  foreach ($types as $values) {
+    $type = $values->type;
     $form['fields']['#types']['#value'][] = $type;
 
-    // Get all user reference fields.
-    $options = $rids;
-    foreach ($content['fields'] as $userref) {
-      if ($userref['type'] == 'userreference') {
-        $options[$userref['field_name']] = $userrefs[$userref['field_name']] = $userref['widget']['label'];
-      }
-    }
-
     // For each field, add checkboxes for visible and editable for all roles.
-    $fields = _workflow_fields_get_extra_fields($type) + $content['fields'];
-    foreach ($fields as $field) {
-      $permissions = db_fetch_array(db_query("SELECT visible_roles, editable_roles FROM {workflow_fields} WHERE sid = %d AND name = '%s' AND type = '%s'", 
-        intval($sid), $field['field_name'], $type
-      ));
-      if ($permissions === FALSE) { // by default, author has full access to the fields
-        $permissions = array(
-          'visible_roles' => FIELD_ROLE_AUTHOR,
-          'editable_roles' => FIELD_ROLE_AUTHOR,
+    $fields = _workflow_fields_get_fields($type);
+    foreach ($fields as $field_name => $field) {
+      if (!isset($permissions[$type][$field_name])) {
+        $perms = array(
+          'visible_roles' => array(FIELD_ROLE_AUTHOR),
+          'editable_roles' => array(FIELD_ROLE_AUTHOR),
         );
       }
-      $visible = explode(',', $permissions['visible_roles']);
-      $editable = explode(',', $permissions['editable_roles']);
+      else {
+        $perms = $permissions[$type][$field_name];
+      }
 
-      $form['fields'][$type][$field['field_name']]['visible'] = array(
+      $form['fields'][$type][$field_name] = array(
+        '#field_label' => $field['label'],
+        '#weight' => isset($field['weight']) ? $field['weight'] : -100,
+      );
+      $form['fields'][$type][$field_name]['visible'] = array(
         '#type' => 'checkboxes',
-        '#options' => $options,
-        '#default_value' => $visible,
+        '#options' => $rids,
+        '#default_value' => $perms['visible_roles'],
       );
-      $form['fields'][$type][$field['field_name']]['editable'] = array(
+      $form['fields'][$type][$field_name]['editable'] = array(
         '#type' => 'checkboxes',
-        '#options' => $options,
-        '#default_value' => $editable,
+        '#options' => $rids,
+        '#default_value' => $perms['editable_roles'],
       );
 
       // Selection shortcuts.
@@ -198,10 +191,10 @@ function _workflow_fields_state_form_alter(&$form, $form_state, $form_id) {
 function workflow_fields_theme() {
   return array(
     'workflow_fields_state' => array(
-      'arguments' => array('form' => NULL),
+      'render element' => 'element',
     ),
     'workflow_fields_shortcuts' => array(
-      'arguments' => array('form' => NULL),
+      'render element' => 'element',
     ),
   );
 }
@@ -209,36 +202,39 @@ function workflow_fields_theme() {
 /**
  * Theme function for workflow state form.
  */
-function theme_workflow_fields_state($form) {
+function theme_workflow_fields_state($vars) {
+  $element = &$vars['element'];
   $header = array(t('Content type'), t('Field name'), t('Visible'), t('Editable'), t('Select'));
   $rows = array();
-  foreach ($form['#types']['#value'] as $type) {
-    $content = content_types($type);
-    $fields = _workflow_fields_get_extra_fields($type) + $content['fields'];
-    foreach ($fields as $field) {
+  foreach (element_children($element) as $type) {
+    $type_info = node_type_get_type($type);
+    foreach (element_children($element[$type]) as $field_name) {
+      $field_label = $element[$type][$field_name]['#field_label'];
       $rows[] = array(
-        $content['name'] .'<br/>('. $type .')',
-        $field['widget']['label'] .'<br/>('. $field['field_name'] .')',
-        drupal_render($form[$type][$field['field_name']]['visible']),
-        drupal_render($form[$type][$field['field_name']]['editable']),
-        drupal_render($form[$type][$field['field_name']]['shortcuts']),
+        $type_info->name .'<br/>('. $type .')',
+        $field_label .'<br/>('. $field_name .')',
+        drupal_render($element[$type][$field_name]['visible']),
+        drupal_render($element[$type][$field_name]['editable']),
+        drupal_render($element[$type][$field_name]['shortcuts']),
       );
     }
   }
-  $output = theme('table', $header, $rows, array('class' => 'workflow-fields-table')) .'<p />';
+  $attributes = array('class' => array('workflow-fields-table'));
+  $output = theme('table', compact('header', 'rows', 'attributes')) .'<p />';
   return $output;
 }
 
 /**
  * Theme function for field shortcuts on workflow state form.
  */
-function theme_workflow_fields_shortcuts($form) {
+function theme_workflow_fields_shortcuts($vars) {
+  $element = &$vars['element'];
   drupal_add_js(drupal_get_path('module', 'workflow_fields') .'/workflow_fields.js');
   $output = '<div class="form-item">';
-  if ($form['#render title']) {
+  if ($element['#render title']) {
     $output .= '<label>'. t('Select: ') .'</label>';
   }
-  foreach ($form['#value'] as $group) {
+  foreach ($element['#value'] as $group) {
     $links = array();
     foreach ($group as $key => $link) {
       $links[] = "<a href=\"{$link['href']}\">{$link['title']}</a>";
@@ -255,45 +251,58 @@ function theme_workflow_fields_shortcuts($form) {
 function workflow_fields_state_form_submit($form, &$form_state) {
   if (isset($form_state['values']['fields'])) {
     if (!isset($form_state['values']['sid'])) {
-      $form_state['values']['sid'] = db_result(db_query("SELECT sid FROM {workflow_states} WHERE wid = %d AND state = '%s'",
-        $form_state['values']['wid'], $form_state['values']['state']));
+      $state = workflow_get_workflow_states_by_wid_state(
+        $form_state['values']['wid'], $form_state['values']['state']);
+    }
+    else {
+      $state = workflow_get_workflow_states_by_sid($form_state['values']['sid']);
     }
-    db_query("DELETE FROM {workflow_fields} WHERE sid = %d", intval($form_state['values']['sid']));
+    db_delete('workflow_fields')->condition('sid', $state->sid)->execute();
+    $insert = db_insert('workflow_fields')
+      ->fields(array('sid', 'name', 'type', 'visible_roles', 'editable_roles'));
     foreach ($form_state['values']['fields'] as $type => $fields) {
       foreach ($fields as $name => $field) {
         $visible = array_filter($field['visible']);
         $editable = array_filter($field['editable']);
-        db_query("INSERT INTO {workflow_fields} (sid, name, type, visible_roles, editable_roles) VALUES(%d, '%s', '%s', '%s', '%s')",
-          $form_state['values']['sid'], $name, $type, implode(',', $visible), implode(',', $editable)
-        );
+        $insert->values(array(
+          'sid' => $state->sid,
+          'name' => $name,
+          'type' => $type,
+          'visible_roles' => implode(',', $visible),
+          'editable_roles' => implode(',', $editable),
+        ));
       }
     }
+    $insert->execute();
   }
 }
 
 /**
- * Helper function to alter the node form by hiding/disabling fields depending on the workflow state.
+ * Implementation of hook_form_BASE_FORM_ID_alter().
  */
-function _workflow_fields_node_form_alter(&$form, $form_state, $form_id) {
-  $node = $form['#node'];
+function workflow_fields_form_node_form_alter(&$form, $form_state, $form_id) {
+  $node =& $form['#node'];
   $sid = workflow_node_current_state($node);
   if (!is_numeric($sid)) {
-    $sid = db_result(db_query("SELECT sid FROM {workflow_states} ws 
-                               LEFT JOIN {workflow_type_map} wtm ON ws.wid = wtm.wid 
-                               WHERE wtm.type = '%s' AND ws.sysid = %d", $node->type, WORKFLOW_CREATION));
+    $type_map = workflow_get_workflow_type_map_by_type($node->type);
+    if (!$type_map) {
+      return;
+    }
+    $sid = workflow_get_creation_state_by_wid($type_map->wid);
   }
 
   // Check for visible/editable flags.
-  $content = content_types($node->type);
-  $fields = _workflow_fields_get_extra_fields($node->type) + $content['fields'];
+  $fields = _workflow_fields_get_fields($node->type);
   $form['sid'] = array('#type' => 'value', '#value' => $sid);
   list($visibles, $editables) = _workflow_fields_compute_permissions($sid, $node->type, $node, 'edit');
-  if ($visibles) foreach ($visibles as $field_name => $visible) {
-    if (!isset($fields[$field_name])) continue;
-
+  foreach ($visibles as $field_name => $visible) {
     $editable = $editables[$field_name];
-    if ($editable && $visible) continue;
-
+    
+    if (!isset($fields[$field_name])) {
+      continue;
+    }
+    else
+    
     // Find the path to the field in the form.
     $field = $fields[$field_name];
     if (!empty($field['path'])) {
@@ -303,63 +312,49 @@ function _workflow_fields_node_form_alter(&$form, $form_state, $form_id) {
       }
     }
     else {
-      $path = _workflow_fields_array_key_path($field_name, $form, array('#field_info'));
+      $path = _workflow_fields_array_key_path($field_name, $form, array('#group_children'));
     }
-    if ($path === FALSE) continue;
-   
-    // Render the form for viewing.
-    $node =& $form['#node'];
-    if (!isset($node->content)) {
-      $node = node_build_content($node, FALSE, TRUE);
+    if ($path === FALSE) {
+      continue;
+    }
+    
+    if ($editable && $visible) {
+      if (isset($field['widget']['weight'])) {
+        $element =& _workflow_fields_array_path($form, $path);
+        $element['#weight'] = $field['widget']['weight'];
+      }
+      continue;
     }
 
     // Process the field.
     if (isset($field['process'])) { // Does the field need special handling?
-      call_user_func_array($field['process'], array(&$form, $field, $path, $visible, $editable, isset($field['process arguments']) ? (array)$field['process arguments'] : array()));
+      call_user_func_array($field['process'], array(&$form, $field, $path, $node, $visible, $editable, isset($field['process arguments']) ? (array)$field['process arguments'] : array()));
     }
     else { // Standard handling
-      _workflow_fields_process_field($form, $field, $path, $visible, $editable);
-    }
-  
-    // Hide empty fieldsets.
-    if (count($path) > 1) {
-      _workflow_fields_hide_empty_fieldsets($form[$path[0]]);
+      _workflow_fields_process_field($form, $field, $path, $node, $visible, $editable);
     }
   }
 }
 
-function _workflow_fields_hide_empty_fieldsets(&$parent) {
-  foreach (element_children($parent) as $child) {
-    $element =& $parent[$child];
-    if (isset($element['#type']) && (!isset($element['#access']) || $element['#access'])) return FALSE;
-    if (!_workflow_fields_hide_empty_fieldsets($element)) return FALSE;
-  }
-  // If we reach here, then all children are empty.
-  if (isset($parent['#type']) && $parent['#type'] == 'fieldset') {
-    $parent['#access'] = FALSE;
-  }
-  return TRUE;
-}
-
-function _workflow_fields_process_field(&$form, $field, $path, $visible, $editable) {
+function _workflow_fields_process_field(&$form, $field, $path, $node, $visible, $editable) {
   $element =& _workflow_fields_array_path($form, $path);
   $parent =& _workflow_fields_array_path($form, array_slice($path, 0, -1));
 
   if ($visible) { // Show the read-only version of the field
-    if (!isset($field['extra'])) { // Is this a CCK field?
+    if (!isset($field['extra'])) { // Normal field
       $parent[$field['field_name'] .'_view'] = array(
-        '#type' => 'markup',
-        '#value' => content_view_field($field, $form['#node'], FALSE, TRUE),
-        '#weight' => isset($element['#weight']) ? $element['#weight'] : $form['#field_info'][$field['field_name']]['widget']['weight'],
+        '#type' => 'item',
+        '#title' => isset($element['#title']) ? $element['#title'] : '',
+        '#markup' => drupal_render(field_view_field('node', $node, $field['field_name'])),
+        '#weight' => isset($field['widget']['weight']) ? $field['widget']['weight'] : 0,
       );
-    }
-    else { // Non-CCK
-      $node = $form['#node'];
-      if (_workflow_fields_array_path_exists($node->content, $path)) {
-        $view = _workflow_fields_array_path($node->content, $path);
-        $parent[$field['field_name'] .'_view'] = $view;
+      if (isset($form['#group_children'][$field['field_name']])) {
+        $form['#group_children'][$field['field_name'].'_view']
+          = $form['#group_children'][$field['field_name']];
       }
     }
+    // If non field, visible but not editable... you should define process.
+    
     if (isset($parent['#type']) && $parent['#type'] == 'fieldset') {
       $parent['#access'] = TRUE; // #access of parent can be set to FALSE when all fields are disabled (by hook_field_access)
     }
@@ -369,10 +364,22 @@ function _workflow_fields_process_field(&$form, $field, $path, $visible, $editab
   $element['#access'] = FALSE;
 }
 
+function _workflow_fields_show_title(&$form, $field, $path, $node, $visible, $editable, $args) {
+  $element =& _workflow_fields_array_path($form, $path);
+  $parent =& _workflow_fields_array_path($form, array_slice($path, 0, -1));
+  $element['#access'] = FALSE;
+  $parent['title_view'] = array(
+    '#type' => 'item',
+    '#title' => isset($element['#title']) ? $element['#title'] : '',
+    '#markup' => check_plain($node->title),
+    '#weight' => isset($element['#weight']) ? $element['#weight'] : 0,
+  );
+}
+
 /**
  * Implementation of hook_workflow_fields().
  *
- * Used to describe non-CCK fields to be handled during form rendering.
+ * Used to describe non-fields to be handled during form rendering.
  *
  * @param $type
  *   Content type being handled.
@@ -383,35 +390,20 @@ function _workflow_fields_process_field(&$form, $field, $path, $visible, $editab
  *   'path' (optional): explicit field path
  *   'process' (optional): callback to handle hiding / read-only with signature process(&$form, $field, $path, $visible, $editable)
  *   'process arguments' (optional): array of extra arguments to pass to callback
- *
  */
 function workflow_fields_workflow_fields($type) {
-  $content = node_get_types('type',  $type);
+  $content = node_type_get_type($type);
   $fields = array();
   if ($content->has_title) {
     $fields['title'] = array(
       'label' => $content->title_label,
+      'process' => '_workflow_fields_show_title',
     );
   }
-  if ($content->has_body) {
-    $fields['body'] = array(
-      'label' => $content->body_label,
-      'process' => '_workflow_fields_process_body',
-    );
-  }
-  if (module_exists('taxonomy')) {
-    $vocabularies = taxonomy_get_vocabularies($type);
-    if (!empty($vocabularies)) foreach ($vocabularies as $vid => $vocabulary) {
-      $fields['vid_' . $vid] = array(
-        'label' => $vocabulary->name,
-        'path' => $vocabulary->tags ? array('taxonomy', 'tags', $vid) : array('taxonomy', $vid),
-      );
-    }
-  }
   return $fields;
 }
 
-function _workflow_fields_get_extra_fields($type, $reset = FALSE) {
+function _workflow_fields_get_fields($type, $reset = FALSE) {
   static $fields = array();
   if (!isset($fields[$type]) || $reset) {
     $fields[$type] = module_invoke_all('workflow_fields', $type);
@@ -421,35 +413,27 @@ function _workflow_fields_get_extra_fields($type, $reset = FALSE) {
       $fields[$type][$key]['extra'] = TRUE;
     }
     drupal_alter('workflow_fields', $fields, $type);
+    $fields[$type] += field_info_instances('node', $type);
   }
   return $fields[$type];
 }
 
-function _workflow_fields_process_body(&$form, $field, $path, $visible, $editable, $arguments) {
-  $form['body_field']['#access'] = FALSE;
-  if ($visible) {
-    $form['body'] = $form['#node']->content['body'];
-    $form['body']['#weight'] = $form['#content_extra_fields']['body_field']['weight'];
-  }
-}
-
 /**
  * Implementation of hook_workflow_operations().
  */
 function workflow_fields_workflow_operations($mode, $wid, $sid=0) {
   switch ($mode) {
-  case 'workflow':
-    break;
-  case 'state':
-    if (WORKFLOW_CREATION == db_result(db_query("SELECT sysid FROM {workflow_states} WHERE wid = %d AND sid = %d", $wid, $sid))) { // (creation) state
-      return array(
-        'workflow_creation_edit' => array(
-          'title' => t('Edit'),
-          'href' => "admin/build/workflow/state/$wid/$sid",
-        ),
-      );
-    }
-    break;
+    case 'state':
+      $creation_sid = workflow_get_creation_state_by_wid($wid);
+      if ($sid == $creation_sid) { // (creation) state
+        return array(
+          'workflow_creation_edit' => array(
+            'title' => t('Edit'),
+            'href' => "admin/config/workflow/workflow/state/$wid/$sid",
+          ),
+        );
+      }
+      break;
   }
 }
 
@@ -457,7 +441,7 @@ function workflow_fields_workflow_operations($mode, $wid, $sid=0) {
  * Implementation of hook_menu().
  */
 function workflow_fields_menu() {
-  $items['admin/settings/workflow_fields'] = array(
+  $items['admin/config/workflow/workflow_fields'] = array(
     'title' => 'Workflow Fields settings',
     'description' => 'Global settings for the behaviour of Workflow Fields.',
     'page callback' => 'drupal_get_form',
@@ -492,16 +476,6 @@ function _workflow_fields_compute_groups($node = NULL) {
     if ($user->uid == $node->uid) {
       $groups[] = FIELD_ROLE_AUTHOR;
     }
-    $content = content_types($node->type);
-    foreach ($content['fields'] as $name => $field) {
-      if ($field['type'] == 'userreference' && isset($node->$name)) { 
-        foreach ($node->$name as $uid) {
-          if ($uid['uid'] === $user->uid) {
-            $groups[] = $name;
-          }
-        }
-      }
-    }
   }
   return $groups;
 }
@@ -510,22 +484,26 @@ function _workflow_fields_compute_permissions($sid, $type, $node, $op) {
   $visibles = array();
   $editables = array();
   $groups = _workflow_fields_compute_groups($node);
-  $result = db_query("SELECT name, visible_roles, editable_roles FROM {workflow_fields} WHERE sid = %d AND type = '%s'", $sid, $type);
-  global $user;
-  while ($row = db_fetch_array($result)) {
-    $visible_roles = explode(',', $row['visible_roles']);
-    $editable_roles = explode(',', $row['editable_roles']);
-    $visibles[$row['name']] = user_access('bypass field restrictions') || (bool)array_intersect($groups, $visible_roles);
-    $editables[$row['name']] = user_access('bypass field restrictions') || (bool)array_intersect($groups, $editable_roles);
+  $result = db_query(
+    "SELECT name, visible_roles, editable_roles
+    FROM {workflow_fields} WHERE sid = :sid AND type = :type",
+    array(':sid' => $sid, ':type' => $type)
+  );
+  
+  foreach ($result as $row) {
+    $visible_roles = explode(',', $row->visible_roles);
+    $editable_roles = explode(',', $row->editable_roles);
+    $visibles[$row->name] = user_access('bypass field restrictions') || (bool)array_intersect($groups, $visible_roles);
+    $editables[$row->name] = user_access('bypass field restrictions') || (bool)array_intersect($groups, $editable_roles);
     if ($op == 'edit') {
-      if (variable_get('workflow_fields_hide_read_only_when_editing', FALSE) && !$editables[$row['name']]) {
-        $visibles[$row['name']] = FALSE;
+      if (variable_get('workflow_fields_hide_read_only_when_editing', FALSE) && !$editables[$row->name]) {
+        $visibles[$row->name] = FALSE;
       }
-      if (variable_get('workflow_fields_edit_invisible_when_editing', TRUE) && $editables[$row['name']]) {
-        $visibles[$row['name']] = TRUE;
+      if (variable_get('workflow_fields_edit_invisible_when_editing', TRUE) && $editables[$row->name]) {
+        $visibles[$row->name] = TRUE;
       }
-      if (!$visibles[$row['name']]) {
-        $editables[$row['name']] = FALSE;
+      if (!$visibles[$row->name]) {
+        $editables[$row->name] = FALSE;
       }
     }
   }
@@ -567,21 +545,21 @@ function _workflow_fields_array_path_exists($array, $path) {
 /**
  * Implementation of hook_field_access().
  */
-function workflow_fields_field_access($op, $field, $account = NULL, $node = NULL) {
-  if (!$node) return TRUE;
-  $node = node_load($node->nid); // The node object can be a views result object too: not good
+function workflow_fields_field_access($op, $field, $entity_type, $node, $account) {
+  if ($entity_type == 'node' || !$node) {
+    $sid = workflow_node_current_state($node);
+    if (!$sid) return TRUE;
+    if (!is_numeric($sid)) {
+      $type_map = workflow_get_workflow_type_map_by_type($node->type);
+      $sid = workflow_get_creation_state_by_wid($type_map->wid);
+    }
 
-  $sid = workflow_node_current_state($node);
-  if (!$sid) return TRUE;
-  if (!is_numeric($sid)) {
-    $sid = db_result(db_query("SELECT sid FROM {workflow_states} ws 
-                               LEFT JOIN {workflow_type_map} wtm ON ws.wid = wtm.wid 
-                               WHERE wtm.type = '%s' AND ws.sysid = %d", $node->type, WORKFLOW_CREATION));
+    // Check for visible/editable flags.
+    list($visibles, $editables) = _workflow_fields_compute_permissions($sid, $node->type, $node, $op);
+    if (!isset($visibles[$field['field_name']])) return TRUE;
+    return ($op == 'view') ? $visibles[$field['field_name']] : ($visibles[$field['field_name']] && $editables[$field['field_name']]);
+  }
+  else {
+    return TRUE;
   }
-
-  // Check for visible/editable flags.
-  list($visibles, $editables) = _workflow_fields_compute_permissions($sid, $node->type, $node, $op);
-  if (!isset($visibles[$field['field_name']])) return TRUE;
-  return ($op == 'view') ? $visibles[$field['field_name']] : ($visibles[$field['field_name']] && $editables[$field['field_name']]);
 }
-
