d223babae95a3636639ae6b23e8d97654bbe8cf6
[yaffs-website] / web / modules / contrib / media_entity / src / Plugin / Action / PublishMedia.php
1 <?php
2
3 namespace Drupal\media_entity\Plugin\Action;
4
5 use Drupal\Core\Action\ActionBase;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\media_entity\Entity\Media;
8
9 /**
10  * Publishes a media entity.
11  *
12  * @Action(
13  *   id = "media_publish_action",
14  *   label = @Translation("Publish media"),
15  *   type = "media"
16  * )
17  */
18 class PublishMedia extends ActionBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function execute(Media $entity = NULL) {
24     $entity->setPublished(TRUE)->save();
25   }
26
27   /**
28    * {@inheritdoc}
29    */
30   public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
31     /** @var \Drupal\media_entity\MediaInterface $object */
32     $result = $object->access('update', $account, TRUE)
33       ->andIf($object->status->access('edit', $account, TRUE));
34
35     return $return_as_object ? $result : $result->isAllowed();
36   }
37
38 }