From e57b9e709a6422a19b99d33fce65b8d53ff6e4cf Mon Sep 17 00:00:00 2001 From: Daniel Aitken Date: Thu, 10 Dec 2020 11:22:09 -0400 Subject: [PATCH] manually implementing postsave (#815) * manually implementing postsave * it was the see --- 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 610d4ae3..edb5c423 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 9d5bc8a4..f5da3c93 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 85771ee3..6fd1b7b3 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. + * + * @param \Drupal\Core\Media\MediaInterface $media + * The media that was just inserted. + * + * @see https://www.drupal.org/project/drupal/issues/2551893 */ -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); } /**