Browse Source

Use \t rather than TranslatableMarkup, and codesniffer compliance.

pull/2/head
Nigel Banks 3 years ago
parent
commit
c84d9203d3
  1. 6
      dgi_fixity.install
  2. 11
      dgi_fixity.module
  3. 6
      dgi_fixity.views.inc
  4. 8
      src/Access/FixityCheckRevisionAccessCheck.php
  5. 9
      src/Entity/FixityCheck.php
  6. 23
      src/FixityCheckBatchCheck.php
  7. 11
      src/FixityCheckBatchGenerate.php

6
dgi_fixity.install

@ -5,8 +5,6 @@
* Install hook implementations. * Install hook implementations.
*/ */
use Drupal\Core\StringTranslation\TranslatableMarkup;
/** /**
* Implements hook_requirements(). * Implements hook_requirements().
*/ */
@ -26,8 +24,8 @@ function dgi_fixity_requirements($phase) {
$failed = $stats['failed'] > 0; $failed = $stats['failed'] > 0;
$out_to_date = $stats['periodic']['expired'] > 0; $out_to_date = $stats['periodic']['expired'] > 0;
$requirements['dgi_fixity'] = [ $requirements['dgi_fixity'] = [
'title' => new TranslatableMarkup('Fixity'), 'title' => \t('Fixity'),
'value' => $failed ? new TranslatableMarkup('Error') : ($out_to_date ? new TranslatableMarkup('Out of date') : new TranslatableMarkup('Up to date')), 'value' => $failed ? \t('Error') : ($out_to_date ? \t('Out of date') : \t('Up to date')),
'description' => \Drupal::service('renderer')->render($elements), 'description' => \Drupal::service('renderer')->render($elements),
'severity' => $failed ? REQUIREMENT_ERROR : ($out_to_date ? REQUIREMENT_WARNING : REQUIREMENT_OK), 'severity' => $failed ? REQUIREMENT_ERROR : ($out_to_date ? REQUIREMENT_WARNING : REQUIREMENT_OK),
]; ];

11
dgi_fixity.module

@ -12,7 +12,6 @@ use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Mail\MailFormatHelper; use Drupal\Core\Mail\MailFormatHelper;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\dgi_fixity\EntityTypeInfo; use Drupal\dgi_fixity\EntityTypeInfo;
use Drupal\dgi_fixity\Form\SettingsForm; use Drupal\dgi_fixity\Form\SettingsForm;
@ -26,7 +25,7 @@ function dgi_fixity_modules_installed($modules) {
// This section is only entered when this module is installed prior to either // This section is only entered when this module is installed prior to either
// of these optional dependencies installation. // of these optional dependencies installation.
// In particular the optional view: // In particular the optional view:
// - `views.view.fixity_check_source_islandora` // - views.view.fixity_check_source_islandora
// Which requires the following fields: // Which requires the following fields:
// - field.storage.media.field_media_use // - field.storage.media.field_media_use
// - field.storage.taxonomy_term.field_external_uri // - field.storage.taxonomy_term.field_external_uri
@ -81,13 +80,13 @@ function dgi_fixity_mail($key, &$message, $params) {
} }
$now = \Drupal::time()->getRequestTime(); $now = \Drupal::time()->getRequestTime();
$subject = (new TranslatableMarkup('Fixity Check Report - @now', ['@now' => date(DATE_RFC7231, $now)]))->render(); $subject = \t('Fixity Check Report - @now', ['@now' => date(DATE_RFC7231, $now)])->render();
$body = $fixity->summary($stats); $body = $fixity->summary($stats);
if ($stats['failed'] !== 0) { if ($stats['failed'] !== 0) {
$body[] = (new TranslatableMarkup( $body[] = \t(
'There are failed checks which require your attention please review the current state of checks <a href="@site">here</a>.', 'There are failed checks which require your attention please review the current state of checks <a href="@site">here</a>.',
['@site' => Url::fromRoute('entity.fixity_check.collection', [], ['absolute' => TRUE])->toString()] ['@site' => Url::fromRoute('entity.fixity_check.collection', [], ['absolute' => TRUE])->toString()]
))->render(); )->render();
} }
$message['subject'] = $subject; $message['subject'] = $subject;
@ -206,7 +205,7 @@ function dgi_fixity_help($route_name, RouteMatchInterface $route_match) {
case 'help.page.dgi_fixity': case 'help.page.dgi_fixity':
case 'dgi_fixity.settings': case 'dgi_fixity.settings':
$output = array_fill(0, 2, ['#type' => 'html_tag', '#tag' => 'p']); $output = array_fill(0, 2, ['#type' => 'html_tag', '#tag' => 'p']);
$output[0]['#value'] = new TranslatableMarkup( $output[0]['#value'] = \t(
'The Fixity module validates selected files by generating hashes and comparing it against stored values produced by the <a href="@file_hash">File Hash module</a> for selected files uploaded to the site.', 'The Fixity module validates selected files by generating hashes and comparing it against stored values produced by the <a href="@file_hash">File Hash module</a> for selected files uploaded to the site.',
['@file_hash' => URL::fromRoute('help.page', ['name' => 'filehash'])->toString()], ['@file_hash' => URL::fromRoute('help.page', ['name' => 'filehash'])->toString()],
); );

6
dgi_fixity.views.inc

@ -5,8 +5,6 @@
* Provide views data for file.module. * Provide views data for file.module.
*/ */
use Drupal\Core\StringTranslation\TranslatableMarkup;
/** /**
* Implements hook_views_data_alter(). * Implements hook_views_data_alter().
*/ */
@ -32,14 +30,14 @@ function dgi_fixity_views_data_alter(&$data) {
$data['file_managed'][$pseudo_field_name] = [ $data['file_managed'][$pseudo_field_name] = [
'real field' => $field_type->getName(), 'real field' => $field_type->getName(),
'relationship' => [ 'relationship' => [
'title' => new TranslatableMarkup('@entity using @field', 'title' => \t('@entity using @field',
[ [
'@entity' => $entity_type->getLabel(), '@entity' => $entity_type->getLabel(),
'@field' => $field_type->getLabel(), '@field' => $field_type->getLabel(),
], ],
), ),
'label' => $group, 'label' => $group,
'help' => new TranslatableMarkup('Relate each @entity with a @field set to the file.', 'help' => \t('Relate each @entity with a @field set to the file.',
[ [
'@entity' => $entity_type->getLabel(), '@entity' => $entity_type->getLabel(),
'@field' => $field_type->getLabel(), '@field' => $field_type->getLabel(),

8
src/Access/FixityCheckRevisionAccessCheck.php

@ -97,8 +97,8 @@ class FixityCheckRevisionAccessCheck implements AccessInterface {
]; ];
if (!$fixity_check || !isset($map[$op])) { if (!$fixity_check || !isset($map[$op])) {
// If there was no fixity_check to check against, or the $op was not one of the // If there was no fixity_check to check against, or the $op was not one
// supported ones, we return access denied. // of the supported ones, we return access denied.
return FALSE; return FALSE;
} }
@ -122,8 +122,8 @@ class FixityCheckRevisionAccessCheck implements AccessInterface {
} }
else { else {
// First check the access to the default revision and finally, if the // First check the access to the default revision and finally, if the
// fixity_check passed in is not the default revision then check access to // fixity_check passed in is not the default revision then check access
// that, too. // to that, too.
$this->access[$cid] = $this->accessControlHandler->access($this->storage->load($fixity_check->id()), $op, $account) && ($fixity_check->isDefaultRevision() || $this->accessControlHandler->access($fixity_check, $op, $account)); $this->access[$cid] = $this->accessControlHandler->access($this->storage->load($fixity_check->id()), $op, $account) && ($fixity_check->isDefaultRevision() || $this->accessControlHandler->access($fixity_check, $op, $account));
} }
} }

9
src/Entity/FixityCheck.php

@ -8,7 +8,6 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\dgi_fixity\FixityCheckInterface; use Drupal\dgi_fixity\FixityCheckInterface;
use Drupal\file\Entity\File; use Drupal\file\Entity\File;
@ -73,8 +72,8 @@ class FixityCheck extends ContentEntityBase implements FixityCheckInterface {
$fields = parent::baseFieldDefinitions($entity_type); $fields = parent::baseFieldDefinitions($entity_type);
$fields['file'] = BaseFieldDefinition::create('entity_reference') $fields['file'] = BaseFieldDefinition::create('entity_reference')
->setLabel(new TranslatableMarkup('File')) ->setLabel(\t('File'))
->setDescription(new TranslatableMarkup('The file entity the fixity check was performed against.')) ->setDescription(\t('The file entity the fixity check was performed against.'))
->setRequired(TRUE) ->setRequired(TRUE)
->setRevisionable(FALSE) ->setRevisionable(FALSE)
->setTranslatable(FALSE) ->setTranslatable(FALSE)
@ -89,8 +88,8 @@ class FixityCheck extends ContentEntityBase implements FixityCheckInterface {
]); ]);
$fields['state'] = BaseFieldDefinition::create('integer') $fields['state'] = BaseFieldDefinition::create('integer')
->setLabel(new TranslatableMarkup('State')) ->setLabel(\t('State'))
->setDescription(new TranslatableMarkup('A flag indicating the state of the whether the check passed or not.')) ->setDescription(\t('A flag indicating the state of the whether the check passed or not.'))
->setTranslatable(FALSE) ->setTranslatable(FALSE)
->setRevisionable(TRUE) ->setRevisionable(TRUE)
->setInitialValue(static::STATE_UNDEFINED) ->setInitialValue(static::STATE_UNDEFINED)

23
src/FixityCheckBatchCheck.php

@ -4,7 +4,6 @@ namespace Drupal\dgi_fixity;
use Drupal\Core\Batch\BatchBuilder; use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\dgi_fixity\Form\SettingsForm; use Drupal\dgi_fixity\Form\SettingsForm;
/** /**
@ -38,9 +37,9 @@ class FixityCheckBatchCheck {
protected static function buildFixed(array $fids, bool $force, int $batch_size) { protected static function buildFixed(array $fids, bool $force, int $batch_size) {
$builder = new BatchBuilder(); $builder = new BatchBuilder();
return $builder return $builder
->setTitle(new TranslatableMarkup('Performing checks on @count file(s)', ['@count' => count($fids)])) ->setTitle(\t('Performing checks on @count file(s)', ['@count' => count($fids)]))
->setInitMessage(new TranslatableMarkup('Starting')) ->setInitMessage(\t('Starting'))
->setErrorMessage(new TranslatableMarkup('Batch has encountered an error')) ->setErrorMessage(\t('Batch has encountered an error'))
->addOperation([static::class, 'processFixedList'], [ ->addOperation([static::class, 'processFixedList'], [
$fids, $fids,
$force, $force,
@ -66,9 +65,9 @@ class FixityCheckBatchCheck {
); );
} }
return $builder return $builder
->setTitle(new TranslatableMarkup('Enumerating periodic checks from @count Source(s)', ['@count' => count($sources)])) ->setTitle(\t('Enumerating periodic checks from @count Source(s)', ['@count' => count($sources)]))
->setInitMessage(new TranslatableMarkup('Starting')) ->setInitMessage(\t('Starting'))
->setErrorMessage(new TranslatableMarkup('Batch has encountered an error')) ->setErrorMessage(\t('Batch has encountered an error'))
->addOperation([static::class, 'processPeriodic'], [$force, $batch_size]) ->addOperation([static::class, 'processPeriodic'], [$force, $batch_size])
->setFinishCallback([static::class, 'finished']) ->setFinishCallback([static::class, 'finished'])
->toArray(); ->toArray();
@ -101,7 +100,7 @@ class FixityCheckBatchCheck {
} }
$chunk = array_slice($fids, $sandbox['offset'], $batch_size); $chunk = array_slice($fids, $sandbox['offset'], $batch_size);
$end = min($sandbox['total'], $sandbox['offset'] + count($chunk)); $end = min($sandbox['total'], $sandbox['offset'] + count($chunk));
$context['message'] = new TranslatableMarkup('Processing @start to @end of @total', [ $context['message'] = \t('Processing @start to @end of @total', [
'@start' => $sandbox['offset'], '@start' => $sandbox['offset'],
'@end' => $end, '@end' => $end,
'@total' => $sandbox['total'], '@total' => $sandbox['total'],
@ -139,7 +138,7 @@ class FixityCheckBatchCheck {
$check->save(); $check->save();
} }
catch (\Exception $e) { catch (\Exception $e) {
$results['errors'][] = new TranslatableMarkup('Encountered an exception: @exception', [ $results['errors'][] = \t('Encountered an exception: @exception', [
'@exception' => $e, '@exception' => $e,
]); ]);
// In practice exceptions in this case shouldn't arise, but if they do // In practice exceptions in this case shouldn't arise, but if they do
@ -181,7 +180,7 @@ class FixityCheckBatchCheck {
$files = $storage->getPeriodic($sandbox['offset'], $batch_size); $files = $storage->getPeriodic($sandbox['offset'], $batch_size);
$end = min($sandbox['total'], $sandbox['offset'] + count($files)); $end = min($sandbox['total'], $sandbox['offset'] + count($files));
$context['message'] = new TranslatableMarkup('Processing @start to @end', [ $context['message'] = \t('Processing @start to @end', [
'@start' => $sandbox['offset'], '@start' => $sandbox['offset'],
'@end' => $end, '@end' => $end,
]); ]);
@ -229,7 +228,7 @@ class FixityCheckBatchCheck {
} }
catch (\Exception $e) { catch (\Exception $e) {
$results['failed']++; $results['failed']++;
$results['errors'][] = new TranslatableMarkup('Encountered an exception: @exception', [ $results['errors'][] = \t('Encountered an exception: @exception', [
'@exception' => $e, '@exception' => $e,
]); ]);
} }
@ -268,7 +267,7 @@ class FixityCheckBatchCheck {
'@count was skipped.', '@count was skipped.',
'@count were skipped.', '@count were skipped.',
)); ));
$messenger->addStatus(new TranslatableMarkup( $messenger->addStatus(\t(
'@count failed.', ['@count' => $results['failed']] '@count failed.', ['@count' => $results['failed']]
)); ));
$error_count = count($results['errors']); $error_count = count($results['errors']);

11
src/FixityCheckBatchGenerate.php

@ -4,7 +4,6 @@ namespace Drupal\dgi_fixity;
use Drupal\Core\Batch\BatchBuilder; use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\StringTranslation\PluralTranslatableMarkup; use Drupal\Core\StringTranslation\PluralTranslatableMarkup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\dgi_fixity\Form\SettingsForm; use Drupal\dgi_fixity\Form\SettingsForm;
/** /**
@ -25,9 +24,9 @@ class FixityCheckBatchGenerate {
} }
$builder = new BatchBuilder(); $builder = new BatchBuilder();
return $builder return $builder
->setTitle(new TranslatableMarkup('Generating Fixity Checks for previously created files')) ->setTitle(\t('Generating Fixity Checks for previously created files'))
->setInitMessage(new TranslatableMarkup('Starting')) ->setInitMessage(\t('Starting'))
->setErrorMessage(new TranslatableMarkup('Batch has encountered an error')) ->setErrorMessage(\t('Batch has encountered an error'))
->addOperation([static::class, 'generate'], [$batch_size]) ->addOperation([static::class, 'generate'], [$batch_size])
->setFinishCallback([static::class, 'finished']) ->setFinishCallback([static::class, 'finished'])
->toArray(); ->toArray();
@ -63,7 +62,7 @@ class FixityCheckBatchGenerate {
} }
catch (\Exception $e) { catch (\Exception $e) {
$results['failed']++; $results['failed']++;
$results['errors'][] = new TranslatableMarkup('Encountered an exception: @exception', [ $results['errors'][] = \t('Encountered an exception: @exception', [
'@exception' => $e, '@exception' => $e,
]); ]);
} }
@ -99,7 +98,7 @@ class FixityCheckBatchGenerate {
'@count was successful.', '@count was successful.',
'@count were successful.', '@count were successful.',
)); ));
$messenger->addStatus(new TranslatableMarkup( $messenger->addStatus(\t(
'@count failed.', ['@count' => $results['failed']] '@count failed.', ['@count' => $results['failed']]
)); ));
$error_count = count($results['errors']); $error_count = count($results['errors']);

Loading…
Cancel
Save