BynderException.php in Bynder 8.3
File
src/Exception/BynderException.php
View source
<?php
namespace Drupal\bynder\Exception;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Messenger\MessengerTrait;
abstract class BynderException extends \Exception {
use StringTranslationTrait;
use MessengerTrait;
protected $adminPermission = 'administer bynder configuration';
protected $adminMessage;
protected $logMessage;
protected $logMessageArgs;
public function __construct($message, $admin_message = NULL, $log_message = NULL, $log_message_args = []) {
$this->adminMessage = $admin_message ?: $message;
$this->logMessage = $log_message ?: $this->adminMessage;
$this->logMessageArgs = $log_message_args;
parent::__construct($message);
}
public function displayMessage() {
if (\Drupal::currentUser()
->hasPermission($this->adminPermission)) {
$this
->messenger()
->addError($this->adminMessage);
}
else {
$this
->messenger()
->addError($this
->getMessage());
}
}
public function logException() {
\Drupal::logger('bynder')
->error($this->logMessage, $this->logMessageArgs);
return $this;
}
}