You are here

abstract class BynderException in Bynder 8

Same name and namespace in other branches
  1. 8.3 src/Exception/BynderException.php \Drupal\bynder\Exception\BynderException
  2. 8.2 src/Exception/BynderException.php \Drupal\bynder\Exception\BynderException
  3. 4.0.x src/Exception/BynderException.php \Drupal\bynder\Exception\BynderException

Base exception class for Bynder.

Hierarchy

Expanded class hierarchy of BynderException

1 file declares its use of BynderException
BynderUpload.php in src/Plugin/EntityBrowser/Widget/BynderUpload.php

File

src/Exception/BynderException.php, line 10

Namespace

Drupal\bynder\Exception
View source
abstract class BynderException extends \Exception {
  use StringTranslationTrait;

  /**
   * Admin permission related to this exception.
   *
   * @var string
   */
  protected $adminPermission = 'administer bynder configuration';

  /**
   * Message level to be used when displaying the message to the user.
   *
   * @var string
   */
  protected $messageLevel = 'error';

  /**
   * User-facing for admin users.
   *
   * @var string
   */
  protected $adminMessage;

  /**
   * Message to be logged in the Drupal's log.
   *
   * @var string
   */
  protected $logMessage;

  /**
   * Arguments for the log message.
   *
   * @var array
   */
  protected $logMessageArgs;

  /**
   * Constructs BundleNotExistException.
   */
  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);
  }

  /**
   * Displays message to the user.
   */
  public function displayMessage() {
    if (\Drupal::currentUser()
      ->hasPermission($this->adminPermission)) {
      drupal_set_message($this->adminMessage, $this->messageLevel);
    }
    else {
      drupal_set_message($this
        ->getMessage(), $this->messageLevel);
    }
  }

  /**
   * Logs exception into Drupal's log.
   *
   * @return \Drupal\bynder\Exception\BynderException
   *   This exception.
   */
  public function logException() {
    \Drupal::logger('bynder')
      ->error($this->logMessage, $this->logMessageArgs);
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BynderException::$adminMessage protected property User-facing for admin users.
BynderException::$adminPermission protected property Admin permission related to this exception. 2
BynderException::$logMessage protected property Message to be logged in the Drupal's log.
BynderException::$logMessageArgs protected property Arguments for the log message.
BynderException::$messageLevel protected property Message level to be used when displaying the message to the user.
BynderException::displayMessage public function Displays message to the user.
BynderException::logException public function Logs exception into Drupal's log.
BynderException::__construct public function Constructs BundleNotExistException. 9
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.