You are here

abstract class BynderException in Bynder 8.2

Same name and namespace in other branches
  1. 8.3 src/Exception/BynderException.php \Drupal\bynder\Exception\BynderException
  2. 8 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

3 files declare their use of BynderException
BynderUpload.php in src/Plugin/EntityBrowser/Widget/BynderUpload.php
UnableToAddUsageException.php in modules/bynder_usage/src/Exception/UnableToAddUsageException.php
UnableToDeleteUsageException.php in modules/bynder_usage/src/Exception/UnableToDeleteUsageException.php

File

src/Exception/BynderException.php, line 11

Namespace

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

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

  /**
   * 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)) {
      $this
        ->messenger()
        ->addError($this->adminMessage);
    }
    else {
      $this
        ->messenger()
        ->addError($this
        ->getMessage());
    }
  }

  /**
   * 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::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
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
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.