Browse Source

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
pull/791/head
Eli Zoller 4 years ago committed by GitHub
parent
commit
7f0d54e1eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .travis.yml
  2. 6
      composer.json
  3. 1
      drush.services.yml
  4. 53
      islandora.info.yml
  5. 15
      islandora.install
  6. 2
      islandora.module
  7. 2
      islandora.routing.yml
  8. 4
      islandora.services.yml
  9. 3
      modules/islandora_audio/islandora_audio.info.yml
  10. 6
      modules/islandora_audio/src/Plugin/Action/GenerateAudioDerivative.php
  11. 6
      modules/islandora_audio/tests/src/Functional/GenerateAudioDerivativeTest.php
  12. 3
      modules/islandora_breadcrumbs/islandora_breadcrumbs.info.yml
  13. 2
      modules/islandora_core_feature/config/install/migrate_plus.migration.islandora_tags.yml
  14. 45
      modules/islandora_core_feature/islandora_core_feature.info.yml
  15. 3
      modules/islandora_iiif/islandora_iiif.info.yml
  16. 36
      modules/islandora_iiif/src/Form/IslandoraIIIFConfigForm.php
  17. 18
      modules/islandora_iiif/src/Plugin/views/style/IIIFManifest.php
  18. 3
      modules/islandora_image/islandora_image.info.yml
  19. 6
      modules/islandora_image/src/Plugin/Action/GenerateImageDerivative.php
  20. 4
      modules/islandora_image/src/Plugin/Action/GenerateImageDerivativeFile.php
  21. 6
      modules/islandora_image/tests/src/Functional/GenerateImageDerivativeTest.php
  22. 3
      modules/islandora_text_extraction/islandora_text_extraction.info.yml
  23. 1
      modules/islandora_text_extraction/islandora_text_extraction.services.yml
  24. 10
      modules/islandora_text_extraction/src/Controller/MediaSourceController.php
  25. 4
      modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivative.php
  26. 6
      modules/islandora_text_extraction/src/Plugin/Action/GenerateOCRDerivativeFile.php
  27. 66
      modules/islandora_text_extraction/src/Plugin/Field/FieldFormatter/OcrTextFormatter.php
  28. 21
      modules/islandora_text_extraction_defaults/islandora_text_extraction_defaults.info.yml
  29. 3
      modules/islandora_video/islandora_video.info.yml
  30. 6
      modules/islandora_video/src/Plugin/Action/GenerateVideoDerivative.php
  31. 6
      modules/islandora_video/tests/src/Functional/GenerateVideoDerivativeTest.php
  32. 52
      phpunit.xml
  33. 50
      src/Commands/IslandoraCommands.php
  34. 8
      src/ContextProvider/FileContextProvider.php
  35. 8
      src/ContextProvider/FileRouteContextProvider.php
  36. 8
      src/ContextProvider/MediaContextProvider.php
  37. 8
      src/ContextProvider/MediaRouteContextProvider.php
  38. 8
      src/ContextProvider/NodeContextProvider.php
  39. 8
      src/ContextProvider/TermContextProvider.php
  40. 11
      src/ContextProvider/TermRouteContextProvider.php
  41. 2
      src/Controller/ManageMembersController.php
  42. 51
      src/EventGenerator/EmitEvent.php
  43. 7
      src/EventGenerator/EventGenerator.php
  44. 1
      src/EventSubscriber/LinkHeaderSubscriber.php
  45. 19
      src/Flysystem/Adapter/FedoraAdapter.php
  46. 1
      src/Form/ConfirmDeleteMediaAndFile.php
  47. 13
      src/Form/IslandoraSettingsForm.php
  48. 10
      src/GeminiLookup.php
  49. 32
      src/IslandoraUtils.php
  50. 14
      src/MediaSource/MediaSourceService.php
  51. 142
      src/Plugin/Action/AbstractGenerateDerivative.php
  52. 142
      src/Plugin/Action/AbstractGenerateDerivativeBase.php
  53. 140
      src/Plugin/Action/AbstractGenerateDerivativeMediaFile.php
  54. 15
      src/Plugin/Action/EmitFileEvent.php
  55. 12
      src/Plugin/Action/EmitMediaEvent.php
  56. 3
      src/Plugin/Condition/FileUsesFilesystem.php
  57. 4
      src/Plugin/Condition/MediaHasMimetype.php
  58. 2
      src/Plugin/Condition/MediaSourceHasMimetype.php
  59. 4
      src/Plugin/Condition/NodeHadNamespace.php
  60. 8
      src/Plugin/Condition/NodeHasParent.php
  61. 4
      src/Plugin/Condition/NodeReferencedByNode.php
  62. 4
      src/Plugin/Field/FieldFormatter/IslandoraImageFormatter.php
  63. 2
      tests/modules/integer_weight_test_views/integer_weight_test_views.info.yml
  64. 1
      tests/modules/integer_weight_test_views/test_views/views.view.test_integer_weight.yml
  65. 16
      tests/src/Functional/AddMediaToNodeTest.php
  66. 5
      tests/src/Functional/ContentEntityTypeTest.php
  67. 6
      tests/src/Functional/DerivativeReactionTest.php
  68. 9
      tests/src/Functional/EmitNodeEventTest.php
  69. 2
      tests/src/Functional/EntityBundleTest.php
  70. 2
      tests/src/Functional/FormDisplayAlterReactionTest.php
  71. 2
      tests/src/Functional/IndexingTest.php
  72. 17
      tests/src/Functional/IslandoraFunctionalTestBase.php
  73. 6
      tests/src/Functional/IslandoraImageFormatterTest.php
  74. 16
      tests/src/Functional/IslandoraSettingsFormTest.php
  75. 6
      tests/src/Functional/JsonldSelfReferenceReactionTest.php
  76. 10
      tests/src/Functional/JsonldTypeAlterReactionTest.php
  77. 5
      tests/src/Functional/LinkHeaderTest.php
  78. 10
      tests/src/Functional/MediaSourceUpdateTest.php
  79. 4
      tests/src/Functional/ViewModeAlterReactionTest.php
  80. 7
      tests/src/FunctionalJavascript/IntegerWeightTest.php
  81. 68
      tests/src/Kernel/FedoraAdapterTest.php
  82. 5
      tests/src/Kernel/GeminiClientFactoryTest.php

