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