3 namespace Drupal\{{ machine_name }}\Plugin\Action;
6 use Drupal\Core\Action\ConfigurableActionBase;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Core\Session\AccountInterface;
10 use Drupal\Core\Action\ActionBase;
11 use Drupal\Core\Session\AccountInterface;
15 * Provides a {{ plugin_label|article }} action.
18 * id = "{{ plugin_id }}",
19 * label = @Translation("{{ plugin_label }}"),
21 * category = @Translation("{{ category }}")
25 * For simple updating entity fields consider extending FieldUpdateActionBase.
27 class {{ class }} extends {{ configurable ? 'ConfigurableActionBase' : 'ActionBase' }} {
33 public function defaultConfiguration() {
34 return ['title' => ''];
40 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
42 '#title' => t('New title'),
43 '#type' => 'textfield',
45 '#default_value' => $this->configuration['title'],
53 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
54 $this->configuration['title'] = $form_state->getValue('title');
61 public function access($node, AccountInterface $account = NULL, $return_as_object = FALSE) {
62 /** @var \Drupal\node\NodeInterface $node */
63 $access = $node->access('update', $account, TRUE)
64 ->andIf($node->title->access('edit', $account, TRUE));
65 return $return_as_object ? $access : $access->isAllowed();
71 public function execute($node = NULL) {
72 /** @var \Drupal\node\NodeInterface $node */
74 $node->setTitle($this->configuration['title'])->save();
76 $node->setTitle(t('New title'))->save();