From 7f0d54e1ebbd4bece20e5c213a0063d793dcc380 Mon Sep 17 00:00:00 2001 From: Eli Zoller <5439169+elizoller@users.noreply.github.com> Date: Fri, 18 Dec 2020 09:13:07 -0700 Subject: [PATCH] D9 islandora (#809) * update messenger for d9 * fix dependency injection * update info files * stream_for updates for d9 * remove deprecated entity query * replace deprecated functions * use dependency injection for messenger and fix other deprecated functions for d9 * fix deprecations in tests * fix test * phpcs fixes * fix toUrl method * properly use StringTranslationTrait * phpcs fixes and using dependency injection * more deprecations with upgrade_status 3.x version and more phpcs fixes * add defaultTheme per https://www.drupal.org/node/3083055 * replace deprecated context definition method - per https://www.drupal.org/node/2976400 * fix context definitions * remove more deprecations * fix deprecations in tests * codesniffer fixes - dependencies must be prefixed with drupal: and missing variable doc comments * replace more url() -> toUrl() and remove unused variables * more code sniffer fixes * some of these urls are necessary as strings * d9 requires update to flysystem module * update migrate_source_csv * temporarily point crayfish-commons to branch with d9 dependencies * another composer dependency adjustment * point composer to d9 branch of jsonld * remove hook_post_action for d9 * remove hook_post_action as a dependency - this does break multifile media FOR NOW * update migration keys -> ids per https://www.drupal.org/node/3060246 * fix url method * point jsonld back to dev since PR has been merged * wrong branch name * add update hook for change in migration source * update travis.yml for php 7.4 * add doc comment * build on php7.2, 7.3, 7.4 * use this instead of Drupal:: * just php 7.3 and 7.4 * swap back to dev-dev crayfish-commons since PR was merged * perhaps this fixes the config thing * trying to fix config * ugh errant semicolon * missing variable name * maybe it would help if i named the variables consistently * please work... * i can't get the dependency injection of config correct * sad panda * thanks @seth-shaw-unlv for this magical fix * fix dependency injection * putting the config in the AbstractGenerateDerivativeMediaFile class instead * already the system.file config * update test module info file * fix implode ordre of parameters * remove unused use statement * fix geminiclient tests * phpcs fix * check for fedora key in flysystem * check for array not being null * more null checks * try on the downgrade-symfony branch * set fedora url to null if it isn't in the settings * testing the crayfish-commons version fix * fixes for new classes in newer version of guzzlehttp but still needing to support old methods * update phpunit.xml? * transform 1 response from preg_match to a boolean * reorder crayfish-commons version fix * code sniffer fixes * abstract awaying the shared constructor so that phpcpd is happy about less duplicated code * attempt to reduce shared code in the FedoraAdapterTest * remove unused use statement * code sniffer fixes...not sure how i missed these... * remove reliance on branch of crayfish-commons since PR has been merged --- .travis.yml | 4 +- composer.json | 6 +- drush.services.yml | 1 + islandora.info.yml | 53 +++---- islandora.install | 15 ++ islandora.module | 2 +- islandora.routing.yml | 2 - islandora.services.yml | 4 +- .../islandora_audio/islandora_audio.info.yml | 3 +- .../Plugin/Action/GenerateAudioDerivative.php | 6 +- .../GenerateAudioDerivativeTest.php | 6 +- .../islandora_breadcrumbs.info.yml | 3 +- .../migrate_plus.migration.islandora_tags.yml | 2 +- .../islandora_core_feature.info.yml | 45 +++--- .../islandora_iiif/islandora_iiif.info.yml | 3 +- .../src/Form/IslandoraIIIFConfigForm.php | 36 ++++- .../src/Plugin/views/style/IIIFManifest.php | 18 ++- .../islandora_image/islandora_image.info.yml | 3 +- .../Plugin/Action/GenerateImageDerivative.php | 6 +- .../Action/GenerateImageDerivativeFile.php | 4 +- .../GenerateImageDerivativeTest.php | 6 +- .../islandora_text_extraction.info.yml | 3 +- .../islandora_text_extraction.services.yml | 1 - .../src/Controller/MediaSourceController.php | 10 +- .../Plugin/Action/GenerateOCRDerivative.php | 4 +- .../Action/GenerateOCRDerivativeFile.php | 6 +- .../Field/FieldFormatter/OcrTextFormatter.php | 66 +++++++- ...slandora_text_extraction_defaults.info.yml | 21 +-- .../islandora_video/islandora_video.info.yml | 3 +- .../Plugin/Action/GenerateVideoDerivative.php | 6 +- .../GenerateVideoDerivativeTest.php | 6 +- phpunit.xml | 52 +++---- src/Commands/IslandoraCommands.php | 50 ++++-- src/ContextProvider/FileContextProvider.php | 8 +- .../FileRouteContextProvider.php | 8 +- src/ContextProvider/MediaContextProvider.php | 8 +- .../MediaRouteContextProvider.php | 8 +- src/ContextProvider/NodeContextProvider.php | 8 +- src/ContextProvider/TermContextProvider.php | 8 +- .../TermRouteContextProvider.php | 11 +- src/Controller/ManageMembersController.php | 2 +- src/EventGenerator/EmitEvent.php | 51 ++++--- src/EventGenerator/EventGenerator.php | 7 +- src/EventSubscriber/LinkHeaderSubscriber.php | 1 - src/Flysystem/Adapter/FedoraAdapter.php | 19 ++- src/Form/ConfirmDeleteMediaAndFile.php | 1 - src/Form/IslandoraSettingsForm.php | 13 +- src/GeminiLookup.php | 10 +- src/IslandoraUtils.php | 32 ++-- src/MediaSource/MediaSourceService.php | 14 +- .../Action/AbstractGenerateDerivative.php | 142 +++--------------- .../Action/AbstractGenerateDerivativeBase.php | 142 ++++++++++++++++++ .../AbstractGenerateDerivativeMediaFile.php | 140 ++--------------- src/Plugin/Action/EmitFileEvent.php | 15 +- src/Plugin/Action/EmitMediaEvent.php | 12 +- src/Plugin/Condition/FileUsesFilesystem.php | 3 +- src/Plugin/Condition/MediaHasMimetype.php | 4 +- .../Condition/MediaSourceHasMimetype.php | 2 +- src/Plugin/Condition/NodeHadNamespace.php | 4 +- src/Plugin/Condition/NodeHasParent.php | 8 +- src/Plugin/Condition/NodeReferencedByNode.php | 4 +- .../IslandoraImageFormatter.php | 4 +- .../integer_weight_test_views.info.yml | 2 +- .../views.view.test_integer_weight.yml | 1 - tests/src/Functional/AddMediaToNodeTest.php | 16 +- .../src/Functional/ContentEntityTypeTest.php | 5 +- .../src/Functional/DerivativeReactionTest.php | 6 +- tests/src/Functional/EmitNodeEventTest.php | 9 +- tests/src/Functional/EntityBundleTest.php | 2 +- .../FormDisplayAlterReactionTest.php | 2 +- tests/src/Functional/IndexingTest.php | 2 +- .../IslandoraFunctionalTestBase.php | 17 ++- .../IslandoraImageFormatterTest.php | 6 +- .../Functional/IslandoraSettingsFormTest.php | 16 +- .../JsonldSelfReferenceReactionTest.php | 6 +- .../JsonldTypeAlterReactionTest.php | 10 +- tests/src/Functional/LinkHeaderTest.php | 5 +- .../src/Functional/MediaSourceUpdateTest.php | 10 +- .../Functional/ViewModeAlterReactionTest.php | 4 +- .../IntegerWeightTest.php | 7 + tests/src/Kernel/FedoraAdapterTest.php | 68 ++++----- tests/src/Kernel/GeminiClientFactoryTest.php | 5 +- 82 files changed, 716 insertions(+), 628 deletions(-) create mode 100644 src/Plugin/Action/AbstractGenerateDerivativeBase.php diff --git a/.travis.yml b/.travis.yml index fa6315d6..2e01c7d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ sudo: true language: php php: - - 7.2 - 7.3 + - 7.4 env: - TESTSUITE=kernel @@ -11,8 +11,6 @@ env: matrix: fast_finish: true - allow_failures: - - php: 7.3 services: - mysql diff --git a/composer.json b/composer.json index edb5c423..edd148d2 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "drupal/context": "^4.0", + "drupal/context": "^4.0@beta", "drupal/search_api": "~1.8", "islandora/jsonld": "dev-8.x-1.x", "stomp-php/stomp-php": "4.*", @@ -25,9 +25,9 @@ "drupal/features" : "^3.7", "drupal/migrate_plus" : "^5.1", "drupal/migrate_tools" : "^5.0", - "drupal/migrate_source_csv" : "^2.1", + "drupal/migrate_source_csv" : "^3.4", "drupal/token" : "^1.3", - "drupal/flysystem" : "^1.0", + "drupal/flysystem" : "^2.0@alpha", "islandora/crayfish-commons": "dev-dev", "drupal/file_replace": "^1.1" diff --git a/drush.services.yml b/drush.services.yml index fb36bda7..a733ecd2 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -1,5 +1,6 @@ services: islandora.commands: class: \Drupal\islandora\Commands\IslandoraCommands + arguments: ['@entity_type.manager', '@current_user', '@account_switcher'] tags: - { name: drush.command } diff --git a/islandora.info.yml b/islandora.info.yml index f5da3c93..c66c1ba8 100644 --- a/islandora.info.yml +++ b/islandora.info.yml @@ -5,30 +5,31 @@ description: "Islandora Core" type: module package: Islandora core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - - block - - node - - path - - text - - options - - link - - jsonld - - search_api - - jwt - - rest - - filehash - - basic_auth - - context_ui - - action - - eva - - taxonomy - - views_ui - - media - - prepopulate - - features_ui - - migrate_tools - - migrate_source_csv - - content_translation - - flysystem - - token - - file_replace + - drupal:block + - drupal:node + - drupal:path + - drupal:text + - drupal:options + - drupal:link + - drupal:jsonld + - drupal:search_api + - drupal:jwt + - drupal:rest + - drupal:filehash + - drupal:basic_auth + - drupal:context_ui + - drupal:action + - drupal:eva + - drupal:taxonomy + - drupal:views_ui + - drupal:media + - drupal:prepopulate + - drupal:features_ui + - drupal:migrate_tools + - drupal:migrate_source_csv + - drupal:content_translation + - drupal:flysystem + - drupal:token + - drupal:file_replace diff --git a/islandora.install b/islandora.install index 98552efa..bdfd08e6 100644 --- a/islandora.install +++ b/islandora.install @@ -55,3 +55,18 @@ function islandora_update_8003(&$sandbox) { ->schema() ->dropTable('islandora_version_count'); } + +/** + * Renames migration source keys -> ids. + */ +function islandora_update_8004() { + $config_factory = \Drupal::configFactory(); + $config = $config_factory->getEditable('migrate_plus.migration.islandora__tags'); + if ($config) { + if (!$config->get('source.ids')) { + $config->set('source.ids', $config->get('source.keys')); + $config->clear('source.keys'); + $config->save(TRUE); + } + } +} diff --git a/islandora.module b/islandora.module index 6fd1b7b3..22b2ad8a 100644 --- a/islandora.module +++ b/islandora.module @@ -205,7 +205,7 @@ function islandora_file_insert(FileInterface $file) { */ function islandora_file_update(FileInterface $file) { // Exit early if unchanged. - if ($file->filehash['sha1'] == $file->original->filehash['sha1']) { + if ($file->filehash != NULL && $file->original->filehash != NULL && $file->filehash['sha1'] == $file->original->filehash['sha1']) { return; } diff --git a/islandora.routing.yml b/islandora.routing.yml index 7ceacf7b..3bdfdf53 100644 --- a/islandora.routing.yml +++ b/islandora.routing.yml @@ -78,5 +78,3 @@ islandora.confirm_delete_media_and_file: _form: 'Drupal\islandora\Form\ConfirmDeleteMediaAndFile' requirements: _permission: 'administer media+delete any media' - - diff --git a/islandora.services.yml b/islandora.services.yml index b08e0699..0112f41a 100644 --- a/islandora.services.yml +++ b/islandora.services.yml @@ -48,10 +48,10 @@ services: - { name: 'context_provider' } islandora.media_source_service: class: Drupal\islandora\MediaSource\MediaSourceService - arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@entity.query', '@file_system', '@islandora.utils'] + arguments: ['@entity_type.manager', '@current_user', '@language_manager', '@file_system', '@islandora.utils'] islandora.utils: class: Drupal\islandora\IslandoraUtils - arguments: ['@entity_type.manager', '@entity_field.manager', '@entity.query', '@context.manager', '@flysystem_factory', '@language_manager'] + arguments: ['@entity_type.manager', '@entity_field.manager', '@context.manager', '@flysystem_factory', '@language_manager'] islandora.gemini.client: class: Islandora\Crayfish\Commons\Client\GeminiClient factory: ['Drupal\islandora\GeminiClientFactory', create] diff --git a/modules/islandora_audio/islandora_audio.info.yml b/modules/islandora_audio/islandora_audio.info.yml index 237130d3..998590f5 100644 --- a/modules/islandora_audio/islandora_audio.info.yml +++ b/modules/islandora_audio/islandora_audio.info.yml @@ -3,5 +3,6 @@ description: 'Islandora audio derivative actions' type: module package: Islandora core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - - islandora + - drupal:islandora diff --git a/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php b/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php index 41e33d55..904d05e6 100644 --- a/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php +++ b/modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php @@ -34,8 +34,8 @@ class GenerateAudioDerivative extends AbstractGenerateDerivative { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['mimetype']['#description'] = t('Mimetype to convert to (e.g. audio/mpeg, audio/m4a, etc...)'); - $form['args']['#description'] = t('Additional command line parameters for FFMpeg'); + $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. audio/mpeg, audio/m4a, etc...)'); + $form['args']['#description'] = $this->t('Additional command line parameters for FFMpeg'); return $form; } @@ -48,7 +48,7 @@ class GenerateAudioDerivative extends AbstractGenerateDerivative { if ($exploded_mime[0] != 'audio') { $form_state->setErrorByName( 'mimetype', - t('Please enter a audio mimetype (e.g. audio/mpeg, audio/m4a, etc...)') + $this->t('Please enter a audio mimetype (e.g. audio/mpeg, audio/m4a, etc...)') ); } } diff --git a/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php b/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php index 88fb38ce..fc1c6188 100644 --- a/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php +++ b/modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php @@ -40,7 +40,7 @@ class GenerateAudioDerivativeTest extends GenerateDerivativeTestBase { // Create an action to generate a audio derivative. $this->drupalGet('admin/config/system/actions'); $this->getSession()->getPage()->findById("edit-action")->selectOption("Generate a audio derivative"); - $this->getSession()->getPage()->pressButton(t('Create')); + $this->getSession()->getPage()->pressButton($this->t('Create')); $this->assertSession()->statusCodeEquals(200); $this->getSession()->getPage()->fillField('edit-label', "Generate audio test derivative"); @@ -53,7 +53,7 @@ class GenerateAudioDerivativeTest extends GenerateDerivativeTestBase { $this->getSession()->getPage()->fillField('edit-args', "-f mp3"); $this->getSession()->getPage()->fillField('edit-scheme', "public"); $this->getSession()->getPage()->fillField('edit-path', "derp.mov"); - $this->getSession()->getPage()->pressButton(t('Save')); + $this->getSession()->getPage()->pressButton($this->t('Save')); $this->assertSession()->statusCodeEquals(200); // Create a context and add the action as a derivative reaction. @@ -68,7 +68,7 @@ class GenerateAudioDerivativeTest extends GenerateDerivativeTestBase { 'field_media_of[0][target_id]' => 'Test Node', 'field_tags[0][target_id]' => 'Preservation Master', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, t('Save')); + $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); $expected = [ 'source_uri' => 'test_file.txt', diff --git a/modules/islandora_breadcrumbs/islandora_breadcrumbs.info.yml b/modules/islandora_breadcrumbs/islandora_breadcrumbs.info.yml index 085b38bf..56a10bc1 100644 --- a/modules/islandora_breadcrumbs/islandora_breadcrumbs.info.yml +++ b/modules/islandora_breadcrumbs/islandora_breadcrumbs.info.yml @@ -2,6 +2,7 @@ name: 'Islandora Breadcrumbs' type: module description: 'Builds breadcrumbs based on field_member_of relationships.' core: 8.x +core_version_requirement: ^8 || ^9 package: Islandora dependencies: - - islandora + - drupal:islandora diff --git a/modules/islandora_core_feature/config/install/migrate_plus.migration.islandora_tags.yml b/modules/islandora_core_feature/config/install/migrate_plus.migration.islandora_tags.yml index eb4cb827..29a134ea 100644 --- a/modules/islandora_core_feature/config/install/migrate_plus.migration.islandora_tags.yml +++ b/modules/islandora_core_feature/config/install/migrate_plus.migration.islandora_tags.yml @@ -15,7 +15,7 @@ source: plugin: csv path: modules/contrib/islandora/migrate/tags.csv header_row_count: 1 - keys: + ids: - external_uri process: name: name diff --git a/modules/islandora_core_feature/islandora_core_feature.info.yml b/modules/islandora_core_feature/islandora_core_feature.info.yml index eda5da43..bf4f8d7a 100755 --- a/modules/islandora_core_feature/islandora_core_feature.info.yml +++ b/modules/islandora_core_feature/islandora_core_feature.info.yml @@ -2,27 +2,28 @@ name: 'Islandora Core Feature' description: 'Minimum configuration required for Islandora.' type: module core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - - basic_auth - - content_translation - - eva - - features - - field - - file - - filehash - - image - - islandora - - jsonld - - jwt - - language - - link - - media - - migrate_plus - - node - - rest - - serialization - - system - - taxonomy - - user - - views + - drupal:basic_auth + - drupal:content_translation + - drupal:eva + - drupal:features + - drupal:field + - drupal:file + - drupal:filehash + - drupal:image + - drupal:islandora + - drupal:jsonld + - drupal:jwt + - drupal:language + - drupal:link + - drupal:media + - drupal:migrate_plus + - drupal:node + - drupal:rest + - drupal:serialization + - drupal:system + - drupal:taxonomy + - drupal:user + - drupal:views package: Islandora diff --git a/modules/islandora_iiif/islandora_iiif.info.yml b/modules/islandora_iiif/islandora_iiif.info.yml index 06c249e1..0492158a 100644 --- a/modules/islandora_iiif/islandora_iiif.info.yml +++ b/modules/islandora_iiif/islandora_iiif.info.yml @@ -2,6 +2,7 @@ name: 'Islandora IIIF' type: module description: 'IIIF support for Islandora' core: 8.x +core_version_requirement: ^8 || ^9 package: Islandora dependencies: - - islandora + - drupal:islandora diff --git a/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php b/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php index fd349b39..aecb7706 100644 --- a/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php +++ b/modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php @@ -2,16 +2,49 @@ namespace Drupal\islandora_iiif\Form; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Utility\UrlHelper; +use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\ClientException; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Form to configure IslandoraIIIF. */ class IslandoraIIIFConfigForm extends ConfigFormBase { + /** + * The HTTP client to fetch the files with. + * + * @var \GuzzleHttp\ClientInterface + */ + protected $httpClient; + + /** + * IslandoraIIIFConfigForm constructor. + * + * @param \GuzzleHttp\ClientInterface $http_client + * A Guzzle client object. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory service. + */ + public function __construct(ClientInterface $http_client, ConfigFactoryInterface $config_factory) { + parent::__construct($config_factory); + $this->httpClient = $http_client; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('http_client'), + $container->get('config.factory') + ); + } + /** * {@inheritdoc} */ @@ -78,9 +111,8 @@ class IslandoraIIIFConfigForm extends ConfigFormBase { * True if server returns 200 on a HEAD request. */ private function validateIiifUrl($server_uri) { - $client = \Drupal::httpClient(); try { - $result = $client->head($server_uri); + $result = $this->httpClient->head($server_uri); return ($result->getStatusCode() == 200); } catch (ClientException $e) { diff --git a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php index 94b8f6e3..2479c839 100644 --- a/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php +++ b/modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php @@ -4,6 +4,7 @@ namespace Drupal\islandora_iiif\Plugin\views\style; use Drupal\views\Plugin\views\style\StylePluginBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Serializer\SerializerInterface; @@ -74,10 +75,17 @@ class IIIFManifest extends StylePluginBase { */ protected $fileSystem; + /** + * The messenger. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, FileSystem $file_system, Client $http_client) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, SerializerInterface $serializer, Request $request, ImmutableConfig $iiif_config, FileSystem $file_system, Client $http_client, MessengerInterface $messenger) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->serializer = $serializer; @@ -85,6 +93,7 @@ class IIIFManifest extends StylePluginBase { $this->iiifConfig = $iiif_config; $this->fileSystem = $file_system; $this->httpClient = $http_client; + $this->messenger = $messenger; } /** @@ -99,7 +108,8 @@ class IIIFManifest extends StylePluginBase { $container->get('request_stack')->getCurrentRequest(), $container->get('config.factory')->get('islandora_iiif.settings'), $container->get('file_system'), - $container->get('http_client') + $container->get('http_client'), + $container->get('messenger') ); } @@ -176,7 +186,7 @@ class IIIFManifest extends StylePluginBase { foreach ($images as $image) { // Create the IIIF URL for this file // Visiting $iiif_url will resolve to the info.json for the image. - $file_url = $image->entity->url(); + $file_url = $image->entity->createFileUrl(FALSE); $mime_type = $image->entity->getMimeType(); $iiif_url = rtrim($iiif_address, '/') . '/' . urlencode($file_url); @@ -297,7 +307,7 @@ class IIIFManifest extends StylePluginBase { // If no fields to choose from, add an error message indicating such. if (count($field_options) == 0) { - drupal_set_message($this->t('No image or file fields were found in the View. + $this->messenger->addMessage($this->t('No image or file fields were found in the View. You will need to add a field to this View'), 'error'); } diff --git a/modules/islandora_image/islandora_image.info.yml b/modules/islandora_image/islandora_image.info.yml index fe5ef2cf..87076462 100644 --- a/modules/islandora_image/islandora_image.info.yml +++ b/modules/islandora_image/islandora_image.info.yml @@ -2,6 +2,7 @@ name: 'Islandora Image' type: module description: 'Islandora Image derivative actions' core: 8.x +core_version_requirement: ^8 || ^9 package: Islandora dependencies: - - islandora + - drupal:islandora diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php index fa713a71..e81f157b 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php @@ -32,8 +32,8 @@ class GenerateImageDerivative extends AbstractGenerateDerivative { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['mimetype']['#description'] = t('Mimetype to convert to (e.g. image/jpeg, image/png, etc...)'); - $form['args']['#description'] = t('Additional command line arguments for ImageMagick convert (e.g. -resize 50%'); + $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. image/jpeg, image/png, etc...)'); + $form['args']['#description'] = $this->t('Additional command line arguments for ImageMagick convert (e.g. -resize 50%'); return $form; } @@ -48,7 +48,7 @@ class GenerateImageDerivative extends AbstractGenerateDerivative { if ($exploded_mime[0] != "image") { $form_state->setErrorByName( 'mimetype', - t('Please enter an image mimetype (e.g. image/jpeg, image/png, etc...)') + $this->t('Please enter an image mimetype (e.g. image/jpeg, image/png, etc...)') ); } } diff --git a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php index b73e163e..d6f99b58 100644 --- a/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php +++ b/modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php @@ -25,7 +25,7 @@ class GenerateImageDerivativeFile extends AbstractGenerateDerivativeMediaFile { $config['mimetype'] = 'application/xml'; $config['queue'] = 'islandora-connector-houdini'; $config['destination_media_type'] = 'file'; - $config['scheme'] = file_default_scheme(); + $config['scheme'] = $this->config->get('default_scheme'); return $config; } @@ -34,7 +34,7 @@ class GenerateImageDerivativeFile extends AbstractGenerateDerivativeMediaFile { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['mimetype']['#description'] = t('Mimetype to convert to (e.g. application/xml, etc...)'); + $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. application/xml, etc...)'); $form['mimetype']['#value'] = 'image/jpeg'; $form['mimetype']['#type'] = 'hidden'; return $form; diff --git a/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php b/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php index 8c554186..b6e016fc 100644 --- a/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php +++ b/modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php @@ -42,7 +42,7 @@ class GenerateImageDerivativeTest extends GenerateDerivativeTestBase { // Create an action to generate a jpeg thumbnail. $this->drupalGet('admin/config/system/actions'); $this->getSession()->getPage()->findById("edit-action")->selectOption("Generate an image derivative"); - $this->getSession()->getPage()->pressButton(t('Create')); + $this->getSession()->getPage()->pressButton($this->t('Create')); $this->assertSession()->statusCodeEquals(200); $this->getSession()->getPage()->fillField('edit-label', "Generate image test derivative"); @@ -55,7 +55,7 @@ class GenerateImageDerivativeTest extends GenerateDerivativeTestBase { $this->getSession()->getPage()->fillField('edit-args', "-thumbnail 20x20"); $this->getSession()->getPage()->fillField('edit-scheme', "public"); $this->getSession()->getPage()->fillField('edit-path', "derp.jpeg"); - $this->getSession()->getPage()->pressButton(t('Save')); + $this->getSession()->getPage()->pressButton($this->t('Save')); $this->assertSession()->statusCodeEquals(200); // Create a context and add the action as a derivative reaction. @@ -70,7 +70,7 @@ class GenerateImageDerivativeTest extends GenerateDerivativeTestBase { 'field_media_of[0][target_id]' => 'Test Node', 'field_tags[0][target_id]' => 'Preservation Master', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, t('Save')); + $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); $expected = [ 'source_uri' => 'test_file.txt', diff --git a/modules/islandora_text_extraction/islandora_text_extraction.info.yml b/modules/islandora_text_extraction/islandora_text_extraction.info.yml index a22048f2..67687f90 100644 --- a/modules/islandora_text_extraction/islandora_text_extraction.info.yml +++ b/modules/islandora_text_extraction/islandora_text_extraction.info.yml @@ -2,6 +2,7 @@ name: 'Islandora Text Extraction' type: module description: 'Islandora 8 module to connect to Hypercube microservice, and to get text from PDF ingest' core: 8.x +core_version_requirement: ^8 || ^9 package: 'Islandora' dependencies: - - islandora + - drupal:islandora diff --git a/modules/islandora_text_extraction/islandora_text_extraction.services.yml b/modules/islandora_text_extraction/islandora_text_extraction.services.yml index 72d63bdf..7f37b599 100644 --- a/modules/islandora_text_extraction/islandora_text_extraction.services.yml +++ b/modules/islandora_text_extraction/islandora_text_extraction.services.yml @@ -5,4 +5,3 @@ services: islandora_text_extraction.search_reindexer: class: Drupal\islandora_text_extraction\SearchReindexer arguments: ['@islandora.utils', '@logger.channel.islandora_text_extraction'] - diff --git a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php index 576f2a43..14c36ebd 100644 --- a/modules/islandora_text_extraction/src/Controller/MediaSourceController.php +++ b/modules/islandora_text_extraction/src/Controller/MediaSourceController.php @@ -3,11 +3,13 @@ namespace Drupal\islandora_text_extraction\Controller; use Drupal\Core\Controller\ControllerBase; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\File\FileSystem; +use Drupal\Core\File\FileSystemInterface; use Drupal\media\Entity\Media; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Drupal\Core\File\FileSystem; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * Controller for Media Source. @@ -93,10 +95,10 @@ class MediaSourceController extends ControllerBase { if ($contents) { $directory = $this->fileSystem->dirname($content_location); - if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { + if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable"); } - $file = file_save_data($contents, $content_location, FILE_EXISTS_REPLACE); + $file = file_save_data($contents, $content_location, FileSystemInterface::EXISTS_REPLACE); if ($media->hasField($destination_field)) { $media->{$destination_field}->setValue([ 'target_id' => $file->id(), diff --git a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php index 752d261b..745c5772 100644 --- a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php +++ b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php @@ -33,7 +33,7 @@ class GenerateOCRDerivative extends AbstractGenerateDerivative { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['mimetype']['#description'] = t('Mimetype to convert to (e.g. application/xml, etc...)'); + $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. application/xml, etc...)'); $form['mimetype']['#value'] = 'text/plain'; $form['mimetype']['#type'] = 'textfield'; @@ -50,7 +50,7 @@ class GenerateOCRDerivative extends AbstractGenerateDerivative { if ($exploded_mime[0] != 'text') { $form_state->setErrorByName( 'mimetype', - t('Please enter file mimetype (e.g. text/plain.)') + $this->t('Please enter file mimetype (e.g. text/plain.)') ); } } diff --git a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php index 2c5cbcce..3b5e8498 100644 --- a/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php +++ b/modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php @@ -27,7 +27,7 @@ class GenerateOCRDerivativeFile extends AbstractGenerateDerivativeMediaFile { $config['mimetype'] = 'application/xml'; $config['queue'] = 'islandora-connector-ocr'; $config['destination_media_type'] = 'file'; - $config['scheme'] = file_default_scheme(); + $config['scheme'] = $this->config->get('default_scheme'); $config['destination_text_field_name'] = ''; return $config; } @@ -40,7 +40,7 @@ class GenerateOCRDerivativeFile extends AbstractGenerateDerivativeMediaFile { $file_fields = $map['media']; $field_options = array_combine(array_keys($file_fields), array_keys($file_fields)); $form = parent::buildConfigurationForm($form, $form_state); - $form['mimetype']['#description'] = t('Mimetype to convert to (e.g. application/xml, etc...)'); + $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. application/xml, etc...)'); $form['mimetype']['#value'] = 'text/plain'; $form['mimetype']['#type'] = 'hidden'; $position = array_search('destination_field_name', array_keys($form)); @@ -70,7 +70,7 @@ class GenerateOCRDerivativeFile extends AbstractGenerateDerivativeMediaFile { if ($exploded_mime[0] != 'text') { $form_state->setErrorByName( 'mimetype', - t('Please enter file mimetype (e.g. application/xml.)') + $this->t('Please enter file mimetype (e.g. application/xml.)') ); } } diff --git a/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php b/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php index d21363fc..2e066943 100644 --- a/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php +++ b/modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php @@ -2,11 +2,16 @@ namespace Drupal\islandora_text_extraction\Plugin\Field\FieldFormatter; +use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\file\Entity\File; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\Render\RendererInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'ocr_txt_formatter' formatter. @@ -17,7 +22,62 @@ use Drupal\file\Entity\File; * field_types = {"file"} * ) */ -class OcrTextFormatter extends FormatterBase { +class OcrTextFormatter extends FormatterBase implements ContainerFactoryPluginInterface { + + /** + * The entity type manager. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * OcrTextFormatter constructor. + * + * @param string $plugin_id + * The plugin_id for the formatter. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The definition of the field to which the formatter is associated. + * @param array $settings + * The formatter settings. + * @param string $label + * The formatter label display setting. + * @param string $view_mode + * The view mode. + * @param array $third_party_settings + * Third party settings. + * @param \Drupal\Core\Render\RendererInterface $renderer + * The renderer. + * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory + * The factory for configuration objects. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, RendererInterface $renderer, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings, $renderer, $config_factory); + + $this->entityTypeManager = $entity_type_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('renderer'), + $container->get('config.factory'), + $container->get('entity_type.manager') + ); + } /** * {@inheritdoc} @@ -70,7 +130,7 @@ class OcrTextFormatter extends FormatterBase { */ protected function viewValue(FieldItemInterface $item) { $fileItem = $item->getValue(); - $file = File::load($fileItem['target_id']); + $file = $this->entityTypeManager->getStorage('file')->load($fileItem['target_id']); $contents = file_get_contents($file->getFileUri()); if (mb_detect_encoding($contents) != 'UTF-8') { $contents = utf8_encode($contents); diff --git a/modules/islandora_text_extraction_defaults/islandora_text_extraction_defaults.info.yml b/modules/islandora_text_extraction_defaults/islandora_text_extraction_defaults.info.yml index 5081bb27..5b9aa14f 100644 --- a/modules/islandora_text_extraction_defaults/islandora_text_extraction_defaults.info.yml +++ b/modules/islandora_text_extraction_defaults/islandora_text_extraction_defaults.info.yml @@ -2,15 +2,16 @@ name: 'Islandora Text Extraction Defaults' type: module description: 'Default config for the Islandora Text Extraction module.' core: 8.x +core_version_requirement: ^8 || ^9 package: Islandora dependencies: - - field - - file - - islandora_core_feature - - islandora_text_extraction - - language - - media - - path - - system - - text - - user + - drupal:field + - drupal:file + - drupal:islandora_core_feature + - drupal:islandora_text_extraction + - drupal:language + - drupal:media + - drupal:path + - drupal:system + - drupal:text + - drupal:user diff --git a/modules/islandora_video/islandora_video.info.yml b/modules/islandora_video/islandora_video.info.yml index bccc6c80..48eb82f2 100644 --- a/modules/islandora_video/islandora_video.info.yml +++ b/modules/islandora_video/islandora_video.info.yml @@ -3,5 +3,6 @@ description: 'Islandora video derivative actions' type: module package: Islandora core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - - islandora + - drupal:islandora diff --git a/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php b/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php index c28ffdc0..7c861992 100644 --- a/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php +++ b/modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php @@ -33,8 +33,8 @@ class GenerateVideoDerivative extends AbstractGenerateDerivative { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); - $form['mimetype']['#description'] = t('Mimetype to convert to (e.g. video/mp4, video/quicktime, etc...)'); - $form['args']['#description'] = t('Additional command line parameters for FFMpeg'); + $form['mimetype']['#description'] = $this->t('Mimetype to convert to (e.g. video/mp4, video/quicktime, etc...)'); + $form['args']['#description'] = $this->t('Additional command line parameters for FFMpeg'); return $form; } @@ -47,7 +47,7 @@ class GenerateVideoDerivative extends AbstractGenerateDerivative { if ($exploded_mime[0] != 'video') { $form_state->setErrorByName( 'mimetype', - t('Please enter a video mimetype (e.g. video/mp4, video/quicktime, etc...)') + $this->t('Please enter a video mimetype (e.g. video/mp4, video/quicktime, etc...)') ); } } diff --git a/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php b/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php index b7b5adc3..8714a2f1 100644 --- a/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php +++ b/modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php @@ -37,7 +37,7 @@ class GenerateVideoDerivativeTest extends GenerateDerivativeTestBase { // Create an action to generate a jpeg thumbnail. $this->drupalGet('admin/config/system/actions'); $this->getSession()->getPage()->findById("edit-action")->selectOption("Generate a video derivative"); - $this->getSession()->getPage()->pressButton(t('Create')); + $this->getSession()->getPage()->pressButton($this->t('Create')); $this->assertSession()->statusCodeEquals(200); $this->getSession()->getPage()->fillField('edit-label', "Generate video test derivative"); @@ -50,7 +50,7 @@ class GenerateVideoDerivativeTest extends GenerateDerivativeTestBase { $this->getSession()->getPage()->fillField('edit-args', "-f mp4"); $this->getSession()->getPage()->fillField('edit-scheme', "public"); $this->getSession()->getPage()->fillField('edit-path', "derp.mov"); - $this->getSession()->getPage()->pressButton(t('Save')); + $this->getSession()->getPage()->pressButton($this->t('Save')); $this->assertSession()->statusCodeEquals(200); // Create a context and add the action as a derivative reaction. @@ -65,7 +65,7 @@ class GenerateVideoDerivativeTest extends GenerateDerivativeTestBase { 'field_media_of[0][target_id]' => 'Test Node', 'field_tags[0][target_id]' => 'Preservation Master', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, t('Save')); + $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); $expected = [ 'source_uri' => 'test_file.txt', diff --git a/phpunit.xml b/phpunit.xml index c9f04458..a4091781 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,15 +1,27 @@ - - + + + + ./includes + ./lib + ./modules + ../modules + ../sites + + + ./modules/*/src/Tests + ./modules/*/tests + ../modules/*/src/Tests + ../modules/*/tests + ../modules/*/*/src/Tests + ../modules/*/*/tests + + @@ -29,13 +41,13 @@ - + - + - + - + @@ -63,24 +75,4 @@ - - - ./includes - ./lib - - ./modules - - ./modules/*/src/Tests - ./modules/*/tests - - ../modules - - ../modules/*/src/Tests - ../modules/*/tests - ../modules/*/*/src/Tests - ../modules/*/*/tests - - ../sites - - diff --git a/src/Commands/IslandoraCommands.php b/src/Commands/IslandoraCommands.php index c13f3623..5209546c 100644 --- a/src/Commands/IslandoraCommands.php +++ b/src/Commands/IslandoraCommands.php @@ -3,8 +3,10 @@ namespace Drupal\islandora\Commands; use Consolidation\AnnotatedCommand\CommandData; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Session\AccountProxy; +use Drupal\Core\Session\AccountSwitcherInterface; use Drupal\Core\Session\UserSession; -use Drupal\user\Entity\User; use Drush\Commands\DrushCommands; /** @@ -13,6 +15,35 @@ use Drush\Commands\DrushCommands; * ... because the --user option was removed from drush 9. */ class IslandoraCommands extends DrushCommands { + /** + * Entity type manager object. + * + * @var \Drupal\Core\Entity\EntityTypeManagerInterface + */ + protected $entityTypeManager; + + /** + * Drupal\Core\Session\AccountProxy definition. + * + * @var \Drupal\Core\Session\AccountProxy + */ + protected $currentUser; + + /** + * The account switcher service. + * + * @var \Drupal\Core\Session\AccountSwitcherInterface + */ + protected $accountSwitcher; + + /** + * {@inheritdoc} + */ + public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountProxy $current_user, AccountSwitcherInterface $account_switcher) { + $this->entityTypeManager = $entity_type_manager; + $this->currentUser = $current_user; + $this->accountSwitcher = $account_switcher; + } /** * Add the userid option. @@ -56,7 +87,8 @@ class IslandoraCommands extends DrushCommands { protected function validateUser(CommandData $commandData) { $userid = $commandData->input()->getOption('userid'); if ($userid) { - $account = User::load($userid); + $account = + $this->entityTypeManager->getStorage('user')->load($userid); if (!$account) { throw new \Exception("User ID does not match an existing user."); } @@ -87,18 +119,17 @@ class IslandoraCommands extends DrushCommands { protected function switchUser(CommandData $commandData) { $userid = $commandData->input()->getOption('userid'); if ($userid) { - $account = User::load($userid); - $accountSwitcher = \Drupal::service('account_switcher'); + $account = $this->entityTypeManager->getStorage('user')->load($userid); $userSession = new UserSession([ 'uid' => $account->id(), - 'name' => $account->getUsername(), + 'name' => $account->getDisplayName(), 'roles' => $account->getRoles(), ]); - $accountSwitcher->switchTo($userSession); + $this->accountSwitcher->switchTo($userSession); $this->logger()->notice( dt( 'Now acting as user ID @id', - ['@id' => \Drupal::currentUser()->id()] + ['@id' => $this->currentUser->id()] ) ); } @@ -127,12 +158,11 @@ class IslandoraCommands extends DrushCommands { */ protected function switchUserBack(CommandData $commandData) { if ($commandData->input()->getOption('userid')) { - $accountSwitcher = \Drupal::service('account_switcher'); $this->logger()->notice(dt( 'Switching back from user @uid.', - ['@uid' => \Drupal::currentUser()->id()] + ['@uid' => $this->currentUser->id()] )); - $accountSwitcher->switchBack(); + $this->accountSwitcher->switchBack(); } } diff --git a/src/ContextProvider/FileContextProvider.php b/src/ContextProvider/FileContextProvider.php index 9b6e5cc1..b7645e2c 100644 --- a/src/ContextProvider/FileContextProvider.php +++ b/src/ContextProvider/FileContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\file\FileInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class FileContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:file', NULL, FALSE); - $context = new Context($context_definition, $this->file); + $context = EntityContext::fromEntity($this->file); return ['@islandora.file_route_context_provider:file' => $context]; } @@ -45,7 +43,7 @@ class FileContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:file', $this->t('File from entity hook'))); + $context = EntityContext::fromEntityTypeId('file', $this->t('File from entity hook')); return ['@islandora.file_route_context_provider:file' => $context]; } diff --git a/src/ContextProvider/FileRouteContextProvider.php b/src/ContextProvider/FileRouteContextProvider.php index bd55644f..21323e8d 100644 --- a/src/ContextProvider/FileRouteContextProvider.php +++ b/src/ContextProvider/FileRouteContextProvider.php @@ -4,8 +4,9 @@ namespace Drupal\islandora\ContextProvider; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; +use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -37,7 +38,8 @@ class FileRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:file', NULL, FALSE); + $context_definition = EntityContextDefinition::fromEntityTypeId('file')->setLabel(NULL)->setRequired(FALSE); + $value = NULL; // Hack the file out of the route. @@ -64,7 +66,7 @@ class FileRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:file', $this->t('File from URL'))); + $context = EntityContext::fromEntityTypeId('file', $this->t('File from URL')); return ['file' => $context]; } diff --git a/src/ContextProvider/MediaContextProvider.php b/src/ContextProvider/MediaContextProvider.php index 33270357..038b6ad8 100644 --- a/src/ContextProvider/MediaContextProvider.php +++ b/src/ContextProvider/MediaContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\media\MediaInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class MediaContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:media', NULL, FALSE); - $context = new Context($context_definition, $this->media); + $context = EntityContext::fromEntity($this->media); return ['@islandora.media_route_context_provider:media' => $context]; } @@ -45,7 +43,7 @@ class MediaContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:media', $this->t('Media from entity hook'))); + $context = EntityContext::fromEntityType(\Drupal::entityTypeManager()->getDefinition('media'), $this->t('Media from URL')); return ['@islandora.media_route_context_provider:media' => $context]; } diff --git a/src/ContextProvider/MediaRouteContextProvider.php b/src/ContextProvider/MediaRouteContextProvider.php index 3a731760..4bfb19c7 100644 --- a/src/ContextProvider/MediaRouteContextProvider.php +++ b/src/ContextProvider/MediaRouteContextProvider.php @@ -4,8 +4,9 @@ namespace Drupal\islandora\ContextProvider; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; +use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\media\Entity\Media; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -38,8 +39,7 @@ class MediaRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $result = []; - $context_definition = new ContextDefinition('entity:media', NULL, FALSE); + $context_definition = EntityContextDefinition::fromEntityTypeId('media')->setLabel(NULL)->setRequired(FALSE); $value = NULL; // Hack the media out of the route. @@ -70,7 +70,7 @@ class MediaRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:media', $this->t('Media from URL'))); + $context = EntityContext::fromEntityType(\Drupal::entityTypeManager()->getDefinition('media'), $this->t('Media from URL')); return ['media' => $context]; } diff --git a/src/ContextProvider/NodeContextProvider.php b/src/ContextProvider/NodeContextProvider.php index 637e4888..f044af4b 100644 --- a/src/ContextProvider/NodeContextProvider.php +++ b/src/ContextProvider/NodeContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\node\NodeInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class NodeContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:node', NULL, FALSE); - $context = new Context($context_definition, $this->node); + $context = EntityContext::fromEntity($this->node); return ['@node.node_route_context:node' => $context]; } @@ -45,7 +43,7 @@ class NodeContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:node', $this->t('Node from entity hook'))); + $context = EntityContext::fromEntityTypeId('node', $this->t('Node from entity hook')); return ['@node.node_route_context:node' => $context]; } diff --git a/src/ContextProvider/TermContextProvider.php b/src/ContextProvider/TermContextProvider.php index 7a1e6b79..a7b0274a 100644 --- a/src/ContextProvider/TermContextProvider.php +++ b/src/ContextProvider/TermContextProvider.php @@ -3,9 +3,8 @@ namespace Drupal\islandora\ContextProvider; use Drupal\taxonomy\TermInterface; -use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -36,8 +35,7 @@ class TermContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:taxonomy_term', NULL, FALSE); - $context = new Context($context_definition, $this->term); + $context = EntityContext::fromEntity($this->term); return ['@islandora.taxonomy_term_route_context_provider:taxonomy_term' => $context]; } @@ -45,7 +43,7 @@ class TermContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:taxonomy_term', $this->t('Term from entity hook'))); + $context = EntityContext::fromEntityTypeId('taxonomy_term', $this->t('Term from entity hook')); return ['@islandora.taxonomy_term_route_context_provider:taxonomy_term' => $context]; } diff --git a/src/ContextProvider/TermRouteContextProvider.php b/src/ContextProvider/TermRouteContextProvider.php index 59313523..b54cc226 100644 --- a/src/ContextProvider/TermRouteContextProvider.php +++ b/src/ContextProvider/TermRouteContextProvider.php @@ -4,8 +4,9 @@ namespace Drupal\islandora\ContextProvider; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Plugin\Context\Context; -use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\ContextProviderInterface; +use Drupal\Core\Plugin\Context\EntityContext; +use Drupal\Core\Plugin\Context\EntityContextDefinition; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -24,7 +25,7 @@ class TermRouteContextProvider implements ContextProviderInterface { protected $routeMatch; /** - * Constructs a new FileRouteContextProvider. + * Constructs a new TermRouteContextProvider. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match object. @@ -37,10 +38,10 @@ class TermRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getRuntimeContexts(array $unqualified_context_ids) { - $context_definition = new ContextDefinition('entity:taxonomy_term', NULL, FALSE); + $context_definition = EntityContextDefinition::fromEntityTypeId('taxonomy_term')->setLabel(NULL)->setRequired(FALSE); $value = NULL; - // Hack the file out of the route. + // Hack the taxonomy term out of the route. $route_object = $this->routeMatch->getRouteObject(); if ($route_object) { $route_contexts = $route_object->getOption('parameters'); @@ -64,7 +65,7 @@ class TermRouteContextProvider implements ContextProviderInterface { * {@inheritdoc} */ public function getAvailableContexts() { - $context = new Context(new ContextDefinition('entity:taxonomy_term', $this->t('Term from URL'))); + $context = EntityContext::fromEntityTypeId('taxonomy_term', $this->t('Term from URL')); return ['taxonomy_term' => $context]; } diff --git a/src/Controller/ManageMembersController.php b/src/Controller/ManageMembersController.php index 5b298916..9197811b 100644 --- a/src/Controller/ManageMembersController.php +++ b/src/Controller/ManageMembersController.php @@ -130,7 +130,7 @@ class ManageMembersController extends EntityController { } // Build the message shown when there are no bundles. - $type_label = $type_definition->getLowercaseLabel(); + $type_label = $type_definition->getSingularLabel(); $link_text = $this->t('Add a new @entity_type.', ['@entity_type' => $type_label]); $build['#add_bundle_message'] = $this->t('There is no @entity_type yet. @add_link', [ '@entity_type' => $type_label, diff --git a/src/EventGenerator/EmitEvent.php b/src/EventGenerator/EmitEvent.php index ce69472c..ac03fbf0 100644 --- a/src/EventGenerator/EmitEvent.php +++ b/src/EventGenerator/EmitEvent.php @@ -5,10 +5,12 @@ namespace Drupal\islandora\EventGenerator; use Drupal\Core\Access\AccessResult; use Drupal\Core\Action\ConfigurableActionBase; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\jwt\Authentication\Provider\JwtAuth; use Stomp\Exception\StompException; use Stomp\StatefulStomp; @@ -19,6 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * Configurable action base for actions that publish messages to queues. */ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFactoryPluginInterface { + use StringTranslationTrait; /** * Current user. @@ -55,6 +58,13 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact */ protected $auth; + /** + * The messenger. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + /** * Constructs a EmitEvent action. * @@ -74,6 +84,8 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact * Stomp client. * @param \Drupal\jwt\Authentication\Provider\JwtAuth $auth * JWT Auth client. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger. */ public function __construct( array $configuration, @@ -83,7 +95,8 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact EntityTypeManagerInterface $entity_type_manager, EventGeneratorInterface $event_generator, StatefulStomp $stomp, - JwtAuth $auth + JwtAuth $auth, + MessengerInterface $messenger ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->account = $account; @@ -91,6 +104,7 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact $this->eventGenerator = $event_generator; $this->stomp = $stomp; $this->auth = $auth; + $this->messenger = $messenger; } /** @@ -105,7 +119,8 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact $container->get('entity_type.manager'), $container->get('islandora.eventgenerator'), $container->get('islandora.stomp'), - $container->get('jwt.authentication.jwt') + $container->get('jwt.authentication.jwt'), + $container->get('messenger') ); } @@ -119,10 +134,10 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact if (empty($token)) { // JWT isn't properly configured. Log and notify user. \Drupal::logger('islandora')->error( - t('Error getting JWT token for message. Check JWT Configuration.') + $this->t('Error getting JWT token for message. Check JWT Configuration.') ); - drupal_set_message( - t('Error getting JWT token for message. Check JWT Configuration.'), 'error' + $this->messenger->addMessage( + $this->t('Error getting JWT token for message. Check JWT Configuration.'), 'error' ); return; } @@ -139,10 +154,10 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact catch (\RuntimeException $e) { // Notify the user the event couldn't be generated and abort. \Drupal::logger('islandora')->error( - t('Error generating event: @msg', ['@msg' => $e->getMessage()]) + $this->t('Error generating event: @msg', ['@msg' => $e->getMessage()]) ); - drupal_set_message( - t('Error generating event: @msg', ['@msg' => $e->getMessage()]), + $this->messenger->addMessage( + $this->t('Error generating event: @msg', ['@msg' => $e->getMessage()]), 'error' ); return; @@ -162,8 +177,8 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact ); // Notify user. - drupal_set_message( - t('Error publishing message: @msg', + $this->messenger->addMessage( + $this->t('Error publishing message: @msg', ['@msg' => $e->getMessage()] ), 'error' @@ -194,22 +209,22 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['queue'] = [ '#type' => 'textfield', - '#title' => t('Queue'), + '#title' => $this->t('Queue'), '#default_value' => $this->configuration['queue'], '#required' => TRUE, '#rows' => '8', - '#description' => t('Name of queue to which event is published'), + '#description' => $this->t('Name of queue to which event is published'), ]; $form['event'] = [ '#type' => 'select', - '#title' => t('Event type'), + '#title' => $this->t('Event type'), '#default_value' => $this->configuration['event'], - '#description' => t('Type of event to emit'), + '#description' => $this->t('Type of event to emit'), '#options' => [ - 'Create' => t('Create'), - 'Update' => t('Update'), - 'Delete' => t('Delete'), - 'Generate Derivative' => t('Generate Derivative'), + 'Create' => $this->t('Create'), + 'Update' => $this->t('Update'), + 'Delete' => $this->t('Delete'), + 'Generate Derivative' => $this->t('Generate Derivative'), ], ]; return $form; diff --git a/src/EventGenerator/EventGenerator.php b/src/EventGenerator/EventGenerator.php index 3175c224..6b3a4c5c 100644 --- a/src/EventGenerator/EventGenerator.php +++ b/src/EventGenerator/EventGenerator.php @@ -92,11 +92,12 @@ class EventGenerator implements EventGeneratorInterface { ]; $flysystem_config = Settings::get('flysystem'); - $fedora_url = $flysystem_config['fedora']['config']['root']; - $event["target"] = $fedora_url; + if ($flysystem_config != NULL && array_key_exists('fedora', $flysystem_config)) { + $fedora_url = $flysystem_config['fedora']['config']['root']; + $event["target"] = $fedora_url; + } $entity_type = $entity->getEntityTypeId(); - $event_type = $data["event"]; if ($data["event"] == "Generate Derivative") { $event["type"] = "Activity"; $event["summary"] = $data["event"]; diff --git a/src/EventSubscriber/LinkHeaderSubscriber.php b/src/EventSubscriber/LinkHeaderSubscriber.php index 21311410..ce33ce2e 100644 --- a/src/EventSubscriber/LinkHeaderSubscriber.php +++ b/src/EventSubscriber/LinkHeaderSubscriber.php @@ -263,7 +263,6 @@ abstract class LinkHeaderSubscriber implements EventSubscriberInterface { $current_format = $this->requestStack->getCurrentRequest()->query->get('_format'); $links = []; - $route_name = $this->routeMatch->getRouteName(); if ($rest_resource_config) { $formats = $rest_resource_config->getFormats("GET"); diff --git a/src/Flysystem/Adapter/FedoraAdapter.php b/src/Flysystem/Adapter/FedoraAdapter.php index 0cc95044..6ee588b5 100644 --- a/src/Flysystem/Adapter/FedoraAdapter.php +++ b/src/Flysystem/Adapter/FedoraAdapter.php @@ -7,7 +7,6 @@ use League\Flysystem\AdapterInterface; use League\Flysystem\Adapter\Polyfill\NotSupportingVisibilityTrait; use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait; use League\Flysystem\Config; -use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Response; use GuzzleHttp\Psr7\StreamWrapper; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; @@ -144,7 +143,14 @@ class FedoraAdapter implements AdapterInterface { // NonRDFSource's are considered files. Everything else is a // directory. $type = 'dir'; - $links = Psr7\parse_header($response->getHeader('Link')); + // phpcs:disable + if (class_exists(\GuzzleHttp\Psr7\Header::class)) { + $links = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link')); + } + else { + $links = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link')); + } + // phpcs:enable foreach ($links as $link) { if ($link['rel'] == 'type' && $link[0] == '') { $type = 'file'; @@ -377,7 +383,14 @@ class FedoraAdapter implements AdapterInterface { $return = NULL; if ($response->getStatusCode() == 410) { $return = FALSE; - $link_headers = Psr7\parse_header($response->getHeader('Link')); + // phpcs:disable + if (class_exists(\GuzzleHttp\Psr7\Header::class)) { + $link_headers = \GuzzleHttp\Psr7\Header::parse($response->getHeader('Link')); + } + else { + $link_headers = \GuzzleHttp\Psr7\parse_header($response->getHeader('Link')); + } + // phpcs:enable if ($link_headers) { $tombstones = array_filter($link_headers, function ($o) { return (isset($o['rel']) && $o['rel'] == 'hasTombstone'); diff --git a/src/Form/ConfirmDeleteMediaAndFile.php b/src/Form/ConfirmDeleteMediaAndFile.php index 04b7d458..64c1bff3 100644 --- a/src/Form/ConfirmDeleteMediaAndFile.php +++ b/src/Form/ConfirmDeleteMediaAndFile.php @@ -127,7 +127,6 @@ class ConfirmDeleteMediaAndFile extends DeleteMultipleForm { } // Check for files. $fields = $this->entityFieldManager->getFieldDefinitions('media', $entity->bundle()); - $files = []; foreach ($fields as $field) { $type = $field->getType(); if ($type == 'file' || $type == 'image') { diff --git a/src/Form/IslandoraSettingsForm.php b/src/Form/IslandoraSettingsForm.php index 72ebf11d..6bb868d2 100644 --- a/src/Form/IslandoraSettingsForm.php +++ b/src/Form/IslandoraSettingsForm.php @@ -144,7 +144,7 @@ class IslandoraSettingsForm extends ConfigFormBase { '#title' => $this->t('JWT Expiry'), '#default_value' => $config->get(self::JWT_EXPIRY), '#description' => $this->t('A positive time interval expression. Eg: "60 secs", "2 days", "10 hours", "7 weeks". Be sure you provide the time units (@unit), plurals are accepted.', - ['@unit' => implode(self::TIME_INTERVALS, ", ")] + ['@unit' => implode(", ", self::TIME_INTERVALS)] ), ]; @@ -155,7 +155,12 @@ class IslandoraSettingsForm extends ConfigFormBase { ]; $flysystem_config = Settings::get('flysystem'); - $fedora_url = $flysystem_config['fedora']['config']['root']; + if ($flysystem_config != NULL) { + $fedora_url = $flysystem_config['fedora']['config']['root']; + } + else { + $fedora_url = NULL; + } $form[self::FEDORA_URL] = [ '#type' => 'textfield', @@ -255,11 +260,11 @@ class IslandoraSettingsForm extends ConfigFormBase { ); } else { - if (!preg_match("/\b(" . implode(self::TIME_INTERVALS, "|") . ")s?\b/", $expiry)) { + if (!preg_match("/\b(" . implode("|", self::TIME_INTERVALS) . ")s?\b/", $expiry)) { $form_state->setErrorByName( self::JWT_EXPIRY, $this->t("No time interval found, please include one of (@int). Plurals are also accepted.", - ['@int' => implode(self::TIME_INTERVALS, ", ")] + ['@int' => implode(", ", self::TIME_INTERVALS)] ) ); } diff --git a/src/GeminiLookup.php b/src/GeminiLookup.php index 657b3a4b..a712ddf3 100644 --- a/src/GeminiLookup.php +++ b/src/GeminiLookup.php @@ -5,7 +5,6 @@ namespace Drupal\islandora; use Drupal\Core\Entity\EntityInterface; use Drupal\islandora\MediaSource\MediaSourceService; use Drupal\jwt\Authentication\Provider\JwtAuth; -use GuzzleHttp\Psr7; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Islandora\Crayfish\Commons\Client\GeminiClient; @@ -136,7 +135,14 @@ class GeminiLookup { $urls['fedora'], ['allow_redirects' => FALSE, 'headers' => ['Authorization' => $token]] ); - $links = Psr7\parse_header($head->getHeader("Link")); + // phpcs:disable + if (class_exists(\GuzzleHttp\Psr7\Header::class)) { + $links = \GuzzleHttp\Psr7\Header::parse($head->getHeader('Link')); + } + else { + $links = \GuzzleHttp\Psr7\parse_header($head->getHeader('Link')); + } + //phpcs:enable foreach ($links as $link) { if ($link['rel'] == 'describedby') { return trim($link[0], '<>'); diff --git a/src/IslandoraUtils.php b/src/IslandoraUtils.php index 87f0021b..99088ddd 100644 --- a/src/IslandoraUtils.php +++ b/src/IslandoraUtils.php @@ -8,7 +8,6 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\Query\QueryException; -use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Site\Settings; @@ -48,13 +47,6 @@ class IslandoraUtils { */ protected $entityFieldManager; - /** - * Entity query. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $entityQuery; - /** * Context manager. * @@ -83,8 +75,6 @@ class IslandoraUtils { * The entity type manager. * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager * The entity field manager. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query - * Entity query. * @param \Drupal\context\ContextManager $context_manager * Context manager. * @param \Drupal\flysystem\FlysystemFactory $flysystem_factory @@ -95,14 +85,12 @@ class IslandoraUtils { public function __construct( EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, - QueryFactory $entity_query, ContextManager $context_manager, FlysystemFactory $flysystem_factory, LanguageManagerInterface $language_manager ) { $this->entityTypeManager = $entity_type_manager; $this->entityFieldManager = $entity_field_manager; - $this->entityQuery = $entity_query; $this->contextManager = $context_manager; $this->flysystemFactory = $flysystem_factory; $this->languageManager = $language_manager; @@ -157,7 +145,7 @@ class IslandoraUtils { ->load('media.' . self::MEDIA_OF_FIELD)) { return []; } - $mids = $this->entityQuery->get('media') + $mids = $this->entityTypeManager->getStorage('media')->getQuery() ->condition(self::MEDIA_OF_FIELD, $node->id()) ->execute(); if (empty($mids)) { @@ -217,10 +205,12 @@ class IslandoraUtils { ); // Query for media that reference this file. - $query = $this->entityQuery->get('media', 'OR'); + $query = $this->entityTypeManager->getStorage('media')->getQuery(); + $group = $query->orConditionGroup(); foreach ($conditions as $condition) { - $query->condition($condition, $fid); + $group->condition($condition, $fid); } + $query->condition($group); return $this->entityTypeManager->getStorage('media') ->loadMultiple($query->execute()); @@ -252,7 +242,7 @@ class IslandoraUtils { // Add field_external_uri. $fields[] = self::EXTERNAL_URI_FIELD; - $query = $this->entityQuery->get('taxonomy_term'); + $query = $this->entityTypeManager->getStorage('taxonomy_term')->getQuery(); $orGroup = $query->orConditionGroup(); foreach ($fields as $field) { @@ -504,7 +494,7 @@ class IslandoraUtils { array_walk($term_fields, $remove_entity); array_walk($node_fields, $remove_entity); - $query = $this->entityQuery->get('media'); + $query = $this->entityTypeManager->getStorage('media')->getQuery(); $taxon_condition = $this->getEntityQueryOrCondition($query, $term_fields, $term->id()); $query->condition($taxon_condition); $node_condition = $this->getEntityQueryOrCondition($query, $node_fields, $node->id()); @@ -531,7 +521,7 @@ class IslandoraUtils { * Array of fields. */ public function getReferencingFields($entity_type, $target_type) { - $fields = $this->entityQuery->get('field_storage_config') + $fields = $this->entityTypeManager->getStorage('field_storage_config')->getQuery() ->condition('entity_type', $entity_type) ->condition('settings.target_type', $target_type) ->execute(); @@ -593,11 +583,7 @@ class IslandoraUtils { * The file URL. */ public function getDownloadUrl(FileInterface $file) { - $undefined = $this->languageManager->getLanguage('und'); - return $file->url('canonical', [ - 'absolute' => TRUE, - 'language' => $undefined, - ]); + return $file->createFileUrl(FALSE); } /** diff --git a/src/MediaSource/MediaSourceService.php b/src/MediaSource/MediaSourceService.php index 4909124b..de346115 100644 --- a/src/MediaSource/MediaSourceService.php +++ b/src/MediaSource/MediaSourceService.php @@ -3,7 +3,6 @@ namespace Drupal\islandora\MediaSource; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Entity\Query\QueryFactory; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Session\AccountInterface; @@ -43,13 +42,6 @@ class MediaSourceService { */ protected $languageManager; - /** - * Entity query. - * - * @var \Drupal\Core\Entity\Query\QueryFactory - */ - protected $entityQuery; - /** * File system service. * @@ -73,8 +65,6 @@ class MediaSourceService { * The current user. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * Language manager. - * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query - * Entity query. * @param \Drupal\Core\File\FileSystemInterface $file_system * File system service. * @param \Drupal\islandora\IslandoraUtils $islandora_utils @@ -84,14 +74,12 @@ class MediaSourceService { EntityTypeManagerInterface $entity_type_manager, AccountInterface $account, LanguageManagerInterface $language_manager, - QueryFactory $entity_query, FileSystemInterface $file_system, IslandoraUtils $islandora_utils ) { $this->entityTypeManager = $entity_type_manager; $this->account = $account; $this->languageManager = $language_manager; - $this->entityQuery = $entity_query; $this->fileSystem = $file_system; $this->islandoraUtils = $islandora_utils; } @@ -293,7 +281,7 @@ class MediaSourceService { } $directory = $this->fileSystem->dirname($content_location); - if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { + if (!$this->fileSystem->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { throw new HttpException(500, "The destination directory does not exist, could not be created, or is not writable"); } diff --git a/src/Plugin/Action/AbstractGenerateDerivative.php b/src/Plugin/Action/AbstractGenerateDerivative.php index 7efb4f2c..b22201e1 100644 --- a/src/Plugin/Action/AbstractGenerateDerivative.php +++ b/src/Plugin/Action/AbstractGenerateDerivative.php @@ -3,117 +3,13 @@ namespace Drupal\islandora\Plugin\Action; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; -use Drupal\islandora\IslandoraUtils; -use Drupal\islandora\EventGenerator\EmitEvent; -use Drupal\islandora\EventGenerator\EventGeneratorInterface; -use Drupal\islandora\MediaSource\MediaSourceService; -use Drupal\jwt\Authentication\Provider\JwtAuth; -use Drupal\token\TokenInterface; -use Stomp\StatefulStomp; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Emits a Node event. */ -class AbstractGenerateDerivative extends EmitEvent { - - /** - * Islandora utility functions. - * - * @var \Drupal\islandora\IslandoraUtils - */ - protected $utils; - - /** - * Media source service. - * - * @var \Drupal\islandora\MediaSource\MediaSourceService - */ - protected $mediaSource; - - /** - * Token replacement service. - * - * @var \Drupal\token\TokenInterface - */ - protected $token; - - /** - * Constructs a EmitEvent action. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Session\AccountInterface $account - * Current user. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * Entity type manager. - * @param \Drupal\islandora\EventGenerator\EventGeneratorInterface $event_generator - * EventGenerator service to serialize AS2 events. - * @param \Stomp\StatefulStomp $stomp - * Stomp client. - * @param \Drupal\jwt\Authentication\Provider\JwtAuth $auth - * JWT Auth client. - * @param \Drupal\islandora\IslandoraUtils $utils - * Islandora utility functions. - * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source - * Media source service. - * @param \Drupal\token\TokenInterface $token - * Token service. - */ - public function __construct( - array $configuration, - $plugin_id, - $plugin_definition, - AccountInterface $account, - EntityTypeManagerInterface $entity_type_manager, - EventGeneratorInterface $event_generator, - StatefulStomp $stomp, - JwtAuth $auth, - IslandoraUtils $utils, - MediaSourceService $media_source, - TokenInterface $token - ) { - parent::__construct( - $configuration, - $plugin_id, - $plugin_definition, - $account, - $entity_type_manager, - $event_generator, - $stomp, - $auth - ); - $this->utils = $utils; - $this->mediaSource = $media_source; - $this->token = $token; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('current_user'), - $container->get('entity_type.manager'), - $container->get('islandora.eventgenerator'), - $container->get('islandora.stomp'), - $container->get('jwt.authentication.jwt'), - $container->get('islandora.utils'), - $container->get('islandora.media_source_service'), - $container->get('token') - ); - } +class AbstractGenerateDerivative extends AbstractGenerateDerivativeBase { /** * {@inheritdoc} @@ -127,7 +23,7 @@ class AbstractGenerateDerivative extends EmitEvent { 'mimetype' => '', 'args' => '', 'destination_media_type' => '', - 'scheme' => file_default_scheme(), + 'scheme' => $this->config->get('default_scheme'), 'path' => '[date:custom:Y]-[date:custom:m]/[node:nid].bin', ]; } @@ -205,60 +101,60 @@ class AbstractGenerateDerivative extends EmitEvent { $form['source_term'] = [ '#type' => 'entity_autocomplete', '#target_type' => 'taxonomy_term', - '#title' => t('Source term'), + '#title' => $this->t('Source term'), '#default_value' => $this->utils->getTermForUri($this->configuration['source_term_uri']), '#required' => TRUE, - '#description' => t('Term indicating the source media'), + '#description' => $this->t('Term indicating the source media'), ]; $form['derivative_term'] = [ '#type' => 'entity_autocomplete', '#target_type' => 'taxonomy_term', - '#title' => t('Derivative term'), + '#title' => $this->t('Derivative term'), '#default_value' => $this->utils->getTermForUri($this->configuration['derivative_term_uri']), '#required' => TRUE, - '#description' => t('Term indicating the derivative media'), + '#description' => $this->t('Term indicating the derivative media'), ]; $form['destination_media_type'] = [ '#type' => 'entity_autocomplete', '#target_type' => 'media_type', - '#title' => t('Derivative media type'), + '#title' => $this->t('Derivative media type'), '#default_value' => $this->getEntityById($this->configuration['destination_media_type']), '#required' => TRUE, - '#description' => t('The Drupal media type to create with this derivative, can be different than the source'), + '#description' => $this->t('The Drupal media type to create with this derivative, can be different than the source'), ]; $form['mimetype'] = [ '#type' => 'textfield', - '#title' => t('Mimetype'), + '#title' => $this->t('Mimetype'), '#default_value' => $this->configuration['mimetype'], '#required' => TRUE, '#rows' => '8', - '#description' => t('Mimetype to convert to (e.g. image/jpeg, video/mp4, etc...)'), + '#description' => $this->t('Mimetype to convert to (e.g. image/jpeg, video/mp4, etc...)'), ]; $form['args'] = [ '#type' => 'textfield', - '#title' => t('Additional arguments'), + '#title' => $this->t('Additional arguments'), '#default_value' => $this->configuration['args'], '#rows' => '8', - '#description' => t('Additional command line arguments'), + '#description' => $this->t('Additional command line arguments'), ]; $form['scheme'] = [ '#type' => 'select', - '#title' => t('File system'), + '#title' => $this->t('File system'), '#options' => $scheme_options, '#default_value' => $this->configuration['scheme'], '#required' => TRUE, ]; $form['path'] = [ '#type' => 'textfield', - '#title' => t('File path'), + '#title' => $this->t('File path'), '#default_value' => $this->configuration['path'], - '#description' => t('Path within the upload destination where files will be stored. Includes the filename and optional extension.'), + '#description' => $this->t('Path within the upload destination where files will be stored. Includes the filename and optional extension.'), ]; $form['queue'] = [ '#type' => 'textfield', - '#title' => t('Queue name'), + '#title' => $this->t('Queue name'), '#default_value' => $this->configuration['queue'], - '#description' => t('Queue name to send along to help routing events, CHANGE WITH CARE. Defaults to :queue', [ + '#description' => $this->t('Queue name to send along to help routing events, CHANGE WITH CARE. Defaults to :queue', [ ':queue' => $this->defaultConfiguration()['queue'], ]), ]; @@ -276,14 +172,14 @@ class AbstractGenerateDerivative extends EmitEvent { if (count($exploded_mime) != 2) { $form_state->setErrorByName( 'mimetype', - t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') + $this->t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') ); } if (empty($exploded_mime[1])) { $form_state->setErrorByName( 'mimetype', - t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') + $this->t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') ); } } diff --git a/src/Plugin/Action/AbstractGenerateDerivativeBase.php b/src/Plugin/Action/AbstractGenerateDerivativeBase.php new file mode 100644 index 00000000..711b9a17 --- /dev/null +++ b/src/Plugin/Action/AbstractGenerateDerivativeBase.php @@ -0,0 +1,142 @@ +utils = $utils; + $this->mediaSource = $media_source; + $this->token = $token; + $this->messenger = $messenger; + $this->config = $config->get('system.file'); + parent::__construct( + $configuration, + $plugin_id, + $plugin_definition, + $account, + $entity_type_manager, + $event_generator, + $stomp, + $auth, + $messenger + ); + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('current_user'), + $container->get('entity_type.manager'), + $container->get('islandora.eventgenerator'), + $container->get('islandora.stomp'), + $container->get('jwt.authentication.jwt'), + $container->get('islandora.utils'), + $container->get('islandora.media_source_service'), + $container->get('token'), + $container->get('messenger'), + $container->get('config.factory') + ); + } + +} diff --git a/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php b/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php index 151af915..84c064e9 100644 --- a/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php +++ b/src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php @@ -2,20 +2,9 @@ namespace Drupal\islandora\Plugin\Action; -use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\Core\Url; -use Drupal\islandora\EventGenerator\EmitEvent; -use Drupal\islandora\EventGenerator\EventGeneratorInterface; -use Drupal\islandora\IslandoraUtils; -use Drupal\islandora\MediaSource\MediaSourceService; -use Drupal\jwt\Authentication\Provider\JwtAuth; -use Drupal\token\Token; -use Stomp\StatefulStomp; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Emits a Node for generating derivatives event. @@ -26,113 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * type = "media" * ) */ -class AbstractGenerateDerivativeMediaFile extends EmitEvent { - - /** - * Islandora utility functions. - * - * @var \Drupal\islandora\IslandoraUtils - */ - protected $utils; - - /** - * Media source service. - * - * @var \Drupal\islandora\MediaSource\MediaSourceService - */ - protected $mediaSource; - - /** - * Token replacement service. - * - * @var \Drupal\token\Token - */ - protected $token; - - /** - * The entity field manager. - * - * @var \Drupal\Core\Entity\EntityFieldManager - */ - protected $entityFieldManager; - - /** - * Constructs a EmitEvent action. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Session\AccountInterface $account - * Current user. - * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager - * Entity type manager. - * @param \Drupal\islandora\EventGenerator\EventGeneratorInterface $event_generator - * EventGenerator service to serialize AS2 events. - * @param \Stomp\StatefulStomp $stomp - * Stomp client. - * @param \Drupal\jwt\Authentication\Provider\JwtAuth $auth - * JWT Auth client. - * @param \Drupal\islandora\IslandoraUtils $utils - * Islandora utility functions. - * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source - * Media source service. - * @param \Drupal\token\Token $token - * Token service. - * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager - * Field Manager service. - */ - public function __construct( - array $configuration, - $plugin_id, - $plugin_definition, - AccountInterface $account, - EntityTypeManager $entity_type_manager, - EventGeneratorInterface $event_generator, - StatefulStomp $stomp, - JwtAuth $auth, - IslandoraUtils $utils, - MediaSourceService $media_source, - Token $token, - EntityFieldManagerInterface $entity_field_manager - ) { - parent::__construct( - $configuration, - $plugin_id, - $plugin_definition, - $account, - $entity_type_manager, - $event_generator, - $stomp, - $auth - ); - $this->utils = $utils; - $this->mediaSource = $media_source; - $this->token = $token; - $this->entityFieldManager = $entity_field_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('current_user'), - $container->get('entity_type.manager'), - $container->get('islandora.eventgenerator'), - $container->get('islandora.stomp'), - $container->get('jwt.authentication.jwt'), - $container->get('islandora.utils'), - $container->get('islandora.media_source_service'), - $container->get('token'), - $container->get('entity_field.manager') - ); - } +class AbstractGenerateDerivativeMediaFile extends AbstractGenerateDerivativeBase { /** * {@inheritdoc} @@ -222,32 +105,32 @@ class AbstractGenerateDerivativeMediaFile extends EmitEvent { $form['args'] = [ '#type' => 'textfield', - '#title' => t('Additional arguments'), + '#title' => $this->t('Additional arguments'), '#default_value' => $this->configuration['args'], '#rows' => '8', - '#description' => t('Additional command line arguments'), + '#description' => $this->t('Additional command line arguments'), ]; $form['mimetype'] = [ '#type' => 'textfield', - '#title' => t('Mimetype'), + '#title' => $this->t('Mimetype'), '#default_value' => $this->configuration['mimetype'], '#required' => TRUE, '#rows' => '8', - '#description' => t('Mimetype to convert to (e.g. image/jpeg, video/mp4, etc...)'), + '#description' => $this->t('Mimetype to convert to (e.g. image/jpeg, video/mp4, etc...)'), ]; $form['path'] = [ '#type' => 'textfield', - '#title' => t('File path'), + '#title' => $this->t('File path'), '#default_value' => $this->configuration['path'], - '#description' => t('Path within the upload destination where files will be stored. Includes the filename and optional extension.'), + '#description' => $this->t('Path within the upload destination where files will be stored. Includes the filename and optional extension.'), ]; $form['queue'] = [ '#type' => 'textfield', - '#title' => t('Queue name'), + '#title' => $this->t('Queue name'), '#default_value' => $this->configuration['queue'], - '#description' => t('Queue name to send along to help routing events, CHANGE WITH CARE. Defaults to :queue', [ + '#description' => $this->t('Queue name to send along to help routing events, CHANGE WITH CARE. Defaults to :queue', [ ':queue' => $this->defaultConfiguration()['queue'], ]), ]; @@ -259,19 +142,18 @@ class AbstractGenerateDerivativeMediaFile extends EmitEvent { */ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { parent::validateConfigurationForm($form, $form_state); - $mimetype = $form_state->getValue('mimetype'); $exploded = explode('/', $form_state->getValue('mimetype')); if (count($exploded) != 2) { $form_state->setErrorByName( 'mimetype', - t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') + $this->t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') ); } if (empty($exploded[1])) { $form_state->setErrorByName( 'mimetype', - t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') + $this->t('Please enter a mimetype (e.g. image/jpeg, video/mp4, audio/mp3, etc...)') ); } } diff --git a/src/Plugin/Action/EmitFileEvent.php b/src/Plugin/Action/EmitFileEvent.php index f8f4be2e..a749a2a4 100644 --- a/src/Plugin/Action/EmitFileEvent.php +++ b/src/Plugin/Action/EmitFileEvent.php @@ -5,8 +5,10 @@ namespace Drupal\islandora\Plugin\Action; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Site\Settings; +use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\jwt\Authentication\Provider\JwtAuth; use Drupal\islandora\EventGenerator\EmitEvent; use Drupal\islandora\EventGenerator\EventGeneratorInterface; @@ -52,6 +54,8 @@ class EmitFileEvent extends EmitEvent { * JWT Auth client. * @param \Drupal\Core\File\FileSystemInterface $file_system * File system service. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger. */ public function __construct( array $configuration, @@ -62,7 +66,8 @@ class EmitFileEvent extends EmitEvent { EventGeneratorInterface $event_generator, StatefulStomp $stomp, JwtAuth $auth, - FileSystemInterface $file_system + FileSystemInterface $file_system, + MessengerInterface $messenger ) { parent::__construct( $configuration, @@ -72,7 +77,8 @@ class EmitFileEvent extends EmitEvent { $entity_type_manager, $event_generator, $stomp, - $auth + $auth, + $messenger ); $this->fileSystem = $file_system; } @@ -90,7 +96,8 @@ class EmitFileEvent extends EmitEvent { $container->get('islandora.eventgenerator'), $container->get('islandora.stomp'), $container->get('jwt.authentication.jwt'), - $container->get('file_system') + $container->get('file_system'), + $container->get('messenger') ); } @@ -99,7 +106,7 @@ class EmitFileEvent extends EmitEvent { */ protected function generateData(EntityInterface $entity) { $uri = $entity->getFileUri(); - $scheme = $this->fileSystem->uriScheme($uri); + $scheme = StreamWrapperManager::getScheme($uri); $flysystem_config = Settings::get('flysystem'); $data = parent::generateData($entity); diff --git a/src/Plugin/Action/EmitMediaEvent.php b/src/Plugin/Action/EmitMediaEvent.php index c5ad550a..275dd510 100644 --- a/src/Plugin/Action/EmitMediaEvent.php +++ b/src/Plugin/Action/EmitMediaEvent.php @@ -4,6 +4,7 @@ namespace Drupal\islandora\Plugin\Action; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\jwt\Authentication\Provider\JwtAuth; use Drupal\islandora\EventGenerator\EmitEvent; @@ -51,6 +52,8 @@ class EmitMediaEvent extends EmitEvent { * JWT Auth client. * @param \Drupal\islandora\MediaSource\MediaSourceService $media_source * Media source service. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger. */ public function __construct( array $configuration, @@ -61,7 +64,8 @@ class EmitMediaEvent extends EmitEvent { EventGeneratorInterface $event_generator, StatefulStomp $stomp, JwtAuth $auth, - MediaSourceService $media_source + MediaSourceService $media_source, + MessengerInterface $messenger ) { parent::__construct( $configuration, @@ -71,7 +75,8 @@ class EmitMediaEvent extends EmitEvent { $entity_type_manager, $event_generator, $stomp, - $auth + $auth, + $messenger ); $this->mediaSource = $media_source; } @@ -89,7 +94,8 @@ class EmitMediaEvent extends EmitEvent { $container->get('islandora.eventgenerator'), $container->get('islandora.stomp'), $container->get('jwt.authentication.jwt'), - $container->get('islandora.media_source_service') + $container->get('islandora.media_source_service'), + $container->get('messenger') ); } diff --git a/src/Plugin/Condition/FileUsesFilesystem.php b/src/Plugin/Condition/FileUsesFilesystem.php index 27e120e8..f1befc02 100644 --- a/src/Plugin/Condition/FileUsesFilesystem.php +++ b/src/Plugin/Condition/FileUsesFilesystem.php @@ -6,6 +6,7 @@ use Drupal\Core\Condition\ConditionPluginBase; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\Core\StreamWrapper\StreamWrapperManager; use Drupal\file\FileInterface; use Drupal\islandora\IslandoraUtils; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -151,7 +152,7 @@ class FileUsesFilesystem extends ConditionPluginBase implements ContainerFactory */ protected function evaluateFile(FileInterface $file) { $uri = $file->getFileUri(); - $scheme = $this->fileSystem->uriScheme($uri); + $scheme = StreamWrapperManager::getScheme($uri); return !empty($this->configuration['filesystems'][$scheme]); } diff --git a/src/Plugin/Condition/MediaHasMimetype.php b/src/Plugin/Condition/MediaHasMimetype.php index 291c0da6..52dfe749 100644 --- a/src/Plugin/Condition/MediaHasMimetype.php +++ b/src/Plugin/Condition/MediaHasMimetype.php @@ -101,11 +101,11 @@ class MediaHasMimetype extends ConditionPluginBase implements ContainerFactoryPl public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['mimetypes'] = [ '#type' => 'textfield', - '#title' => t('Mime types'), + '#title' => $this->t('Mime types'), '#default_value' => $this->configuration['mimetypes'], '#required' => TRUE, '#maxlength' => 256, - '#description' => t('Comma-delimited list of Mime types (e.g. image/jpeg, video/mp4, etc...) that trigger the condition.'), + '#description' => $this->t('Comma-delimited list of Mime types (e.g. image/jpeg, video/mp4, etc...) that trigger the condition.'), ]; return parent::buildConfigurationForm($form, $form_state); } diff --git a/src/Plugin/Condition/MediaSourceHasMimetype.php b/src/Plugin/Condition/MediaSourceHasMimetype.php index 86450750..185b2431 100644 --- a/src/Plugin/Condition/MediaSourceHasMimetype.php +++ b/src/Plugin/Condition/MediaSourceHasMimetype.php @@ -12,7 +12,7 @@ use Drupal\file\Entity\File; * @Condition( * id = "media_source_mimetype", * label = @Translation("Media Source Mimetype"), - * context = { + * context_definitions = { * "media" = @ContextDefinition("entity:media", required = FALSE, label = @Translation("Media")) * } * ) diff --git a/src/Plugin/Condition/NodeHadNamespace.php b/src/Plugin/Condition/NodeHadNamespace.php index 4872f7eb..0ec25afd 100644 --- a/src/Plugin/Condition/NodeHadNamespace.php +++ b/src/Plugin/Condition/NodeHadNamespace.php @@ -95,11 +95,11 @@ class NodeHadNamespace extends ConditionPluginBase implements ContainerFactoryPl $options = array_combine($node_fields, $node_fields); $form['pid_field'] = [ '#type' => 'select', - '#title' => t('Field that contains the PID'), + '#title' => $this->t('Field that contains the PID'), '#options' => $options, '#default_value' => $this->configuration['pid_field'], '#required' => TRUE, - '#description' => t("Machine name of the field that contains the PID."), + '#description' => $this->t("Machine name of the field that contains the PID."), ]; return parent::buildConfigurationForm($form, $form_state); diff --git a/src/Plugin/Condition/NodeHasParent.php b/src/Plugin/Condition/NodeHasParent.php index 5002707f..f9ef0cbf 100644 --- a/src/Plugin/Condition/NodeHasParent.php +++ b/src/Plugin/Condition/NodeHasParent.php @@ -82,10 +82,10 @@ class NodeHasParent extends ConditionPluginBase implements ContainerFactoryPlugi public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['parent_nid'] = [ '#type' => 'entity_autocomplete', - '#title' => t('Parent node'), + '#title' => $this->t('Parent node'), '#default_value' => $this->entityTypeManager->getStorage('node')->load($this->configuration['parent_nid']), '#required' => TRUE, - '#description' => t("Can be a collection node or a compound object."), + '#description' => $this->t("Can be a collection node or a compound object."), '#target_type' => 'node', ]; $field_map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('entity_reference'); @@ -93,11 +93,11 @@ class NodeHasParent extends ConditionPluginBase implements ContainerFactoryPlugi $options = array_combine($node_fields, $node_fields); $form['parent_reference_field'] = [ '#type' => 'select', - '#title' => t('Field that contains reference to parents'), + '#title' => $this->t('Field that contains reference to parents'), '#options' => $options, '#default_value' => $this->configuration['parent_reference_field'], '#required' => TRUE, - '#description' => t("Machine name of field that contains references to parent node."), + '#description' => $this->t("Machine name of field that contains references to parent node."), ]; return parent::buildConfigurationForm($form, $form_state); diff --git a/src/Plugin/Condition/NodeReferencedByNode.php b/src/Plugin/Condition/NodeReferencedByNode.php index acb03dfa..a2abac80 100644 --- a/src/Plugin/Condition/NodeReferencedByNode.php +++ b/src/Plugin/Condition/NodeReferencedByNode.php @@ -85,11 +85,11 @@ class NodeReferencedByNode extends ConditionPluginBase implements ContainerFacto $options = array_combine($node_fields, $node_fields); $form['reference_field'] = [ '#type' => 'select', - '#title' => t('Field to check for reference to this node'), + '#title' => $this->t('Field to check for reference to this node'), '#options' => $options, '#default_value' => $this->configuration['reference_field'], '#required' => TRUE, - '#description' => t("Machine name of field that should be checked for references to this node."), + '#description' => $this->t("Machine name of field that should be checked for references to this node."), ]; return parent::buildConfigurationForm($form, $form_state); diff --git a/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php b/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php index 321dd05d..6c6e87da 100644 --- a/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php +++ b/src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php @@ -96,7 +96,7 @@ class IslandoraImageFormatter extends ImageFormatter { $configuration['view_mode'], $configuration['third_party_settings'], $container->get('current_user'), - $container->get('entity.manager')->getStorage('image_style'), + $container->get('entity_type.manager')->getStorage('image_style'), $container->get('islandora.utils') ); } @@ -124,7 +124,7 @@ class IslandoraImageFormatter extends ImageFormatter { return $elements; } - $url = $node->urlInfo(); + $url = $node->toUrl(); foreach ($elements as &$element) { $element['#url'] = $url; diff --git a/tests/modules/integer_weight_test_views/integer_weight_test_views.info.yml b/tests/modules/integer_weight_test_views/integer_weight_test_views.info.yml index 78c510fc..7e298142 100644 --- a/tests/modules/integer_weight_test_views/integer_weight_test_views.info.yml +++ b/tests/modules/integer_weight_test_views/integer_weight_test_views.info.yml @@ -2,7 +2,7 @@ name: 'Integer weight test views' type: module description: 'Provides default views for integer weight views tests.' package: Testing -core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - drupal:node - drupal:views diff --git a/tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml b/tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml index c08b8400..08dc4912 100644 --- a/tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml +++ b/tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml @@ -248,4 +248,3 @@ display: - 'user.node_grants:view' - user.permissions tags: { } - diff --git a/tests/src/Functional/AddMediaToNodeTest.php b/tests/src/Functional/AddMediaToNodeTest.php index 856f004f..32909775 100644 --- a/tests/src/Functional/AddMediaToNodeTest.php +++ b/tests/src/Functional/AddMediaToNodeTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\islandora\Functional; use Drupal\Core\Url; -use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; +use Drupal\Tests\field\Traits\EntityReferenceTestTrait; /** * Tests the RelatedLinkHeader view alter. @@ -94,7 +94,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { 'access content', ]); $this->drupalLogin($account); - $options['auth'] = [$account->getUsername(), $account->pass_raw]; + $options['auth'] = [$account->getDisplayName(), $account->pass_raw]; $response = $client->request('PUT', $add_to_node_url, $options); $this->assertTrue($response->getStatusCode() == 403, "Expected 403, received {$response->getStatusCode()}"); @@ -108,7 +108,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { 'bypass node access', ]); $this->drupalLogin($account); - $options['auth'] = [$account->getUsername(), $account->pass_raw]; + $options['auth'] = [$account->getDisplayName(), $account->pass_raw]; $response = $client->request('PUT', $add_to_node_url, $options); $this->assertTrue($response->getStatusCode() == 403, "Expected 403, received {$response->getStatusCode()}"); @@ -121,7 +121,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { // Request without Content-Type header should fail with 400. $options = [ - 'auth' => [$account->getUsername(), $account->pass_raw], + 'auth' => [$account->getDisplayName(), $account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Location' => 'public://test_file.txt', @@ -133,7 +133,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { // Request without Content-Location header should fail with 400. $options = [ - 'auth' => [$account->getUsername(), $account->pass_raw], + 'auth' => [$account->getDisplayName(), $account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Type' => 'text/plain', @@ -145,7 +145,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { // Request without body should fail with 400. $options = [ - 'auth' => [$account->getUsername(), $account->pass_raw], + 'auth' => [$account->getDisplayName(), $account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Type' => 'text/plain', @@ -157,7 +157,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { // Test properly formed requests with bad parameters in the route. $options = [ - 'auth' => [$account->getUsername(), $account->pass_raw], + 'auth' => [$account->getDisplayName(), $account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Type' => 'text/plain', @@ -200,7 +200,7 @@ class AddMediaToNodeTest extends IslandoraFunctionalTestBase { // Should be successful with proper url, options, and permissions. $options = [ - 'auth' => [$account->getUsername(), $account->pass_raw], + 'auth' => [$account->getDisplayName(), $account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Type' => 'text/plain', diff --git a/tests/src/Functional/ContentEntityTypeTest.php b/tests/src/Functional/ContentEntityTypeTest.php index caf11de3..362ff7fb 100644 --- a/tests/src/Functional/ContentEntityTypeTest.php +++ b/tests/src/Functional/ContentEntityTypeTest.php @@ -39,7 +39,7 @@ class ContentEntityTypeTest extends IslandoraFunctionalTestBase { $this->addCondition('test', 'content_entity_type'); $this->getSession()->getPage()->checkField("edit-conditions-content-entity-type-types-node"); $this->getSession()->getPage()->findById("edit-conditions-content-entity-type-context-mapping-node")->selectOption("@node.node_route_context:node"); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); $this->addPresetReaction('test', 'index', 'hello_world'); // Create a new node confirm Hello World! is printed to the screen. @@ -48,12 +48,11 @@ class ContentEntityTypeTest extends IslandoraFunctionalTestBase { // Add a new media and confirm Hello World! is not printed to the // screen. - $file = current($this->getTestFiles('file')); $values = [ 'name[0][value]' => 'Test Media', 'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, t('Save')); + $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); $this->assertSession()->pageTextNotContains("Hello World!"); } diff --git a/tests/src/Functional/DerivativeReactionTest.php b/tests/src/Functional/DerivativeReactionTest.php index 38ec6ffa..e1b1c827 100644 --- a/tests/src/Functional/DerivativeReactionTest.php +++ b/tests/src/Functional/DerivativeReactionTest.php @@ -52,7 +52,7 @@ class DerivativeReactionTest extends IslandoraFunctionalTestBase { 'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file.txt', 'field_media_of[0][target_id]' => 'Test Node', ]; - $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, t('Save')); + $this->drupalPostForm('media/add/' . $this->testMediaType->id(), $values, $this->t('Save')); // field_media_of is set and there's a file, so derivatives should fire. $this->assertSession()->pageTextContains("Hello World!"); @@ -70,9 +70,9 @@ class DerivativeReactionTest extends IslandoraFunctionalTestBase { 'files[field_media_file_0]' => __DIR__ . '/../../fixtures/test_file2.txt', ]; $this->drupalGet($media_url . '/edit'); - $this->getSession()->getPage()->pressButton(t('Remove')); + $this->getSession()->getPage()->pressButton($this->t('Remove')); $this->getSession()->getPage()->fillField('files[field_media_file_0]', __DIR__ . '/../../fixtures/test_file2.txt'); - $this->getSession()->getPage()->pressButton(t('Save')); + $this->getSession()->getPage()->pressButton($this->t('Save')); $this->assertSession()->pageTextContains("Hello World!"); } diff --git a/tests/src/Functional/EmitNodeEventTest.php b/tests/src/Functional/EmitNodeEventTest.php index d3bb7449..83f062ae 100644 --- a/tests/src/Functional/EmitNodeEventTest.php +++ b/tests/src/Functional/EmitNodeEventTest.php @@ -44,7 +44,7 @@ class EmitNodeEventTest extends IslandoraFunctionalTestBase { $this->addCondition('test', 'content_entity_type'); $this->getSession()->getPage()->checkField("edit-conditions-content-entity-type-types-node"); $this->getSession()->getPage()->findById("edit-conditions-content-entity-type-context-mapping-node")->selectOption("@node.node_route_context:node"); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); $this->addPresetReaction('test', 'index', $action_id); $this->assertSession()->statusCodeEquals(200); @@ -68,7 +68,7 @@ class EmitNodeEventTest extends IslandoraFunctionalTestBase { protected function createEmitAction($entity_type, $event_type) { $this->drupalGet('admin/config/system/actions'); $this->getSession()->getPage()->findById("edit-action")->selectOption("Emit a $entity_type event to a queue/topic"); - $this->getSession()->getPage()->pressButton(t('Create')); + $this->getSession()->getPage()->pressButton($this->t('Create')); $this->assertSession()->statusCodeEquals(200); $action_id = "emit_" . $entity_type . "_" . lcfirst($event_type); @@ -76,7 +76,7 @@ class EmitNodeEventTest extends IslandoraFunctionalTestBase { $this->getSession()->getPage()->fillField('edit-id', $action_id); $this->getSession()->getPage()->fillField('edit-queue', "emit-$entity_type-" . lcfirst($event_type)); $this->getSession()->getPage()->findById("edit-event")->selectOption($event_type); - $this->getSession()->getPage()->pressButton(t('Save')); + $this->getSession()->getPage()->pressButton($this->t('Save')); $this->assertSession()->statusCodeEquals(200); return $action_id; @@ -102,8 +102,7 @@ class EmitNodeEventTest extends IslandoraFunctionalTestBase { "Authorization header must be set" ); $matches = []; - $this->assertTrue( - preg_match('/^Bearer (.*)/', $headers['Authorization'], $matches), + $this->assertTrue((boolean) preg_match('/^Bearer(\s*.*)/', $headers['Authorization'], $matches), "Authorization header must be a bearer token" ); $this->assertTrue( diff --git a/tests/src/Functional/EntityBundleTest.php b/tests/src/Functional/EntityBundleTest.php index 740ce8c1..bde1ee40 100644 --- a/tests/src/Functional/EntityBundleTest.php +++ b/tests/src/Functional/EntityBundleTest.php @@ -27,7 +27,7 @@ class EntityBundleTest extends IslandoraFunctionalTestBase { $this->addCondition('test', 'islandora_entity_bundle'); $this->getSession()->getPage()->checkField("edit-conditions-islandora-entity-bundle-bundles-test-type"); $this->getSession()->getPage()->findById("edit-conditions-islandora-entity-bundle-context-mapping-node")->selectOption("@node.node_route_context:node"); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); $this->addPresetReaction('test', 'index', 'hello_world'); // Create a new test_type confirm Hello World! is printed to the screen. diff --git a/tests/src/Functional/FormDisplayAlterReactionTest.php b/tests/src/Functional/FormDisplayAlterReactionTest.php index 08501579..d394b728 100644 --- a/tests/src/Functional/FormDisplayAlterReactionTest.php +++ b/tests/src/Functional/FormDisplayAlterReactionTest.php @@ -49,7 +49,7 @@ class FormDisplayAlterReactionTest extends IslandoraFunctionalTestBase { $this->drupalGet("admin/structure/context/test/reaction/add/form_display_alter"); $this->getSession()->getPage()->findById("edit-reactions-form-display-alter-mode")->selectOption('node.secondary'); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); $this->assertSession()->statusCodeEquals(200); drupal_flush_all_caches(); diff --git a/tests/src/Functional/IndexingTest.php b/tests/src/Functional/IndexingTest.php index bd451fc3..e995329d 100644 --- a/tests/src/Functional/IndexingTest.php +++ b/tests/src/Functional/IndexingTest.php @@ -65,7 +65,7 @@ class IndexingTest extends IslandoraFunctionalTestBase { $this->addPresetReaction('test', 'delete', 'goodbye_world'); // Delete the node. - $this->drupalPostForm("$url/delete", [], t('Delete')); + $this->drupalPostForm("$url/delete", [], $this->t('Delete')); $this->assertSession()->statusCodeEquals(200); // Confirm Goodbye, Cruel World! is printed to the screen. diff --git a/tests/src/Functional/IslandoraFunctionalTestBase.php b/tests/src/Functional/IslandoraFunctionalTestBase.php index 0b942eb8..a948daa4 100644 --- a/tests/src/Functional/IslandoraFunctionalTestBase.php +++ b/tests/src/Functional/IslandoraFunctionalTestBase.php @@ -5,6 +5,7 @@ namespace Drupal\Tests\islandora\Functional; use Drupal\Core\Config\FileStorage; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\link\LinkItemInterface; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\field\Traits\EntityReferenceTestTrait; @@ -19,6 +20,7 @@ class IslandoraFunctionalTestBase extends BrowserTestBase { use EntityReferenceTestTrait; use TestFileCreationTrait; use MediaTypeCreationTrait; + use StringTranslationTrait; /** * {@inheritdoc} @@ -30,6 +32,11 @@ class IslandoraFunctionalTestBase extends BrowserTestBase { 'menu_link_content', ]; + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + /** * {@inheritdoc} */ @@ -275,7 +282,7 @@ EOD; 'label' => $label, 'name' => $name, ], - t('Save')); + $this->t('Save')); $this->assertSession()->statusCodeEquals(200); } @@ -297,7 +304,7 @@ EOD; ->getPage() ->findById("edit-reactions-$reaction_type-actions") ->selectOption($action_id); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); $this->assertSession()->statusCodeEquals(200); } @@ -305,7 +312,7 @@ EOD; * Create a new node by posting its add form. */ protected function postNodeAddForm($bundle_id, $values, $button_text) { - $this->drupalPostForm("node/add/$bundle_id", $values, t('@text', ['@text' => $button_text])); + $this->drupalPostForm("node/add/$bundle_id", $values, $this->t('@text', ['@text' => $button_text])); $this->assertSession()->statusCodeEquals(200); } @@ -313,7 +320,7 @@ EOD; * Create a new node by posting its add form. */ protected function postTermAddForm($taxomony_id, $values, $button_text) { - $this->drupalPostForm("admin/structure/taxonomy/manage/$taxomony_id/add", $values, t('@text', ['@text' => $button_text])); + $this->drupalPostForm("admin/structure/taxonomy/manage/$taxomony_id/add", $values, $this->t('@text', ['@text' => $button_text])); $this->assertSession()->statusCodeEquals(200); } @@ -321,7 +328,7 @@ EOD; * Edits a node by posting its edit form. */ protected function postEntityEditForm($entity_url, $values, $button_text) { - $this->drupalPostForm("$entity_url/edit", $values, t('@text', ['@text' => $button_text])); + $this->drupalPostForm("$entity_url/edit", $values, $this->t('@text', ['@text' => $button_text])); $this->assertSession()->statusCodeEquals(200); } diff --git a/tests/src/Functional/IslandoraImageFormatterTest.php b/tests/src/Functional/IslandoraImageFormatterTest.php index aa85162c..2793cf49 100644 --- a/tests/src/Functional/IslandoraImageFormatterTest.php +++ b/tests/src/Functional/IslandoraImageFormatterTest.php @@ -34,7 +34,7 @@ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { 'type' => 'islandora_image', 'settings' => ['image_style' => NULL, 'image_link' => 'content'], ]; - $display = entity_get_display('media', $testImageMediaType->id(), 'default'); + $display = $this->container->get('entity_display.repository')->getViewDisplay('media', $testImageMediaType->id(), 'default'); $display->setComponent('field_media_image', $display_options) ->removeComponent('created') ->removeComponent('uid') @@ -81,8 +81,8 @@ class IslandoraImageFormatterTest extends IslandoraFunctionalTestBase { $elements = $this->xpath( '//a[@href=:path]/img[@src=:url and @alt=:alt and @title=:title]', [ - ':path' => $node->url(), - ':url' => file_url_transform_relative(file_create_url($file->getFileUri())), + ':path' => $node->toUrl()->toString(), + ':url' => $file->createFileUrl(), ':alt' => 'Some Alt', ':title' => 'Some Title', ] diff --git a/tests/src/Functional/IslandoraSettingsFormTest.php b/tests/src/Functional/IslandoraSettingsFormTest.php index bdf15d29..5373a3dd 100644 --- a/tests/src/Functional/IslandoraSettingsFormTest.php +++ b/tests/src/Functional/IslandoraSettingsFormTest.php @@ -37,10 +37,10 @@ class IslandoraSettingsFormTest extends IslandoraFunctionalTestBase { $this->assertSession()->pageTextContains("Gemini URL"); $this->assertSession()->fieldValueEquals('edit-gemini-url', ''); - $this->drupalPostForm('admin/config/islandora/core', ['edit-gemini-url' => 'not_a_url'], t('Save configuration')); + $this->drupalPostForm('admin/config/islandora/core', ['edit-gemini-url' => 'not_a_url'], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce("Cannot parse URL not_a_url"); - $this->drupalPostForm('admin/config/islandora/core', ['edit-gemini-url' => 'http://whaturl.bob'], t('Save configuration')); + $this->drupalPostForm('admin/config/islandora/core', ['edit-gemini-url' => 'http://whaturl.bob'], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce("Cannot connect to URL http://whaturl.bob"); } @@ -53,7 +53,7 @@ class IslandoraSettingsFormTest extends IslandoraFunctionalTestBase { $this->drupalPostForm('admin/config/islandora/core', [ 'gemini_pseudo_bundles[test_type:node]' => TRUE, - ], t('Save configuration')); + ], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce("Must enter Gemini URL before selecting bundles to display a pseudo field on."); } @@ -67,19 +67,19 @@ class IslandoraSettingsFormTest extends IslandoraFunctionalTestBase { $this->assertSession()->pageTextContains("JWT Expiry"); $this->assertSession()->fieldValueEquals('edit-jwt-expiry', '+2 hour'); // Blank is not allowed. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => ""], t('Save configuration')); + $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => ""], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('"" is not a valid time or interval expression.'); // Negative is not allowed. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "-2 hours"], t('Save configuration')); + $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "-2 hours"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('Time or interval expression cannot be negative'); // Must include an integer value. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "last hour"], t('Save configuration')); + $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "last hour"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('No numeric interval specified, for example "1 day"'); // Must have an accepted interval. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "1 fortnight"], t('Save configuration')); + $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "1 fortnight"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('No time interval found, please include one of'); // Test a valid setting. - $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "2 weeks"], t('Save configuration')); + $this->drupalPostForm('/admin/config/islandora/core', ['edit-jwt-expiry' => "2 weeks"], $this->t('Save configuration')); $this->assertSession()->pageTextContainsOnce('The configuration options have been saved.'); } diff --git a/tests/src/Functional/JsonldSelfReferenceReactionTest.php b/tests/src/Functional/JsonldSelfReferenceReactionTest.php index 7f99d625..f3c88271 100644 --- a/tests/src/Functional/JsonldSelfReferenceReactionTest.php +++ b/tests/src/Functional/JsonldSelfReferenceReactionTest.php @@ -51,7 +51,7 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { $this->postNodeAddForm('test_type', ['title[0][value]' => 'Test Node'], - t('Save')); + $this->t('Save')); $this->assertSession()->pageTextContains("Test Node"); $url = $this->getUrl(); @@ -153,8 +153,8 @@ class JsonldSelfReferenceReactionTest extends IslandoraFunctionalTestBase { $reaction_id = 'islandora_map_uri_predicate'; list($file, $media) = $this->makeMediaAndFile($account); - $media_url = $media->url('canonical', ['absolute' => TRUE]); - $file_url = $file->url('canonical', ['absolute' => TRUE]); + $media_url = $media->toUrl('canonical', ['absolute' => TRUE])->toString(); + $file_url = $file->createFileUrl(FALSE); $this->drupalGet($media_url); $this->assertSession()->statusCodeEquals(200); diff --git a/tests/src/Functional/JsonldTypeAlterReactionTest.php b/tests/src/Functional/JsonldTypeAlterReactionTest.php index 6e838126..e5d21abc 100644 --- a/tests/src/Functional/JsonldTypeAlterReactionTest.php +++ b/tests/src/Functional/JsonldTypeAlterReactionTest.php @@ -27,16 +27,16 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest { 'new_storage_type' => 'string', 'label' => 'Typed Predicate', 'field_name' => 'type_predicate', - ], t('Save and continue')); - $this->drupalPostForm(NULL, [], t('Save field settings')); - $this->drupalPostForm(NULL, [], t('Save settings')); + ], $this->t('Save and continue')); + $this->drupalPostForm(NULL, [], $this->t('Save field settings')); + $this->drupalPostForm(NULL, [], $this->t('Save settings')); $this->assertRaw('field_type_predicate', 'Redirected to "Manage fields" page.'); // Add the test node. $this->postNodeAddForm('test_type', [ 'title[0][value]' => 'Test Node', 'field_type_predicate[0][value]' => 'schema:Organization', - ], t('Save')); + ], $this->t('Save')); $this->assertSession()->pageTextContains("Test Node"); $url = $this->getUrl(); @@ -73,7 +73,7 @@ class JsonldTypeAlterReactionTest extends JsonldSelfReferenceReactionTest { $this->addCondition('test', 'islandora_entity_bundle'); $this->getSession()->getPage()->checkField("edit-conditions-islandora-entity-bundle-bundles-test-type"); $this->getSession()->getPage()->findById("edit-conditions-islandora-entity-bundle-context-mapping-node")->selectOption("@node.node_route_context:node"); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); // The first time a Context is saved, you need to clear the cache. // Subsequent changes to the context don't need a cache rebuild, though. diff --git a/tests/src/Functional/LinkHeaderTest.php b/tests/src/Functional/LinkHeaderTest.php index 472986c2..1cd1e0a8 100644 --- a/tests/src/Functional/LinkHeaderTest.php +++ b/tests/src/Functional/LinkHeaderTest.php @@ -135,15 +135,14 @@ class LinkHeaderTest extends IslandoraFunctionalTestBase { public function testMediaLinkHeaders() { // Get the file to check its url in the response headers. - $file_url = $this->file->url('canonical', ['absolute' => TRUE]); + $file_url = $this->file->createFileUrl(FALSE); $rest_url = Url::fromRoute('islandora.media_source_update', ['media' => $this->media->id()]) ->setAbsolute() ->toString(); - $media_url = $this->media->url('canonical', ['absolute' => TRUE]); + $media_url = $this->media->toUrl('canonical', ['absolute' => TRUE])->toString(); // Perform a GET request as anonymous. $this->drupalGet($media_url, [], ['Cache-Control: no-cache']); - // Check link headers. $this->assertTrue( $this->validateLinkHeaderWithUrl('describes', $file_url, '', 'text/plain') == 1, diff --git a/tests/src/Functional/MediaSourceUpdateTest.php b/tests/src/Functional/MediaSourceUpdateTest.php index 6994f2ab..fdea6aef 100644 --- a/tests/src/Functional/MediaSourceUpdateTest.php +++ b/tests/src/Functional/MediaSourceUpdateTest.php @@ -84,7 +84,7 @@ class MediaSourceUpdateTest extends IslandoraFunctionalTestBase { // Update without Content-Type header should fail with 400. $options = [ - 'auth' => [$this->account->getUsername(), $this->account->pass_raw], + 'auth' => [$this->account->getAccountName(), $this->account->pass_raw], 'http_errors' => FALSE, 'body' => $file_contents, ]; @@ -93,7 +93,7 @@ class MediaSourceUpdateTest extends IslandoraFunctionalTestBase { // Update without body should fail with 400. $options = [ - 'auth' => [$this->account->getUsername(), $this->account->pass_raw], + 'auth' => [$this->account->getAccountName(), $this->account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Type' => 'text/plain', @@ -104,7 +104,7 @@ class MediaSourceUpdateTest extends IslandoraFunctionalTestBase { // Should be successful. $options = [ - 'auth' => [$this->account->getUsername(), $this->account->pass_raw], + 'auth' => [$this->account->getAccountName(), $this->account->pass_raw], 'http_errors' => FALSE, 'headers' => [ 'Content-Type' => 'text/plain', @@ -116,10 +116,10 @@ class MediaSourceUpdateTest extends IslandoraFunctionalTestBase { // GET the media and compare file and metadata. $options = [ - 'auth' => [$this->account->getUsername(), $this->account->pass_raw], + 'auth' => [$this->account->getAccountName(), $this->account->pass_raw], 'http_errors' => FALSE, ]; - $url = $this->media->url('canonical', ['absolute' => TRUE]); + $url = $this->media->toUrl('canonical', ['absolute' => TRUE])->toString(); $response = $client->request('GET', $url . '?_format=json', $options); $updated = json_decode($response->getBody(), TRUE); diff --git a/tests/src/Functional/ViewModeAlterReactionTest.php b/tests/src/Functional/ViewModeAlterReactionTest.php index 04f07e00..72cdfe44 100644 --- a/tests/src/Functional/ViewModeAlterReactionTest.php +++ b/tests/src/Functional/ViewModeAlterReactionTest.php @@ -64,7 +64,7 @@ class ViewModeAlterReactionTest extends IslandoraFunctionalTestBase { $this->drupalLogin($account); // Stash the node's url. - $url = $this->referencer->url('canonical', ['absolute' => TRUE]); + $url = $this->referencer->toUrl('canonical', ['absolute' => TRUE]); $this->drupalGet($url); // Make sure we're viewing the default (e.g. the media field is displayed). @@ -75,7 +75,7 @@ class ViewModeAlterReactionTest extends IslandoraFunctionalTestBase { $this->drupalGet("admin/structure/context/test/reaction/add/view_mode_alter"); $this->getSession()->getPage()->findById("edit-reactions-view-mode-alter-mode")->selectOption('node.teaser'); - $this->getSession()->getPage()->pressButton(t('Save and continue')); + $this->getSession()->getPage()->pressButton($this->t('Save and continue')); $this->assertSession()->statusCodeEquals(200); drupal_flush_all_caches(); diff --git a/tests/src/FunctionalJavascript/IntegerWeightTest.php b/tests/src/FunctionalJavascript/IntegerWeightTest.php index ba3892e6..ba289aa4 100644 --- a/tests/src/FunctionalJavascript/IntegerWeightTest.php +++ b/tests/src/FunctionalJavascript/IntegerWeightTest.php @@ -32,6 +32,13 @@ class IntegerWeightTest extends WebDriverTestBase { 'integer_weight_test_views', ]; + /** + * Name of theme. + * + * @var string + */ + protected $defaultTheme = 'stark'; + /** * Name of the field. * diff --git a/tests/src/Kernel/FedoraAdapterTest.php b/tests/src/Kernel/FedoraAdapterTest.php index 522321c4..7ba00232 100644 --- a/tests/src/Kernel/FedoraAdapterTest.php +++ b/tests/src/Kernel/FedoraAdapterTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\islandora\Kernel; use Drupal\islandora\Flysystem\Adapter\FedoraAdapter; -use GuzzleHttp\Psr7; use GuzzleHttp\Psr7\Response; use Islandora\Chullo\IFedoraApi; use League\Flysystem\Config; @@ -18,6 +17,31 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface; */ class FedoraAdapterTest extends IslandoraKernelTestBase { + /** + * Shared functionality for an adapter. + */ + protected function createAdapterBase() { + $prophecy = $this->prophesize(Response::class); + $prophecy->getStatusCode()->willReturn(200); + $prophecy->getHeader('Last-Modified') + ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); + $prophecy->getHeader('Link') + ->willReturn([ + ';rel="type"', + ';rel="type"', + ]); + $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); + $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); + // phpcs:disable + if (class_exists(\GuzzleHttp\Psr7\Utils::class)) { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\Utils::streamFor("DERP")); + } else { + $prophecy->getBody()->willReturn(\GuzzleHttp\Psr7\stream_for("DERP")); + } + // phpcs:enable + return $prophecy; + } + /** * Mocks up an adapter for Fedora calls that return 404. */ @@ -41,18 +65,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { * Mocks up an adapter for Fedora LDP-NR response. */ protected function createAdapterForFile() { - $prophecy = $this->prophesize(Response::class); - $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified') - ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link') - ->willReturn([ - ';rel="type"', - ';rel="type"', - ]); - $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); - $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - $prophecy->getBody()->willReturn(PSR7\stream_for("DERP")); + $prophecy = $this->createAdapterBase(); $response = $prophecy->reveal(); $prophecy = $this->prophesize(IFedoraApi::class); @@ -107,18 +120,7 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $fedora_prophecy->saveResource('', '', Argument::any()) ->willReturn($prophecy->reveal()); - $prophecy = $this->prophesize(Response::class); - $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified') - ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link') - ->willReturn([ - ';rel="type"', - ';rel="type"', - ]); - $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); - $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - $prophecy->getBody()->willReturn(PSR7\stream_for("DERP")); + $prophecy = $this->createAdapterBase(); $fedora_prophecy->getResourceHeaders('')->willReturn($prophecy->reveal()); @@ -599,18 +601,8 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { * @covers \Drupal\islandora\Flysystem\Adapter\FedoraAdapter::copy */ public function testRename() { - $prophecy = $this->prophesize(Response::class); - $prophecy->getStatusCode()->willReturn(200); - $prophecy->getHeader('Last-Modified') - ->willReturn(["Wed, 25 Jul 2018 17:42:04 GMT"]); - $prophecy->getHeader('Link') - ->willReturn([ - ';rel="type"', - ';rel="type"', - ]); - $prophecy->getHeader('Content-Type')->willReturn(['text/plain']); - $prophecy->getHeader('Content-Length')->willReturn([strlen("DERP")]); - $prophecy->getBody()->willReturn(PSR7\stream_for("DERP")); + $prophecy = $this->createAdapterBase(); + $response = $prophecy->reveal(); $fedora_prophecy = $this->prophesize(IFedoraApi::class); @@ -620,8 +612,6 @@ class FedoraAdapterTest extends IslandoraKernelTestBase { $prophecy->getStatusCode()->willReturn(201); $response = $prophecy->reveal(); - $date = new \DateTime(); - $timestamp = $date->format("D, d M Y H:i:s O"); $fedora_prophecy->createVersion('', Argument::any(), NULL, Argument::any())->willReturn($prophecy->reveal()); diff --git a/tests/src/Kernel/GeminiClientFactoryTest.php b/tests/src/Kernel/GeminiClientFactoryTest.php index 68fca748..826723ff 100644 --- a/tests/src/Kernel/GeminiClientFactoryTest.php +++ b/tests/src/Kernel/GeminiClientFactoryTest.php @@ -8,6 +8,7 @@ use Drupal\islandora\GeminiClientFactory; use Islandora\Crayfish\Commons\Client\GeminiClient; use Prophecy\Argument; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException; /** * Tests GeminiClientFactory. @@ -38,9 +39,9 @@ class GeminiClientFactoryTest extends IslandoraKernelTestBase { /** * @covers ::create - * @expectedException \Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException */ public function testNoUrlBlank() { + $this->expectException(PreconditionFailedHttpException::class); $prophecy = $this->prophesize(ImmutableConfig::class); $prophecy->get(Argument::any())->willReturn(''); $immutConfig = $prophecy->reveal(); @@ -54,9 +55,9 @@ class GeminiClientFactoryTest extends IslandoraKernelTestBase { /** * @covers ::create - * @expectedException \Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException */ public function testNoUrlNull() { + $this->expectException(PreconditionFailedHttpException::class); $prophecy = $this->prophesize(ImmutableConfig::class); $prophecy->get(Argument::any())->willReturn(NULL); $immutConfig = $prophecy->reveal();