You are here

function tmgmt_smartling_tmgmt_job_delete in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.3 tmgmt_smartling.module \tmgmt_smartling_tmgmt_job_delete()

Implements hook_ENTITY_TYPE_delete().

File

./tmgmt_smartling.module, line 933
Contains

Code

function tmgmt_smartling_tmgmt_job_delete(JobInterface $job) {

  // Delete file from Smartling dashboard when TMGMT job object is
  // being deleted.
  try {

    // Ignore jobs that don't have a smartling translator.
    if (!$job
      ->hasTranslator() || $job
      ->getTranslator()
      ->getPluginId() != 'smartling') {
      return;
    }
    $translator = $job
      ->getTranslator();
    $plugin = $translator
      ->getPlugin();
    $api_wrapper = $plugin
      ->getApiWrapper($translator
      ->getSettings());
    $api_wrapper
      ->createAuditLogRecord($job, NULL, Drupal::currentUser(), CreateRecordParameters::ACTION_TYPE_DELETE);
    $api_wrapper
      ->deleteFile($plugin
      ->getFileName($job));
  } catch (Exception $e) {
    \Drupal::logger('tmgmt_smartling')
      ->error('File deletion failed with the following message: @message', [
      '@message' => $e
        ->getMessage(),
    ]);
  }
}