From 59c5c8fd43daa227781bb2e5ac72c24cec8c27c0 Mon Sep 17 00:00:00 2001 From: Dan Morrison Date: Thu, 13 Apr 2017 12:21:38 +1200 Subject: [PATCH] Issue #2869239 : Action to refresh the thumbnail : Provide 'Action' to expose automaticallySetThumbnail() function to users. --- ...em.action.media_reset_thumbnail_action.yml | 10 +++++ src/Plugin/Action/ResetMediaThumbnail.php | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 config/install/system.action.media_reset_thumbnail_action.yml create mode 100644 src/Plugin/Action/ResetMediaThumbnail.php diff --git a/config/install/system.action.media_reset_thumbnail_action.yml b/config/install/system.action.media_reset_thumbnail_action.yml new file mode 100644 index 0000000..816281d --- /dev/null +++ b/config/install/system.action.media_reset_thumbnail_action.yml @@ -0,0 +1,10 @@ +langcode: en +status: true +dependencies: + module: + - media_entity +id: media_reset_thumbnail_action +label: 'Reset media thumbnail' +type: media +plugin: media_reset_thumbnail_action +configuration: { } diff --git a/src/Plugin/Action/ResetMediaThumbnail.php b/src/Plugin/Action/ResetMediaThumbnail.php new file mode 100644 index 0000000..632260d --- /dev/null +++ b/src/Plugin/Action/ResetMediaThumbnail.php @@ -0,0 +1,38 @@ +automaticallySetThumbnail(); + // We need to change at least one value, otherwise the changed timestamp + // will not be updated. + $entity->changed = 0; + $entity->save(); + } + + /** + * {@inheritdoc} + */ + public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { + /** @var \Drupal\media_entity\MediaInterface $object */ + return $object->access('update', $account, $return_as_object); + } + +}