diff -urp old/workflow_ng/workflow_ng/modules/workflow_ng_content.inc new/workflow_ng/workflow_ng/modules/workflow_ng_content.inc --- old/workflow_ng/workflow_ng/modules/workflow_ng_content.inc 2008-03-02 17:52:22.000000000 +0200 +++ new/workflow_ng/workflow_ng/modules/workflow_ng_content.inc 2008-07-09 11:25:45.031250000 +0300 @@ -12,7 +12,7 @@ function content_module_info() { 'cck_workflow_ng_forms' => array( 'file' => 'workflow_ng_content_forms.inc', 'file path' => drupal_get_path('module', 'workflow_ng'). '/modules/', - ), + ), ); } @@ -44,6 +44,14 @@ function content_action_info() { ), '#module' => 'CCK', ); + $info['workflow_ng_action_populate_field'] = array( + '#label' => t('Populate a field'), + '#arguments' => array( + 'node' => array('#entity' => 'node', '#label' => t('Content')), + ), + '#description' => 'Populate a CCK field with a PHP-returned value. You should make sure that the used field exists in the given content type.', + '#module' => 'CCK', + ); } return $info; } @@ -60,3 +68,21 @@ function workflow_ng_action_load_referen return array('#new arguments' => array('referenced_node' => node_load(array('nid' => $nid)))); } } + +/** + * Action: populate a field. + */ +function workflow_ng_action_populate_field($node, $settings) { + //Get information about the field. + $field = content_fields($settings['field_name'], $node->type); + + // Taken from function content_default_value(). + ob_start(); + $result = eval($settings['default_value_php']); + ob_end_clean(); + + if (!empty($field) && is_array($result)) { + $node->$settings['field_name'] = $result; + return array('node' => $node); + } +} diff -urp old/workflow_ng/workflow_ng/modules/workflow_ng_content_forms.inc new/workflow_ng/workflow_ng/modules/workflow_ng_content_forms.inc --- old/workflow_ng/workflow_ng/modules/workflow_ng_content_forms.inc 2008-01-05 01:20:12.000000000 +0200 +++ new/workflow_ng/workflow_ng/modules/workflow_ng_content_forms.inc 2008-07-09 11:25:45.000000000 +0300 @@ -49,3 +49,55 @@ function workflow_ng_action_load_referen //returns the needed settings return array('field' => $form_values['field']); } + +/** + * Action "populate a field" configuration form. + */ +function workflow_ng_action_populate_field_form($settings = array(), $argument_info) { + $options = content_fields(); + $fields = array_keys($options); + $fields = array_combine($fields, $fields); + $form = array(); + $form['field_name'] = array( + '#type' => 'select', + '#title' => t('Field'), + '#options' => $fields, + '#default_value' => $settings['field_name'], + '#description' => t('Select the machine-name of the field.'), + '#required' => TRUE, + ); + $sample = 'array( + 0 => array(\'value\' => value for value), + // You\'ll usually want to stop here. Provide more values + // if you want your \'default value\' to be multi-valued : + 1 => array(\'value\' => value for value), + 2 => ... +); + +Example: +return array(0 => array(\'value\' => 10));'; + + $form['default_value_php'] = array( + '#type' => 'textarea', + '#title' => t('Value'), + '#default_value' => $settings['default_value_php'], + '#rows' => 6, + '#tree' => TRUE, + '#description' => t('PHP code that returns a default value. Should not include <?php ?> delimiters. Expected format :
!sample
Using !link_devel\'s \'devel load\' tab on a %type content page might help you figure out the expected format.', array('!sample' => $sample, '!link_devel' => l('devel.module', 'http://www.drupal.org/project/devel'), '%type' => $type_name)), + '#required' => TRUE, + ); + + return $form; +} + +function workflow_ng_action_populate_field_validate($form_id, $form_values, $form) { + // Add values required by _content_admin_field_validate validation. + $field = content_fields($form_values['field_name']); + $form_values['type_name'] = $field['type_name']; + // Validate PHP format. + _content_admin_field_validate($form_id, $form_values, $form); +} + +function workflow_ng_action_populate_field_submit($form_id, $form_values) { + return array('field_name' => $form_values['field_name'], 'default_value_php' => $form_values['default_value_php']); +} Only in new/workflow_ng/workflow_ng/modules: workflow_ng_taxonomy.inc Only in new/workflow_ng/workflow_ng/modules: workflow_ng_taxonomy_forms.inc diff -urp old/workflow_ng/workflow_ng/workflow_ng.module new/workflow_ng/workflow_ng/workflow_ng.module --- old/workflow_ng/workflow_ng/workflow_ng.module 2008-03-02 14:32:56.000000000 +0200 +++ new/workflow_ng/workflow_ng/workflow_ng.module 2008-07-09 11:33:28.359375000 +0300 @@ -913,7 +913,20 @@ if (!function_exists('array_intersect_ke } return $result; } -} +} + +/** + * Own version of array_combine for php < 5. + */ +if (!function_exists('array_combine')) { + function array_combine($arr1,$arr2) { + $out = array(); + foreach($arr1 as $key1 => $value1) { + $out[$value1] = $arr2[$key1]; + } + return $out; + } +} /** * Implementation of hook_form_alter()