mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 15:23:11 +02:00
Add WireLog option for specifying which user should be recorded with the log entry (if different from current user).
This commit is contained in:
@@ -1476,8 +1476,9 @@ abstract class Wire implements WireTranslatable, WireFuelable, WireTrackable {
|
||||
*
|
||||
* @param string $str Text to log, or omit to return the `$log` API variable.
|
||||
* @param array $options Optional extras to include:
|
||||
* - `url` (string): URL to record the with the log entry (default=auto-detect)
|
||||
* - `name` (string): Name of log to use (default=auto-detect)
|
||||
* - `url` (string): URL to record the with the log entry (default=auto-detect)
|
||||
* - `name` (string): Name of log to use (default=auto-detect)
|
||||
* - `user` (User|string|null): User instance, user name, or null to log for current User. (default=null)
|
||||
* @return WireLog
|
||||
*
|
||||
*/
|
||||
|
@@ -95,6 +95,7 @@ class WireLog extends Wire {
|
||||
* @param array $options Options to modify default behavior:
|
||||
* - `showUser` (bool): Include the username in the log entry? (default=true)
|
||||
* - `showURL` (bool): Include the current URL in the log entry? (default=true)
|
||||
* - `user` (User|string|null): User instance, user name, or null to use current User. (default=null)
|
||||
* - `url` (bool): URL to record with the log entry (default=auto determine)
|
||||
* - `delimiter` (string): Log entry delimiter (default="\t" aka tab)
|
||||
* @return bool Whether it was written or not (generally always going to be true)
|
||||
@@ -106,6 +107,7 @@ class WireLog extends Wire {
|
||||
$defaults = array(
|
||||
'showUser' => true,
|
||||
'showURL' => true,
|
||||
'user' => null,
|
||||
'url' => '', // URL to show (default=blank, auto-detect)
|
||||
'delimiter' => "\t",
|
||||
);
|
||||
@@ -141,8 +143,15 @@ class WireLog extends Wire {
|
||||
}
|
||||
|
||||
if($options['showUser']) {
|
||||
$user = $this->wire('user');
|
||||
$text = ($user && $user->id ? $user->name : "?") . "$options[delimiter]$text";
|
||||
$user = !empty($options['user']) ? $options['user'] : $this->wire('user');
|
||||
$userName = '';
|
||||
if($user instanceof Page) {
|
||||
$userName = $user->id ? $user->name : '?';
|
||||
} else if(is_string($user)) {
|
||||
$userName = $user;
|
||||
}
|
||||
if(empty($userName)) $userName = '?';
|
||||
$text = "$userName$options[delimiter]$text";
|
||||
}
|
||||
|
||||
return $log->save($text);
|
||||
|
Reference in New Issue
Block a user