array( 'title' => t('Administer log module'), 'description' => t('Gives full access to everything in the log module.'), 'restrict access' => TRUE, ), 'administer log types' => array( 'title' => t('Administer log types'), 'restrict access' => TRUE, ), ); // Add permissions for each log type. foreach (log_types() as $log_type) { $type = $log_type->type; $ops = array('view', 'edit', 'delete'); $scopes = array('any', 'own'); $perms += array( "create $type log entities" => array( 'title' => t('Create new %type_name log entities', array('%type_name' => $log_type->label)), ), ); foreach ($ops as $op) { foreach ($scopes as $scope) { $perms += array( "$op $scope $type log entities" => array( 'title' => t(drupal_ucfirst($op) . ' ' . $scope . ' %type_name log entities', array('%type_name' => $log_type->label)), ), ); } } } return $perms; } /** * Implements hook_menu(). */ function log_menu() { $items = array(); $items['log/add'] = array( 'title' => 'Add log', 'page callback' => 'log_add_types_page', 'access callback' => 'log_add_access', 'file' => 'log.pages.inc', ); foreach (log_types() as $type => $info) { $items['log/add/' . $type] = array( 'title' => 'Add log', 'page callback' => 'log_add', 'page arguments' => array(2), 'access callback' => 'log_access', 'access arguments' => array('create', 2), 'file' => 'log.pages.inc', ); } $log_uri = 'log/%log'; $log_uri_argument_position = 1; $items[$log_uri] = array( 'title callback' => 'entity_label', 'title arguments' => array('log', $log_uri_argument_position), 'page callback' => 'log_view', 'page arguments' => array($log_uri_argument_position), 'access callback' => 'log_access', 'access arguments' => array('view', $log_uri_argument_position), 'file' => 'log.pages.inc', ); $items[$log_uri . '/view'] = array( 'title' => 'View', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); $items[$log_uri . '/delete'] = array( 'title' => 'Delete log', 'title callback' => 'log_label', 'title arguments' => array($log_uri_argument_position), 'page callback' => 'drupal_get_form', 'page arguments' => array('log_delete_form', $log_uri_argument_position), 'access callback' => 'log_access', 'access arguments' => array('edit', $log_uri_argument_position), 'file' => 'log.pages.inc', ); $items[$log_uri . '/edit'] = array( 'title' => 'Edit', 'page callback' => 'drupal_get_form', 'page arguments' => array('log_form', $log_uri_argument_position), 'access callback' => 'log_access', 'access arguments' => array('edit', $log_uri_argument_position), 'file' => 'log.pages.inc', 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, ); /** * Log admin paths */ // Log settings form $items['admin/config/log'] = array( 'title' => 'Log', 'description' => 'Configure log module.', 'page callback' => 'system_admin_menu_block_page', 'access arguments' => array('administer log module'), 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'), ); $items['admin/config/log/settings'] = array( 'title' => 'Log settings', 'description' => 'Administer log settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('log_settings_form', 4), 'access arguments' => array('administer log module'), 'file' => 'log.admin.inc', ); // Log type delete form $items['admin/config/log/types/%log_type/delete'] = array( 'title' => 'Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('log_type_form_delete_confirm', 4), 'access arguments' => array('administer log types'), 'weight' => 1, 'type' => MENU_NORMAL_ITEM, 'file' => 'log.admin.inc', ); return $items; } /** * Implements hook_admin_paths(). */ function log_admin_paths() { // Display log paths with the admin theme, if specified. if (variable_get('log_admin_theme', TRUE)) { $paths = array( 'log*' => TRUE, ); return $paths; } } /** * Implements hook_entity_info(). */ function log_entity_info() { $return = array( 'log' => array( 'label' => t('Log'), 'entity class' => 'Log', 'controller class' => 'LogController', 'base table' => 'log', 'fieldable' => TRUE, 'entity keys' => array( 'id' => 'id', 'bundle' => 'type', 'label' => 'name', ), 'bundle keys' => array( 'bundle' => 'type', ), 'bundles' => array(), 'load hook' => 'log_load', 'view modes' => array( 'full' => array( 'label' => t('Default'), 'custom settings' => FALSE, ), ), 'label callback' => 'entity_class_label', 'uri callback' => 'entity_class_uri', 'module' => 'log', 'access callback' => 'log_access', ), ); $return['log_type'] = array( 'label' => t('Log type'), 'entity class' => 'LogType', 'controller class' => 'LogTypeController', 'base table' => 'log_type', 'fieldable' => FALSE, 'bundle of' => 'log', 'exportable' => TRUE, 'entity keys' => array( 'id' => 'id', 'name' => 'type', 'label' => 'label', ), 'module' => 'log', // Enable the entity API's admin UI. 'admin ui' => array( 'path' => 'admin/config/log/types', 'file' => 'log.admin.inc', 'controller class' => 'LogTypeUIController', ), 'access callback' => 'log_type_access', ); return $return; } /** * Implements hook_entity_info_alter(). */ function log_entity_info_alter(&$entity_info) { foreach (log_types() as $type => $info) { $entity_info['log']['bundles'][$type] = array( 'label' => $info->label, 'admin' => array( 'path' => 'admin/config/log/types/manage/%log_type', 'real path' => 'admin/config/log/types/manage/' . $type, 'bundle argument' => 5, ), ); } } /** * Implements hook_entity_property_info_alter(). */ function log_entity_property_info_alter(&$info) { $properties = &$info['log']['properties']; $properties['name'] = array( 'label' => t('Name'), 'description' => t('The name of the log item.'), 'setter callback' => 'entity_property_verbatim_set', 'schema field' => 'name', ); $properties['type'] = array( 'label' => t('Log type'), 'type' => 'token', 'description' => t('The type of the log.'), 'setter callback' => 'entity_property_verbatim_set', 'setter permission' => 'administer log module', 'options list' => 'log_type_get_names', 'required' => TRUE, 'schema field' => 'type', ); $properties['uid'] = array( 'label' => t('Owner'), 'type' => 'user', 'description' => t('The owner of the log.'), 'setter callback' => 'entity_property_verbatim_set', 'setter permission' => 'administer log module', 'required' => TRUE, 'schema field' => 'uid', ); $properties['timestamp'] = array( 'label' => t('Timestamp'), 'type' => 'date', 'description' => t('The timestamp of the event being logged.'), 'setter callback' => 'entity_property_verbatim_set', 'setter permission' => 'administer log module', 'required' => TRUE, 'schema field' => 'timestamp', ); $properties['created'] = array( 'label' => t('Created'), 'type' => 'date', 'description' => t('The timestamp when the log was created.'), 'setter callback' => 'entity_property_verbatim_set', 'setter permission' => 'administer log module', 'required' => TRUE, 'schema field' => 'created', ); $properties['changed'] = array( 'label' => t('Changed'), 'type' => 'date', 'description' => t('The timestamp when the log was last modified.'), 'setter callback' => 'entity_property_verbatim_set', 'setter permission' => 'administer log module', 'required' => TRUE, 'schema field' => 'changed', ); $properties['done'] = array( 'label' => t('Done'), 'description' => t('Whether the log is done.'), 'setter callback' => 'entity_property_verbatim_set', 'setter permission' => 'administer log module', 'schema field' => 'done', 'type' => 'boolean', ); } /** * Implements hook_field_extra_fields(). */ function log_field_extra_fields() { $log_types = log_types(); $extra_fields = array( 'log' => array(), ); foreach ($log_types as $type) { // Display the name field if names are editable. if ($type->name_edit) { $extra_fields['log'][$type->type]['form']['name'] = array( 'label' => t('Name'), 'description' => t('The name of the log entry.'), 'weight' => -10, ); } // Display the timestamp field. $extra_fields['log'][$type->type]['form']['timestamp'] = array( 'label' => t('Timestamp'), 'description' => t('The timestamp of the log entry.'), 'weight' => -5, ); // Display the done field. $extra_fields['log'][$type->type]['form']['done'] = array( 'label' => t('Done'), 'description' => t('Whether or not the log is done.'), 'weight' => 100, ); } return $extra_fields; } /** * Implements hook_[entity]_insert(). */ function log_log_insert($log) { // Generate the log's name. log_name_generate($log); } /** * Implements hook_[entity]_update(). */ function log_log_update($log) { // Generate the log's name. log_name_generate($log); } /** * Implements hook_action_info(). */ function log_action_info() { return array( 'log_done_action' => array( 'type' => 'log', 'label' => t('Mark as done'), 'configurable' => FALSE, 'triggers' => array('any'), ), 'log_undone_action' => array( 'type' => 'log', 'label' => t('Mark as not done'), 'configurable' => FALSE, 'triggers' => array('any'), ), 'log_clone_action' => array( 'type' => 'log', 'label' => t('Clone'), 'configurable' => TRUE, 'triggers' => array('any'), ), 'log_reschedule_action' => array( 'type' => 'log', 'label' => t('Reschedule'), 'configurable' => TRUE, 'triggers' => array('any'), ), ); } /*************************************************************** * Log action callbacks * *************************************************************/ /** * Action function for log_done_action. * * Marks a log as done. * * @param object $log * The log entity object. * @param array $context * Array with parameters for this action. */ function log_done_action($log, $context = array()) { // Only proceed if the log is not already done. if ($log->done) { return; } // Mark the log as done. $log->done = TRUE; // Save the log log_save($log); } /** * Action function for log_undone_action. * * Marks a log as not done. * * @param object $log * The log entity object. * @param array $context * Array with parameters for this action. */ function log_undone_action($log, $context = array()) { // Only proceed if the log is already done. if (!$log->done) { return; } // Mark the log as done. $log->done = FALSE; // Save the log log_save($log); } /** * Log reschedule action configuration form. */ function log_reschedule_action_form($context, $form_state) { return _log_action_date_form($context, $form_state, 'Reschedule'); } /** * Log reschedule action configuration form submit. */ function log_reschedule_action_submit($form, $form_state) { return _log_action_date_form_submit($form, $form_state); } /** * Action function for log_reschedule_action. * * Changes the date of a log. * * @param object $log * The log entity object. * @param array $context * Array with parameters for this action. */ function log_reschedule_action($log, $context = array()) { _log_action_date_form_action($log, $context); } /** * Log clone action configuration form. */ function log_clone_action_form($context, $form_state) { return _log_action_date_form($context, $form_state, 'Clone', FALSE); } /** * Log clone action configuration form submit. */ function log_clone_action_submit($form, $form_state) { return _log_action_date_form_submit($form, $form_state); } /** * Action function for log_clone_action. * * Clones a log and gives it a new timestamp. * * @param object $log * The log entity object. * @param array $context * Array with parameters for this action. */ function log_clone_action($log, $context = array()) { // Clear the log id. unset($log->id); // Set the date and save. _log_action_date_form_action($log, $context); } /** * Log action form with date field (helper function). * * @param $context * The context passed into the action form function. * @param $form_state * The form state passed into the action form function. * @param $name * The action name. * @param $default_timestamp * Whether or not to use the log's timestamp as default (defaults to TRUE). * * @return array * Returns a form array. */ function _log_action_date_form($context, $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' => t($name) . ':')); } // Otherwise, display the one. else { $markup = '