Commit 3690ae3b authored by m.stenta's avatar m.stenta
Browse files

Drupal coding standards cleanup.

parent f43a40bb
......@@ -2,13 +2,21 @@
/**
* @file
* Log admin pages
* Log admin pages.
*/
/**
* Log settings form.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*
* @return array
* Returns the form array.
*/
function log_settings_form($form, &$form_state) {
function log_settings_form(array $form, array &$form_state) {
// Use admin theme for log viewing/editing.
$form['log_admin_theme'] = array(
......@@ -24,8 +32,20 @@ function log_settings_form($form, &$form_state) {
/**
* Generates the log type editing form.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
* @param string $log_type
* The log type.
* @param string $op
* The operation being performed.
*
* @return array
* Returns the form array.
*/
function log_type_form($form, &$form_state, $log_type, $op = 'edit') {
function log_type_form(array $form, array &$form_state, $log_type, $op = 'edit') {
if ($op == 'clone') {
$log_type->label .= ' (cloned)';
......@@ -107,7 +127,7 @@ function log_type_form($form, &$form_state, $log_type, $op = 'edit') {
'#value' => t('Delete log type'),
'#weight' => 45,
'#limit_validation_errors' => array(),
'#submit' => array('log_type_form_submit_delete')
'#submit' => array('log_type_form_submit_delete'),
);
}
return $form;
......@@ -115,8 +135,13 @@ function log_type_form($form, &$form_state, $log_type, $op = 'edit') {
/**
* Submit handler for creating/editing log_type.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*/
function log_type_form_submit(&$form, &$form_state) {
function log_type_form_submit(array $form, array &$form_state) {
$log_type = entity_ui_form_submit_build_entity($form, $form_state);
// Save and go back.
log_type_save($log_type);
......@@ -125,23 +150,43 @@ function log_type_form_submit(&$form, &$form_state) {
$form_state['redirect'] = 'admin/config/log/types';
}
function log_type_form_submit_delete(&$form, &$form_state) {
/**
* Submit handler for deleting log_type.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*/
function log_type_form_submit_delete(array $form, array &$form_state) {
$form_state['redirect'] = 'admin/config/log/types/' . $form_state['log_type']->type . '/delete';
}
/**
* Log type delete form.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
* @param string $log_type
* The log type.
*
* @return array
* Returns a delete confirm form array.
*/
function log_type_form_delete_confirm($form, &$form_state, $log_type) {
function log_type_form_delete_confirm(array $form, array &$form_state, $log_type) {
$form['log_type'] = array(
'#type' => 'value',
'#value' => $log_type,
);
// Always provide entity id in the same form key as in the entity edit form.
$form['log_type_id'] = array('#type' => 'value', '#value' => entity_id('log_type' ,$log_type));
$form['log_type_id'] = array(
'#type' => 'value',
'#value' => entity_id('log_type', $log_type));
return confirm_form($form,
t('Are you sure you want to delete log type %title?', array('%title' => entity_label('log_type', $log_type))),
'log/' . entity_id('log_type' ,$log_type),
'log/' . entity_id('log_type', $log_type),
t('This action cannot be undone.'),
t('Delete'),
t('Cancel')
......@@ -150,8 +195,13 @@ function log_type_form_delete_confirm($form, &$form_state, $log_type) {
/**
* Log type delete form submit handler.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*/
function log_type_form_delete_confirm_submit($form, &$form_state) {
function log_type_form_delete_confirm_submit(array $form, array &$form_state) {
$log_type = $form_state['values']['log_type'];
log_type_delete($log_type);
......
......@@ -9,6 +9,10 @@
* Log class.
*/
class Log extends Entity {
/**
* {@inheritdoc}
*/
protected function defaultLabel() {
if (!empty($this->name)) {
return $this->name;
......@@ -18,9 +22,13 @@ class Log extends Entity {
}
}
/**
* {@inheritdoc}
*/
protected function defaultUri() {
return array('path' => 'log/' . $this->identifier());
}
}
/**
......@@ -28,7 +36,9 @@ class Log extends Entity {
*/
class LogController extends EntityAPIController {
// Initialize an empty object.
/**
* {@inheritdoc}
*/
public function create(array $values = array()) {
global $user;
$values += array(
......@@ -44,11 +54,16 @@ class LogController extends EntityAPIController {
return parent::create($values);
}
// Set the changed timestamp when a log entity is saved.
/**
* {@inheritdoc}
*/
public function save($entity, DatabaseTransaction $transaction = NULL) {
// Set the changed timestamp when a log entity is saved.
$entity->changed = REQUEST_TIME;
return parent::save($entity, $transaction);
}
}
/**
......@@ -59,19 +74,30 @@ class LogType extends Entity {
public $label;
public $weight = 0;
/**
* {@inheritdoc}
*/
public function __construct($values = array()) {
parent::__construct($values, 'log_type');
}
function isLocked() {
/**
* {@inheritdoc}
*/
public function isLocked() {
return isset($this->status) && empty($this->is_new) && (($this->status & ENTITY_IN_CODE) || ($this->status & ENTITY_FIXED));
}
}
/**
* Log type controller class.
*/
class LogTypeController extends EntityAPIControllerExportable {
/**
* {@inheritdoc}
*/
public function create(array $values = array()) {
$values += array(
'id' => NULL,
......@@ -83,6 +109,7 @@ class LogTypeController extends EntityAPIControllerExportable {
);
return parent::create($values);
}
}
/**
......@@ -97,4 +124,5 @@ class LogTypeUIController extends EntityDefaultUIController {
$items[$this->path]['description'] = 'Manage log types.';
return $items;
}
}
\ No newline at end of file
}
......@@ -2,7 +2,7 @@
/**
* @file
* Log install
* Log install.
*/
/**
......@@ -69,7 +69,7 @@ function log_schema() {
'timestamp' => array('timestamp'),
'created' => array('created'),
'modified' => array('changed'),
'done' => array('done')
'done' => array('done'),
),
);
$schema['log_type'] = array(
......@@ -117,7 +117,7 @@ function log_schema() {
),
// The following fields are required to make Log types exportable via
// Entity API and Ctools. See
// Entity API and Ctools.
'status' => array(
'type' => 'int',
'not null' => TRUE,
......@@ -151,8 +151,11 @@ function log_uninstall() {
/**
* Add a field to log types that allow their names to be editable by users.
*
* @param array $sandbox
* The update sandbox array.
*/
function log_update_7000(&$sandbox) {
function log_update_7000(array &$sandbox) {
$spec = array(
'description' => 'Boolean: log name is user editable.',
'type' => 'int',
......@@ -165,8 +168,11 @@ function log_update_7000(&$sandbox) {
/**
* Add 'timestamp' field to Logs.
*
* @param array $sandbox
* The update sandbox array.
*/
function log_update_7001(&$sandbox) {
function log_update_7001(array &$sandbox) {
// Add timestamp field to Logs.
$timestamp = array(
......@@ -179,8 +185,11 @@ function log_update_7001(&$sandbox) {
/**
* Add 'done' fields to Logs and Log Types.
*
* @param array $sandbox
* The update sandbox array.
*/
function log_update_7002(&$sandbox) {
function log_update_7002(array &$sandbox) {
// Add done field to Logs and Log Types.
$done = array(
......
......@@ -2,8 +2,7 @@
/**
* @file
* Log
* A general purpose record keeping system.
* Log - A general purpose record keeping system.
*/
/****************************************************************
......@@ -40,7 +39,7 @@ function log_permission() {
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)),
'title' => drupal_ucfirst($op) . ' ' . $scope . ' ' . t('%type_name log entities', array('%type_name' => $log_type->label)),
),
);
}
......@@ -114,11 +113,7 @@ function log_menu() {
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
);
/**
* Log admin paths
*/
// Log settings form
// Log settings form.
$items['admin/config/log'] = array(
'title' => 'Log',
'description' => 'Configure log module.',
......@@ -136,7 +131,7 @@ function log_menu() {
'file' => 'log.admin.inc',
);
// Log type delete form
// Log type delete form.
$items['admin/config/log/types/%log_type/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
......@@ -156,12 +151,13 @@ function log_menu() {
function log_admin_paths() {
// Display log paths with the admin theme, if specified.
$paths = array();
if (variable_get('log_admin_theme', TRUE)) {
$paths = array(
'log*' => TRUE,
);
return $paths;
}
return $paths;
}
/**
......@@ -211,7 +207,7 @@ function log_entity_info() {
'label' => 'label',
),
'module' => 'log',
// Enable the entity API's admin UI.
// Enable the entity API admin UI.
'admin ui' => array(
'path' => 'admin/config/log/types',
'file' => 'log.admin.inc',
......@@ -225,6 +221,8 @@ function log_entity_info() {
/**
* Implements hook_entity_info_alter().
*
* @inheritdoc
*/
function log_entity_info_alter(&$entity_info) {
foreach (log_types() as $type => $info) {
......@@ -343,7 +341,7 @@ function log_field_extra_fields() {
}
/**
* Implements hook_[entity]_insert().
* Implements hook_log_insert().
*/
function log_log_insert($log) {
......@@ -352,7 +350,7 @@ function log_log_insert($log) {
}
/**
* Implements hook_[entity]_update().
* Implements hook_log_update().
*/
function log_log_update($log) {
......@@ -401,12 +399,12 @@ function log_action_info() {
*
* Marks a log as done.
*
* @param object $log
* @param Log $log
* The log entity object.
* @param array $context
* Array with parameters for this action.
*/
function log_done_action($log, $context = array()) {
function log_done_action(Log $log, $context = array()) {
// Only proceed if the log is not already done.
if ($log->done) {
......@@ -416,7 +414,7 @@ function log_done_action($log, $context = array()) {
// Mark the log as done.
$log->done = TRUE;
// Save the log
// Save the log.
log_save($log);
}
......@@ -425,12 +423,12 @@ function log_done_action($log, $context = array()) {
*
* Marks a log as not done.
*
* @param object $log
* @param Log $log
* The log entity object.
* @param array $context
* Array with parameters for this action.
*/
function log_undone_action($log, $context = array()) {
function log_undone_action(Log $log, $context = array()) {
// Only proceed if the log is already done.
if (!$log->done) {
......@@ -440,21 +438,37 @@ function log_undone_action($log, $context = array()) {
// Mark the log as done.
$log->done = FALSE;
// Save the log
// Save the log.
log_save($log);
}
/**
* Log reschedule action configuration form.
*
* @param array $context
* The context passed into the action form function.
* @param array $form_state
* The form state passed into the action form function.
*
* @return array
* Returns a form array.
*/
function log_reschedule_action_form($context, $form_state) {
function log_reschedule_action_form(array $context, array $form_state) {
return _log_action_date_form($context, $form_state, 'Reschedule');
}
/**
* Log reschedule action configuration form submit.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*
* @return array
* Returns an array that will end up in the action's context.
*/
function log_reschedule_action_submit($form, $form_state) {
function log_reschedule_action_submit(array $form, array $form_state) {
return _log_action_date_form_submit($form, $form_state);
}
......@@ -463,26 +477,42 @@ function log_reschedule_action_submit($form, $form_state) {
*
* Changes the date of a log.
*
* @param object $log
* @param Log $log
* The log entity object.
* @param array $context
* Array with parameters for this action.
*/
function log_reschedule_action($log, $context = array()) {
function log_reschedule_action(Log $log, $context = array()) {
_log_action_date_form_action($log, $context);
}
/**
* Log clone action configuration form.
*
* @param array $context
* The context passed into the action form function.
* @param array $form_state
* The form state passed into the action form function.
*
* @return array
* Returns a form array.
*/
function log_clone_action_form($context, $form_state) {
function log_clone_action_form(array $context, array $form_state) {
return _log_action_date_form($context, $form_state, 'Clone', FALSE);
}
/**
* Log clone action configuration form submit.
*
* @param array $form
* The form array.
* @param array $form_state
* The form state array.
*
* @return array
* Returns an array that will end up in the action's context.
*/
function log_clone_action_submit($form, $form_state) {
function log_clone_action_submit(array $form, array $form_state) {
return _log_action_date_form_submit($form, $form_state);
}
......@@ -491,12 +521,12 @@ function log_clone_action_submit($form, $form_state) {
*
* Clones a log and gives it a new timestamp.
*
* @param object $log
* @param Log $log
* The log entity object.
* @param array $context
* Array with parameters for this action.
*/
function log_clone_action($log, $context = array()) {
function log_clone_action(Log $log, $context = array()) {
// Clear the log id.
unset($log->id);
......@@ -508,19 +538,19 @@ function log_clone_action($log, $context = array()) {
/**
* Log action form with date field (helper function).
*
* @param $context
* @param array $context
* The context passed into the action form function.
* @param $form_state
* @param array $form_state
* The form state passed into the action form function.
* @param $name
* @param string $name
* The action name.
* @param $default_timestamp
* @param bool $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) {
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'])) {
......@@ -535,12 +565,12 @@ function _log_action_date_form($context, $form_state, $name, $default_timestamp
// 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) . ':'));
$markup = theme('item_list', array('items' => $logs, 'title' => $name . ':'));
}
// Otherwise, display the one.
else {
$markup = '<h3>' . t($name) . ' ' . reset($logs) . '</h3>';
$markup = '<h3>' . $name . ' ' . reset($logs) . '</h3>';
}
// Display the log(s) in the form.
......@@ -564,7 +594,7 @@ function _log_action_date_form($context, $form_state, $name, $default_timestamp
// Convert the timestamp to the format Date API expects.
$default_value = date('Y-m-d H:i', $timestamp);
// "Date" field
// "Date" field.
$form['timestamp'] = array(
'#type' => 'date_select',
'#title' => t('Date'),
......@@ -581,15 +611,15 @@ function _log_action_date_form($context, $form_state, $name, $default_timestamp
/**
* Log action form with date field submit (helper function).
*
* @param $form
* The form passed into the action form submit function,
* @param $form_state
* @param array $form
* The form passed into the action form submit function.
* @param array $form_state
* The form state passed into the action form submit function.
*
* @return array
* Returns an array that will end up in the action's context.
*/
function _log_action_date_form_submit($form, $form_state) {
function _log_action_date_form_submit(array $form, array $form_state) {
return array(
'timestamp' => $form_state['values']['timestamp'],
);
......@@ -598,12 +628,12 @@ function _log_action_date_form_submit($form, $form_state) {
/**
* Log action form with date field (action helper function).
*
* @param $log
* The log passed into the action function,
* @param $context
* @param Log $log
* The log passed into the action function.
* @param array $context
* The context passed into the action function.
*/
function _log_action_date_form_action($log, $context) {
function _log_action_date_form_action(Log $log, array $context) {
// Set the date.
$log->timestamp = strtotime($context['timestamp']);
......@@ -622,14 +652,14 @@ function _log_action_date_form_action($log, $context) {
/**
* Access callback for log entities.
*
* @param $op
* @param string $op
* The operation being performed. One of 'view', 'edit', 'create', 'delete'.
* @param $log
* Optionally a specific log entity to check.
* @param $account
* @param Log|string $log
* Optionally a specific log entity to check, or a log type.
* @param object $account
* The user to check for. Leave it to NULL to check for the global user.
*
* @return boolean
* @return bool
* Whether access is allowed or not.
*/
function log_access($op, $log = NULL, $account = NULL) {
......@@ -648,7 +678,6 @@ function log_access($op, $log = NULL, $account = NULL) {
// $log may be either an object or a log type. Since log types cannot be
// an integer, use either id or type as the static cache id.
$cid = is_object($log) ? $log->id : $log;
// If we've already checked access for this log, user and op, return from
......@@ -705,8 +734,11 @@ function log_access($op, $log = NULL, $account = NULL) {
/**
* Access callback: Checks whether the user has permission to add a log.
*
* @return boolean
* TRUE if the user has add permission, otherwise FALSE.
* @param object|null $account
* Optionally, a user account to check access for.
*
* @return bool
* Returns TRUE if the user has add permission, otherwise FALSE.
*/
function log_add_access($account = NULL) {
......@@ -730,6 +762,14 @@ function log_add_access($account = NULL) {
/**
* Access callback for log type.
*
* @param string $op
* The operation being performed.
* @param Log|null $log
* Optionally, a log entity to check access for.
*
* @return bool
* Returns TRUE if user has access.
*/
function log_type_access($op, $log = NULL) {
return user_access('administer log types');
......@@ -741,6 +781,14 @@ function log_type_access($op, $log = NULL) {
/**