You are here

class LingotekContentEntityStorageException in Lingotek Translation 3.2.x

Same name and namespace in other branches
  1. 8 src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  2. 8.2 src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  3. 4.0.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  4. 3.0.x src/Exception/LingotekContentEntityStorageException.php \Drupal\lingotek\Exception\LingotekContentEntityStorageException
  5. 3.1.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

An exception for issues when storing content entity translations.

@package Drupal\lingotek\Exception

Hierarchy

Expanded class hierarchy of LingotekContentEntityStorageException

5 files declare their use of LingotekContentEntityStorageException
DownloadAllTranslationsFromLingotekAction.php in src/Plugin/Action/DownloadAllTranslationsFromLingotekAction.php
LingotekContentTranslationService.php in src/LingotekContentTranslationService.php
LingotekEntityController.php in src/Controller/LingotekEntityController.php
LingotekInterfaceTranslationService.php in src/LingotekInterfaceTranslationService.php
LingotekManagementFormBase.php in src/Form/LingotekManagementFormBase.php

File

src/Exception/LingotekContentEntityStorageException.php, line 12

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