Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Issue #2869239 : Action to refresh the thumbnail #84

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions config/install/system.action.media_reset_thumbnail_action.yml
Original file line number Diff line number Diff line change
@@ -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: { }
38 changes: 38 additions & 0 deletions src/Plugin/Action/ResetMediaThumbnail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Drupal\media_entity\Plugin\Action;

use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;

/**
* Provides an action to reset the thumbnail on a media entity.
*
* @Action(
* id = "media_reset_thumbnail_action",
* label = @Translation("Reset media thumbnail"),
* type = "media"
* )
*/
class ResetMediaThumbnail extends ActionBase {

/**
* {@inheritdoc}
*/
public function execute($entity = NULL) {
$entity->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);
}

}