You are here

function _log_action_date_form in Log entity 7

Log action form with date field (helper function).

Parameters

array $context: The context passed into the action form function.

array $form_state: The form state passed into the action form function.

string $name: The action name.

bool $default_timestamp: Whether or not to use the log's timestamp as default (defaults to TRUE).

Return value

array Returns a form array.

2 calls to _log_action_date_form()
log_clone_action_form in ./log.module
Log clone action configuration form.
log_reschedule_action_form in ./log.module
Log reschedule action configuration form.

File

./log.module, line 651
Log - A general purpose record keeping system.

Code

function _log_action_date_form(array $context, array $form_state, $name, $default_timestamp = TRUE) {

  // Build a list of the logs being cloned.
  if (!empty($form_state['selection'])) {
    $logs = array();
    $query = db_select('log', 'l');
    $query
      ->addField('l', 'name');
    $query
      ->condition('l.id', $form_state['selection']);
    $results = $query
      ->execute();
    foreach ($results as $result) {
      $logs[] = $result->name;
    }

    // If there is more than one log, theme an item list.
    if (count($logs) > 1) {
      $markup = theme('item_list', array(
        'items' => $logs,
        'title' => $name . ':',
      ));
    }
    else {
      $markup = '<h3>' . $name . ' ' . reset($logs) . '</h3>';
    }

    // Display the log(s) in the form.
    $form['logs'] = array(
      '#type' => 'markup',
      '#markup' => $markup,
    );
  }

  // Default timestamp to today.
  $timestamp = REQUEST_TIME;

  // If only one log item is selected, and the $default_timestamp parameter is
  // set, use it's timestamp as the default.
  if (!empty($logs) && count($logs) == 1 && $default_timestamp) {
    $log_id = reset($form_state['selection']);
    $log = log_load($log_id);
    $timestamp = $log->timestamp;
  }

  // Convert the timestamp to the format Date API expects.
  $default_value = date('Y-m-d H:i', $timestamp);

  // "Date" field.
  $form['timestamp'] = array(
    '#type' => 'date_select',
    '#title' => t('Date'),
    '#date_format' => 'M j Y',
    '#date_type' => DATE_FORMAT_UNIX,
    '#date_year_range' => '-10:+3',
    '#default_value' => $default_value,
    '#required' => TRUE,
  );
  return $form;
}