You are here

node_recur.api.php in Node recur 7

Same filename and directory in other branches
  1. 7.2 node_recur.api.php

File

node_recur.api.php
View source
<?php

/**
 * Implements hook_node_recur_access_alter().
 *
 * Alter the access control for the node recur form
 * 
 * @param &$access
 *   Boolean status of access for the current user.
 * @param $node
 *   The node being recurred.
 */
function hook_node_recur_access_alter(&$access, $node) {
  if ($node->type == 'story') {
    $access = TRUE;
  }
}

/**
 * Implements hook_node_recur_batch_redirect_alter().
 *
 * Alter redirect path after a batch operation. This is only invoked
 * when recurring existing nodes, not new nodes.
 * 
 * @param &$path
 *   The path that the user will be redirected to after recurring a node.
 * @param $nid
 *    The nid of the node being recurred.
 */
function hook_node_recur_batch_redirect_alter(&$path, $nid = NULL) {
  $path = 'node/' . $nid . '/edit';
}

/**
 * Implements hook_node_recur_validate_dates().
 *
 * This hook is invoked when validating the node recur date form. It will
 * only be called if there are no recorded validation errors found by
 * this module.
 *
 * @param $node
 *   The node being recurred.
 * @param $form_state
 *   The form's form state array.
 * @return
 *   An array of errors to be printed to the screen. Each error is an 
 *   array with the keys 'field' (the name of the field) and 'error'
 *   (the message to print to the screen).
 */
function hook_node_recur_validate_dates($node, $form_state) {
  $errors = array();
  if ($node->type == 'class') {
    if ($form_state['values']['option'] == 'days') {
      if (isset($form_state['values']['days']['monday'])) {
        $errors[] = array(
          'field' => 'days',
          'message' => t('Classes cannot occur on Monday.'),
        );
      }
      if (isset($form_state['values']['days']['tuesday'])) {
        $errors[] = array(
          'field' => 'days',
          'message' => t('Classes cannot occur on Tuesday.'),
        );
      }
    }
  }
  return $errors;
}

/**
 * Implements hook_node_recur_dates_alter().
 * 
 * Modify the recurring dates before they are used to recur nodes.
 * 
 * @param &$dates
 *   An array of start and end dates, keyed by 'start' and 'end'. The 
 *   dates are in timestamp format.
 * @param $variables
 *   An array of variables supplied by and generated by the node recur
 *   form. The possible available values are:
 *     node: The node being recurred.
 *     start_date: The initial starting date of the node (ie, '2012-10-22 15:45:00').
 *     end_date: The initial ending date of the node, if one exists (ie, '2012-10-22 16:45:00').
 *     option: The recurring option selected.
 *     until: The date (timestamp) to recur until.
 *     days: An array of days selected, if the 'days' option was used.
 *     frequency: The selected frequency, if the 'rules' option was used.
 *     period: The selected period, if the 'rules' option was used.
 *     weekends: TRUE if weekends should be included, otherwise FALSE, if the 'rules' option was used.
 */
function hook_node_recur_dates_alter(&$dates, $variables) {
}