comparison core/modules/node/src/Plugin/Action/SaveNode.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\node\Plugin\Action;
4
5 use Drupal\Core\Action\ActionBase;
6 use Drupal\Core\Session\AccountInterface;
7
8 /**
9 * Provides an action that can save any entity.
10 *
11 * @Action(
12 * id = "node_save_action",
13 * label = @Translation("Save content"),
14 * type = "node"
15 * )
16 */
17 class SaveNode extends ActionBase {
18
19 /**
20 * {@inheritdoc}
21 */
22 public function execute($entity = NULL) {
23 // We need to change at least one value, otherwise the changed timestamp
24 // will not be updated.
25 $entity->changed = 0;
26 $entity->save();
27 }
28
29 /**
30 * {@inheritdoc}
31 */
32 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
33 /** @var \Drupal\node\NodeInterface $object */
34 return $object->access('update', $account, $return_as_object);
35 }
36
37 }