You are here

class LingotekContentEntityStorageException in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  2. 4.0.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  3. 3.0.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  4. 3.1.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  5. 3.2.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  6. 3.3.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  7. 3.4.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  8. 3.5.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  9. 3.6.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  10. 3.7.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  11. 3.8.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException

Hierarchy

Expanded class hierarchy of LingotekContentEntityStorageException

3 files declare their use of LingotekContentEntityStorageException
LingotekContentTranslationService.php in src/LingotekContentTranslationService.php
Contains \Drupal\lingotek\LingotekContentTranslationService.
LingotekEntityController.php in src/Controller/LingotekEntityController.php
LingotekManagementForm.php in src/Form/LingotekManagementForm.php
Contains \Drupal\Lingotek\Form\LingotekManagementForm.

File

src/Exception/LingotekContentEntityStorageException.php, line 16
Contains \Drupal\lingotek\Exception\LingotekContentEntityStorageException.

Namespace

Drupal\lingotek\Exception
View source
class LingotekContentEntityStorageException extends LingotekException {

  /**
   * The entity that could not be saved.
   *
   * @var \Drupal\Core\Entity\ContentEntityInterface
   */
  protected $entity;

  /**
   * @var string
   */
  protected $table;
  public function __construct(ContentEntityInterface $entity, \Exception $previous = NULL, $message = NULL, $code = 0) {
    parent::__construct($message, $code, $previous);
    $this->entity = $entity;
    $this->table = $this
      ->extractTableFromPreviousExceptionMessage($previous);
    $this->code = $previous
      ->getCode();
  }

  /**
   * Gets the table name that failed to update.
   */
  public function getTable() {
    return $this->table;
  }

  /**
   * Extract the problematic table from the previous exception message.
   *
   * @param \Exception $previous
   *
   * @returns
   *  A string with the problematic table name.
   */
  protected function extractTableFromPreviousExceptionMessage(\Exception $previous = NULL) {
    $table = '';
    if ($previous !== NULL) {

      // Previous message would be like:
      //    "Data too long for column 'name' at row 2"
      $previous_message = $previous
        ->getMessage();
      $strings = explode("'", $previous_message);
      $table = count($strings > 1) ? $strings[1] : '';
    }
    return $table;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LingotekContentEntityStorageException::$entity protected property The entity that could not be saved.
LingotekContentEntityStorageException::$table protected property
LingotekContentEntityStorageException::extractTableFromPreviousExceptionMessage protected function Extract the problematic table from the previous exception message.
LingotekContentEntityStorageException::getTable public function Gets the table name that failed to update.
LingotekContentEntityStorageException::__construct public function