Commit 69c5fdf4 authored by woprrr's avatar woprrr Committed by chr.fritsch

Issue #2853559 by woprrr: Usage of StringTranslationTrait instead of t() in classes

parent 47a93578
......@@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Utility\Token;
use Drupal\file\FileInterface;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface;
......@@ -21,6 +22,8 @@ use Drupal\Core\File\FileSystemInterface;
*/
class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
use StringTranslationTrait;
/**
* Entity manager service.
*
......@@ -126,7 +129,7 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
// to add it here or else the file upload will fail.
if ($renamed && !empty($extensions)) {
$extensions .= ' txt';
drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $file->getFilename()]));
drupal_set_message($this->t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $file->getFilename()]));
}
// Validate the file.
......@@ -134,7 +137,7 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
if (!empty($errors)) {
$message = [
'error' => [
'#markup' => t('The specified file %name could not be uploaded.', ['%name' => $file->getFilename()]),
'#markup' => $this->t('The specified file %name could not be uploaded.', ['%name' => $file->getFilename()]),
],
'item_list' => [
'#theme' => 'item_list',
......@@ -147,14 +150,14 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
// Prepare destination.
if (!$this->prepareDestination($file, $destination)) {
drupal_set_message(t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination]), 'error');
drupal_set_message($this->t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination]), 'error');
return FALSE;
}
// Move uploaded files from PHP's upload_tmp_dir to destination.
$move_result = file_unmanaged_move($uri, $file->getFileUri());
if (!$move_result) {
drupal_set_message(t('File upload error. Could not move uploaded file.'), 'error');
drupal_set_message($this->t('File upload error. Could not move uploaded file.'), 'error');
$this->logger->notice('Upload error. Could not move uploaded file %file to destination %destination.', ['%file' => $file->getFilename(), '%destination' => $file->getFileUri()]);
return FALSE;
}
......
......@@ -85,7 +85,7 @@ class DropzoneJs extends FormElement {
if (!\Drupal::currentUser()->hasPermission('dropzone upload files')) {
$element['#access'] = FALSE;
drupal_set_message(t("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator"), 'warning');
drupal_set_message(self::t("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator"), 'warning');
}
return $element;
......@@ -161,7 +161,7 @@ class DropzoneJs extends FormElement {
];
}
else {
drupal_set_message(t('There was a problem while processing the file named @name', ['@name' => $name]), 'error');
drupal_set_message(self::t('There was a problem while processing the file named @name', ['@name' => $name]), 'error');
}
}
}
......
......@@ -5,6 +5,7 @@ namespace Drupal\dropzonejs;
use Drupal\Component\Transliteration\TransliterationInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Component\Utility\Unicode;
......@@ -19,6 +20,8 @@ use Drupal\Component\Utility\Unicode;
*/
class UploadHandler implements UploadHandlerInterface {
use StringTranslationTrait;
/**
* The current request.
*
......@@ -116,17 +119,17 @@ class UploadHandler implements UploadHandlerInterface {
switch ($error) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$message = t('The file could not be saved because it exceeds the maximum allowed size for uploads.');
$message = $this->t('The file could not be saved because it exceeds the maximum allowed size for uploads.');
continue;
case UPLOAD_ERR_PARTIAL:
case UPLOAD_ERR_NO_FILE:
$message = t('The file could not be saved because the upload did not complete.');
$message = $this->t('The file could not be saved because the upload did not complete.');
continue;
// Unknown error.
default:
$message = t('The file could not be saved. An unknown error has occurred.');
$message = $this->t('The file could not be saved. An unknown error has occurred.');
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment