$log), 'full'); // Add the log's "done" status. if ($log->done) { $status = 'DONE'; } else { $status = 'NOT DONE'; drupal_set_message('This log item is not done.', 'warning'); } $output['log'][$log->id]['done'] = array( '#markup' => '
Date: ' . $date . '
', '#weight' => -99, ); } return $output; } /** * Page to select log Type to add new log. */ function log_add_types_page() { $items = array(); foreach (log_types() as $log_type_key => $log_type) { if (log_access('create', $log_type)) { $items[] = l(entity_label('log_type', $log_type), 'log/add/' . $log_type_key); } } return array( 'list' => array( '#theme' => 'item_list', '#items' => $items, '#title' => t('Select a type of log to create.'), ), ); } /** * Add new log page callback. */ function log_add($type) { $log_type = log_types($type); $log = entity_create('log', array('type' => $type)); drupal_set_title(t('Log @name', array('@name' => entity_label('log_type', $log_type)))); $output = drupal_get_form('log_form', $log); return $output; } /** * Log Form. */ function log_form($form, &$form_state, $log) { $form['log'] = array( '#type' => 'value', '#value' => $log, ); // Load the log type. $log_type = log_type_load($log->type); // Only display the name field if it's editable. if (!empty($log_type->name_edit)) { $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#description' => t('Leave this blank to automatically generate a name.'), '#default_value' => $log->name, ); } // Timestamp $timestamp_default = !empty($log->timestamp) ? date('Y-m-d H:i:s', $log->timestamp) : ''; $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' => $timestamp_default, '#required' => TRUE, ); // If the log is new, and the log type marks new logs as "done" by default, // mark the log as done. if (empty($log->id) && !empty($log_type->done)) { $log->done = TRUE; } $form['done'] = array( '#type' => 'checkbox', '#title' => t('Done'), '#description' => t('Mark this log as done.'), '#default_value' => $log->done, ); // Log user id. $form['uid'] = array( '#type' => 'value', '#value' => $log->uid, ); field_attach_form('log', $log, $form, $form_state); $submit = array(); if (!empty($form['#submit'])) { $submit += $form['#submit']; } $form['actions'] = array( '#weight' => 100, ); $form['actions']['submit'] = array( '#type' => 'submit', '#value' => t('Save log'), '#submit' => $submit + array('log_form_submit'), ); // Show Delete button if allowed. $log_id = entity_id('log' ,$log); if (!empty($log_id) && log_access('delete', $log)) { // Get the destination query parameter. If it is the current path, change to