Skip to content
Snippets Groups Projects
Commit 546606c7 authored by mark burdett's avatar mark burdett
Browse files

Issue #3383716 by mfb: Remove several translatable strings for each hash algorithm

parent b38225e8
No related branches found
No related tags found
No related merge requests found
......@@ -180,25 +180,20 @@ class FileHash implements FileHashInterface {
*/
public function entityBaseFieldInfo(): array {
$columns = $this->columns();
$labels = $this->labels();
$lengths = $this->lengths();
$descriptions = $this->descriptions();
$names = static::names();
$lengths = static::lengths();
$original = $this->configFactory->get('filehash.settings')->get('original');
if ($original) {
$original_labels = $this->originalLabels();
$original_descriptions = $this->originalDescriptions();
}
$fields = [];
foreach ($columns as $column) {
$fields[$column] = BaseFieldDefinition::create('filehash')
->setLabel($labels[$column])
->setLabel($this->t('@algo hash', ['@algo' => $names[$column]]))
->setSetting('max_length', $lengths[$column])
->setDescription($descriptions[$column]);
->setDescription($this->t('The @algo hash for this file.', ['@algo' => $names[$column]]));
if ($original) {
$fields["original_$column"] = BaseFieldDefinition::create('filehash')
->setLabel($original_labels[$column])
->setLabel($this->t('Original @algo hash', ['@algo' => $names[$column]]))
->setSetting('max_length', $lengths[$column])
->setDescription($original_descriptions[$column]);
->setDescription($this->t('The original @algo hash for this file.', ['@algo' => $names[$column]]));
}
}
return $fields;
......@@ -345,32 +340,6 @@ class FileHash implements FileHashInterface {
return bin2hex(sodium_crypto_generichash_final($state, $length));
}
/**
* {@inheritdoc}
*/
public static function descriptions(): array {
return array_combine(static::KEYS, [
t('The BLAKE2b-128 hash for this file.'),
t('The BLAKE2b-160 hash for this file.'),
t('The BLAKE2b-224 hash for this file.'),
t('The BLAKE2b-256 hash for this file.'),
t('The BLAKE2b-384 hash for this file.'),
t('The BLAKE2b-512 hash for this file.'),
t('The MD5 hash for this file.'),
t('The SHA-1 hash for this file.'),
t('The SHA-224 hash for this file.'),
t('The SHA-256 hash for this file.'),
t('The SHA-384 hash for this file.'),
t('The SHA-512/224 hash for this file.'),
t('The SHA-512/256 hash for this file.'),
t('The SHA-512 hash for this file.'),
t('The SHA3-224 hash for this file.'),
t('The SHA3-256 hash for this file.'),
t('The SHA3-384 hash for this file.'),
t('The SHA3-512 hash for this file.'),
]);
}
/**
* {@inheritdoc}
*/
......@@ -378,32 +347,6 @@ class FileHash implements FileHashInterface {
return array_combine(static::KEYS, static::KEYS);
}
/**
* {@inheritdoc}
*/
public static function labels(): array {
return array_combine(static::KEYS, [
t('BLAKE2b-128 hash'),
t('BLAKE2b-160 hash'),
t('BLAKE2b-224 hash'),
t('BLAKE2b-256 hash'),
t('BLAKE2b-384 hash'),
t('BLAKE2b-512 hash'),
t('MD5 hash'),
t('SHA-1 hash'),
t('SHA-224 hash'),
t('SHA-256 hash'),
t('SHA-384 hash'),
t('SHA-512/224 hash'),
t('SHA-512/256 hash'),
t('SHA-512 hash'),
t('SHA3-224 hash'),
t('SHA3-256 hash'),
t('SHA3-384 hash'),
t('SHA3-512 hash'),
]);
}
/**
* {@inheritdoc}
*/
......@@ -437,56 +380,4 @@ class FileHash implements FileHashInterface {
]);
}
/**
* {@inheritdoc}
*/
public static function originalDescriptions(): array {
return array_combine(static::KEYS, [
t('The original BLAKE2b-128 hash for this file.'),
t('The original BLAKE2b-160 hash for this file.'),
t('The original BLAKE2b-224 hash for this file.'),
t('The original BLAKE2b-256 hash for this file.'),
t('The original BLAKE2b-384 hash for this file.'),
t('The original BLAKE2b-512 hash for this file.'),
t('The original MD5 hash for this file.'),
t('The original SHA-1 hash for this file.'),
t('The original SHA-224 hash for this file.'),
t('The original SHA-256 hash for this file.'),
t('The original SHA-384 hash for this file.'),
t('The original SHA-512/224 hash for this file.'),
t('The original SHA-512/256 hash for this file.'),
t('The original SHA-512 hash for this file.'),
t('The original SHA3-224 hash for this file.'),
t('The original SHA3-256 hash for this file.'),
t('The original SHA3-384 hash for this file.'),
t('The original SHA3-512 hash for this file.'),
]);
}
/**
* {@inheritdoc}
*/
public static function originalLabels(): array {
return array_combine(static::KEYS, [
t('Original BLAKE2b-128 hash'),
t('Original BLAKE2b-160 hash'),
t('Original BLAKE2b-224 hash'),
t('Original BLAKE2b-256 hash'),
t('Original BLAKE2b-384 hash'),
t('Original BLAKE2b-512 hash'),
t('Original MD5 hash'),
t('Original SHA-1 hash'),
t('Original SHA-224 hash'),
t('Original SHA-256 hash'),
t('Original SHA-384 hash'),
t('Original SHA-512/224 hash'),
t('Original SHA-512/256 hash'),
t('Original SHA-512 hash'),
t('Original SHA3-224 hash'),
t('Original SHA3-256 hash'),
t('Original SHA3-384 hash'),
t('Original SHA3-512 hash'),
]);
}
}
......@@ -80,14 +80,6 @@ interface FileHashInterface {
*/
public function validateDedupe(FileInterface $file, bool $strict = FALSE, bool $original = FALSE): array;
/**
* Returns array of field descriptions.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup[]
* Field descriptions.
*/
public static function descriptions(): array;
/**
* Returns array of valid File Hash algorithm identifiers.
*
......@@ -96,14 +88,6 @@ interface FileHashInterface {
*/
public static function keys(): array;
/**
* Returns array of field labels.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup[]
* Field labels.
*/
public static function labels(): array;
/**
* Returns array of hash algorithm hexadecimal output lengths.
*
......@@ -120,20 +104,4 @@ interface FileHashInterface {
*/
public static function names(): array;
/**
* Returns array of field descriptions.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup[]
* Field descriptions.
*/
public static function originalDescriptions(): array;
/**
* Returns array of field labels.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup[]
* Field labels.
*/
public static function originalLabels(): array;
}
......@@ -161,12 +161,12 @@ class FileHashConfigForm extends ConfigFormBase {
if ($value) {
if ($this->deletedFieldsRepository->getFieldDefinitions("file-$column")) {
$form_state->setErrorByName("algos][$column", $this->t('Please run cron first to finish deleting the %label column before enabling it.', [
'%label' => $this->fileHash->labels()[$column],
'%label' => $this->t('@algo hash', ['@algo' => $this->fileHash->names()[$column]]),
]));
}
if ($form_state->getValue('original') && $this->deletedFieldsRepository->getFieldDefinitions("file-original_$column")) {
$form_state->setErrorByName('original', $this->t('Please run cron first to finish deleting the %label column before enabling it.', [
'%label' => $this->fileHash->originalLabels()[$column],
'%label' => $this->t('Original @algo hash', ['@algo' => $this->fileHash->names()[$column]]),
]));
}
}
......
......@@ -91,7 +91,7 @@ class TableFormatter extends DescriptionAwareFileFormatterBase {
$header = [
$this->t('Attachment'),
$this->t('Size'),
$this->fileHash->labels()[$this->getSetting('algo')],
$this->t('@algo hash', ['@algo' => $this->fileHash->names()[$this->getSetting('algo')]]),
];
$rows = [];
foreach ($files as $file) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment