Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manually implementing postsave #815

Merged
merged 2 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"

},
Expand Down
1 change: 0 additions & 1 deletion islandora.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ dependencies:
- content_translation
- flysystem
- token
- hook_post_action
- file_replace
24 changes: 16 additions & 8 deletions islandora.module
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down