4
.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

6
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"

1
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 }

53
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

15
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);
}
}
}

2
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;
}

2
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'

4
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]

3
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

6
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...)')
);
}
}

6
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',

3
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

2
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

45
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

3
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

36
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) {

18
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');
}

3
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

6
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...)')
);
}
}

4
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;

6
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',

3
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

1
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']

10
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(),

4
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.)')
);
}
}

6
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.)')
);
}
}

66
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);

21
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

3
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

6
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...)')
);
}
}

6
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',

52
phpunit.xml

@ -1,15 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
or your current system user. See core/tests/README.md and
https://www.drupal.org/node/2116263 for details.
-->
<phpunit bootstrap="tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" beStrictAboutChangesToGlobalState="true" printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./includes</directory>
<directory>./lib</directory>
<directory>./modules</directory>
<directory>../modules</directory>
<directory>../sites</directory>
</include>
<exclude>
<directory>./modules/*/src/Tests</directory>
<directory>./modules/*/tests</directory>
<directory>../modules/*/src/Tests</directory>
<directory>../modules/*/tests</directory>
<directory>../modules/*/*/src/Tests</directory>
<directory>../modules/*/*/tests</directory>
</exclude>
</coverage>
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
@ -29,13 +41,13 @@
<!-- To disable deprecation testing completely uncomment the next line. -->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
<!-- Example for changing the driver class for mink tests MINK_DRIVER_CLASS value: 'Drupal\FunctionalJavascriptTests\DrupalSelenium2Driver' -->
<env name="MINK_DRIVER_CLASS" value=''/>
<env name="MINK_DRIVER_CLASS" value=""/>
<!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS" value=''/>
<env name="MINK_DRIVER_ARGS" value=""/>
<!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
<env name="MINK_DRIVER_ARGS_PHANTOMJS" value=''/>
<env name="MINK_DRIVER_ARGS_PHANTOMJS" value=""/>
<!-- Example for changing the driver args to webdriver tests MINK_DRIVER_ARGS_WEBDRIVER value: '["chrome", { "chromeOptions": { "w3c": false } }, "http://localhost:4444/wd/hub"]' For using the Firefox browser, replace "chrome" with "firefox" -->
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=''/>
<env name="MINK_DRIVER_ARGS_WEBDRIVER" value=""/>
</php>
<testsuites>
<testsuite name="unit">
@ -63,24 +75,4 @@
</listener>
</listeners>
<!-- Filter for coverage reports. -->
<filter>
<whitelist>
<directory>./includes</directory>
<directory>./lib</directory>
<!-- Extensions can have their own test directories, so exclude those. -->
<directory>./modules</directory>
<exclude>
<directory>./modules/*/src/Tests</directory>
<directory>./modules/*/tests</directory>
</exclude>
<directory>../modules</directory>
<exclude>
<directory>../modules/*/src/Tests</directory>
<directory>../modules/*/tests</directory>
<directory>../modules/*/*/src/Tests</directory>
<directory>../modules/*/*/tests</directory>
</exclude>
<directory>../sites</directory>
</whitelist>
</filter>
</phpunit>

50
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();
}
}

8
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];
}

8
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];
}

8
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];
}

8
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];
}

8
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];
}

8
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];
}

11
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];
}

2
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,

51
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;

7
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"];

1
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");

19
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] == '<http://www.w3.org/ns/ldp#NonRDFSource>') {
$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');

1
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') {

13
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)]
)
);
}

10
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], '<>');

32
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);
}
/**

14
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");
}

142
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...)')
);
}
}

142
src/Plugin/Action/AbstractGenerateDerivativeBase.php

@ -0,0 +1,142 @@
<?php
namespace Drupal\islandora\Plugin\Action;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountInterface;
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;
/**
* A base class for constructor/creator derivative generators.
*/
class AbstractGenerateDerivativeBase 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;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* The system file config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* 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.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The system file config.
*/
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,
MessengerInterface $messenger,
ConfigFactoryInterface $config
) {
$this->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')
);
}
}

140
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...)')
);
}
}

15
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);

12
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')
);
}

3
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]);
}

4
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);
}

2
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"))
* }
* )

4
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);

8
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);

4
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);

4
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;

2
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

1
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: { }

16
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',

5
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!");
}

6
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!");
}

9
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(

2
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.

2
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();

2
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.

17
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);
}

6
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',
]

16
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.');
}

6
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);

10
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.

5
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,

10
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);

4
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();

7
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.
*

68
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([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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([
'<http://www.w3.org/ns/ldp#Resource>;rel="type"',
'<http://www.w3.org/ns/ldp#NonRDFSource>;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());

5
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();

Loading…
Cancel
Save