Index: content_access.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/content_access/content_access.module,v
retrieving revision 1.6
diff -u -r1.6 content_access.module
--- content_access.module	20 Aug 2007 09:39:08 -0000	1.6
+++ content_access.module	11 Jan 2008 00:47:08 -0000
@@ -62,41 +62,73 @@
  * Per node settings page
  */
 function content_access_page($nid) {
-  $roles = content_access_get_roles_and_author();
   $node = node_load($nid);
   drupal_set_title(check_plain($node->title));
 
+  foreach (array('view', 'update', 'delete') as $i) {
+    $defaults[$i] = content_access_per_node_setting($i, $node);
+  }
+  
+  $form = content_access_page_form($defaults);
+
+  $form['node'] = array('#type' => 'value', '#value' => $node);
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Submit'),
+    '#weight' => 10,
+  );
+  return $form;
+}
+
+/**
+ * Builds per node setting page form without require $nid
+ */
+function content_access_page_form($defaults = array()) {
+  
+  // Make sure defaults array is full
+  foreach (array('view', 'update', 'delete') as $i) {
+    if (!isset($defaults[$i])) $defaults[$i] = array();
+  }
+  
+  $roles = content_access_get_roles_and_author();
   $form['settings'] = array(
     '#type' => 'fieldset', 
     '#title' => t('Role access control settings'),
     '#collapsible' => TRUE,
   );
+  
+  if (!$node) {
+    $form['settings']['#description'] = t('Warning: No defaults are set; be sure to fill out all boxes appropriately.');
+  }
+  
   drupal_add_css(drupal_get_path('module', 'content_access') . '/content_access.css');
   $form['settings']['view'] = array('#type' => 'checkboxes',
     '#prefix' => '<div class="content_access-div">',
     '#suffix' => '</div>',
     '#options' => $roles,
     '#title' => t('View'),
-    '#default_value' => content_access_per_node_setting('view', $node),
+    '#default_value' => $defaults['view'],
   );
   $form['settings']['update'] = array('#type' => 'checkboxes',
     '#prefix' => '<div class="content_access-div">',
     '#suffix' => '</div>',
     '#options' => $roles,
     '#title' => t('Edit'),
-    '#default_value' => content_access_per_node_setting('update', $node),
+    '#default_value' => $defaults['update'],
   );
   $form['settings']['delete'] = array('#type' => 'checkboxes',
     '#prefix' => '<div class="content_access-div">',
     '#suffix' => '</div>',
     '#options' => $roles,
     '#title' => t('Delete'),
-    '#default_value' => content_access_per_node_setting('delete', $node),
+    '#default_value' => $defaults['delete'],
   );
   $form['settings']['clearer'] = array(
     '#value' => '<br clear="all" />',
   );
-  if (module_exists('acl')) {
+  if (module_exists('acl') && $node) {
+    // This is disabled when there is no node passed; we could probably
+    // make this compatible in that case too though.
     $form['acl'] = array(
       '#type' => 'fieldset', 
       '#title' => t('User access control lists'),
@@ -114,13 +146,6 @@
       $form['acl'][$op]['#collapsed'] = !isset($_POST['acl'][$op]['add_button']) && !isset($_POST['acl'][$op]['delete_button']); 
     }
   }
-
-  $form['node'] = array('#type' => 'value', '#value' => $node);
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Submit'),
-    '#weight' => 10,
-  );
   return $form;
 }
 
@@ -579,3 +604,45 @@
       break;
   }
 }
+
+/**
+ * Implementation of hook_action_info() for workflow-ng.
+ */
+function content_access_action_info() {
+  return array(
+    'content_access_action_set_node_permissions' => array(
+      '#label' => t('Set node permissions'),
+      '#arguments' => array(
+        'node' => array('#entity' => 'node', '#label' => t('Active node')),
+      ),
+      '#module' => t('Content access'),
+    ),
+  );
+}
+
+/**
+ * Workflow-ng action implementation: Sets permissions for a node type
+ */
+function content_access_action_set_node_permissions($node, $settings) {
+  content_access_save_per_node_settings($node, $settings);
+}
+
+/**
+ * Form for configuring content_access_action_set_node_permissions action.
+ */
+function content_access_action_set_node_permissions_form($settings = array(), $argument_info) {
+  return content_access_page_form($settings);
+}
+
+/**
+ * Save configuration for content_access_action_set_node_permissions action.
+ */
+function content_access_action_set_node_permissions_submit($form_id, $form_values) {
+  var_dump($form_values);
+  $settings = array();
+  foreach (array('view', 'update', 'delete') as $op) {
+    $settings[$op] = array_filter($form_values[$op]);
+  }
+  return $settings;
+}
+
