'. t('Allows users to generate each of the nodes specified by a repeating rule.') .'

'; break; } return $output; } // function repeat_nodegen_help function repeat_nodegen_form_alter(&$form, $form_state, $form_id) { if ($form['#id'] == 'node-form') { _repeat_nodegen_rrule_process_override($form); } } function _repeat_nodegen_rrule_process_override(&$element) { if ($element['#type'] == 'date_repeat_rrule') { if (is_array($element['#process'])) { $element['#process'][] = 'repeat_nodegen_rrule_process'; } else { $element['#process'] = array('date_repeat_rrule_process', 'repeat_nodegen_rrule_process'); } if (is_array($element['#element_validate'])) { array_unshift($element['#element_validate'], 'repeat_nodegen_rrule_validate'); } else { $element['#element_validate'] = array('repeat_nodegen_rrule_validate', 'date_repeat_rrule_validate'); } } $children = element_children($element); foreach ($children as $child) { _repeat_nodegen_rrule_process_override($element[$child]); } } function repeat_nodegen_rrule_process($element, $form_state) { $element['generate_nodes'] = array( '#type' => 'radios', '#title' => t('Generate each date as a single node'), '#options' => array(0 => t('No'), 1 => t('Yes')), '#default_value' => 0, '#weight' => 1, '#description' => t('If you choose yes, you will note be able to edit the nodes as a series once they are generated.'), '#prefix' => '
', '#suffix' => '
', ); $element['UNTIL']['#weight'] = 2; $element['advanced']['#weight'] = 3; $element['exceptions']['#weight'] = 4; $element['help']['#weight'] = 5; return $element; } function repeat_nodegen_rrule_validate($element, &$form_state) { $field_name = $element['#parents'][0]; $generate = $form_state['values'][$field_name]['rrule']['generate_nodes']; if ($generate) { $el_g = array(); $el_g['#parents'] = array('repeat_nodegen'); // date_repeat clobbers the element, so we need to save the generate flag somewhere form_set_value($el_g, array('field_name' => $field_name, 'generate' => 1), $form_state); } } function repeat_nodegen_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { if ($op == 'presave') { if ($node->repeat_nodegen['generate']) { $field_name = $node->repeat_nodegen['field_name']; if (!isset($node->$field_name)) { return ; } $dates = $node->$field_name; $rrule_date_filter = create_function('$a', 'return is_array($a) && isset($a["rrule"]);'); if (is_array($dates) && (count(array_filter($dates, $rrule_date_filter)) == count($dates))) { } // convert this node to a single-date node with no repetition $first_date = array_shift($dates); unset($first_date['rrule']); $node->$field_name = array($first_date); // save the remaining dates into the $generate_key so that we can create more nodes after insertion $node->repeat_nodegen['dates'] = $dates; } } if ($op == 'insert') { if (isset($node->repeat_nodegen) && $node->repeat_nodegen['generate'] && is_array($node->repeat_nodegen['dates'])) { $repeat_info = $node->repeat_nodegen; unset($node->repeat_nodegen); // prevents infinite recursion when we save below... $field_name = $repeat_info['field_name']; foreach ($repeat_info['dates'] as $date) { unset($node->nid); unset($date['rrule']); $node->$field_name = array($date); node_save($node); } } } }