1<?php 2 3namespace Drupal\action_test\Plugin\Action; 4 5use Drupal\Core\Action\ActionBase; 6use Drupal\Core\Session\AccountInterface; 7 8/** 9 * Provides an operation to save user entities. 10 * 11 * @Action( 12 * id = "action_test_save_entity", 13 * label = @Translation("Saves entities"), 14 * type = "user" 15 * ) 16 */ 17class SaveEntity extends ActionBase { 18 19 /** 20 * {@inheritdoc} 21 */ 22 public function execute($entity = NULL) { 23 $entity->save(); 24 } 25 26 /** 27 * {@inheritdoc} 28 */ 29 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { 30 /** @var \Drupal\Core\Entity\EntityInterface $object */ 31 return $object->access('update', $account, $return_as_object); 32 } 33 34} 35