From 68d83a9c935ee41cf01cf1b937c6333811ef2c64 Mon Sep 17 00:00:00 2001 From: qadan Date: Tue, 8 Dec 2020 19:57:11 +0000 Subject: [PATCH 1/2] manually implementing postsave --- composer.json | 1 - islandora.info.yml | 1 - islandora.module | 24 ++++++++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 610d4ae35..edb5c423e 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "drupal/token" : "^1.3", "drupal/flysystem" : "^1.0", "islandora/crayfish-commons": "dev-dev", - "drupal/hook_post_action" : "^1.0", "drupal/file_replace": "^1.1" }, diff --git a/islandora.info.yml b/islandora.info.yml index 9d5bc8a4a..f5da3c93e 100644 --- a/islandora.info.yml +++ b/islandora.info.yml @@ -31,5 +31,4 @@ dependencies: - content_translation - flysystem - token - - hook_post_action - file_replace diff --git a/islandora.module b/islandora.module index 85771ee3a..e0aef9af6 100644 --- a/islandora.module +++ b/islandora.module @@ -120,6 +120,8 @@ function islandora_media_insert(MediaInterface $media) { $media ); } + // Wait until the media insert is complete, then fire file derivatives. + drupal_register_shutdown_function('_islandora_fire_media_file_derivative_reaction', $media); } /** @@ -170,16 +172,22 @@ function islandora_media_delete(MediaInterface $media) { } /** - * Implements hook_ENTITYTYPE_postsave(). + * Helper to fire media derivative file reactions after a media 'insert'. + * + * This function should not be called on its own; it exists as a workaround to + * being unable to fire media events after a media insert operation. This + * behaviour will eventually be replaced by event listeners once these are + * implemented in Drupal 9. + * + * @see https://www.drupal.org/project/drupal/issues/2551893 + * + * @param \Drupal\Core\Media\MediaInterface $media + * The media that was just inserted. */ -function islandora_media_postsave(EntityInterface $media, $op) { - +function _islandora_fire_media_file_derivative_reaction(MediaInterface $media) { $utils = \Drupal::service('islandora.utils'); - // Add derived file to the media. - if ($op == 'insert') { - $utils->executeMediaReactions('\Drupal\islandora\Plugin\ContextReaction\DerivativeFileReaction', $media); - } - + // Execute derivative file reactions. + $utils->executeMediaReactions('\Drupal\islandora\Plugin\ContextReaction\DerivativeFileReaction', $media); } /** From c43c0b73f93756d3e8100c7a3bd635d20f299e35 Mon Sep 17 00:00:00 2001 From: qadan Date: Thu, 10 Dec 2020 10:31:31 -0400 Subject: [PATCH 2/2] it was the see --- islandora.module | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/islandora.module b/islandora.module index e0aef9af6..6fd1b7b35 100644 --- a/islandora.module +++ b/islandora.module @@ -179,10 +179,10 @@ function islandora_media_delete(MediaInterface $media) { * behaviour will eventually be replaced by event listeners once these are * implemented in Drupal 9. * - * @see https://www.drupal.org/project/drupal/issues/2551893 - * * @param \Drupal\Core\Media\MediaInterface $media * The media that was just inserted. + * + * @see https://www.drupal.org/project/drupal/issues/2551893 */ function _islandora_fire_media_file_derivative_reaction(MediaInterface $media) { $utils = \Drupal::service('islandora.utils');