Updating Media dependent modules to versions compatible with core Media.
[yaffs-website] / web / modules / contrib / media_entity_actions / src / Plugin / Action / SaveMedia.php
1 <?php
2
3 namespace Drupal\media_entity_actions\Plugin\Action;
4
5 use Drupal\Core\Action\ActionBase;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\media\MediaInterface;
8
9 /**
10  * Saves a media item.
11  *
12  * @Action(
13  *   id = "media_save_action",
14  *   label = @Translation("Save media"),
15  *   type = "media"
16  * )
17  */
18 class SaveMedia extends ActionBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function execute(MediaInterface $entity = NULL) {
24     if ($entity) {
25       // We need to change at least one value, otherwise the changed timestamp
26       // will not be updated.
27       $entity->setChangedTime(0)->save();
28     }
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
35     /** @var \Drupal\media\MediaInterface $object */
36     return $object->access('update', $account, $return_as_object);
37   }
38
39 }