I am trying to create a custom action with Configuration Form Field . I am able to create Action and it is being displayed on content page ( /admin/content
) , but I am not able to find the path to configure the fields in the Action Plugin.Can anyone please let me know the path to configure the Action Plugin ?
My Code as follows :
UpdateNodeTitle.php
namespace Drupal\action_plugin_examples\Plugin\Action;
use Drupal\Core\Action\ConfigurableActionBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Provides a an Update node title action.
*
* @Action(
* id = "action_plugin_examples_update_node_title",
* label = @Translation("Update node title"),
* type = "node",
* category = @Translation("Custom")
* )
*
*/
class UpdateNodeTitle extends ConfigurableActionBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return ['title' => ''];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['title'] = [
'#title' => $this->t('New title'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $this->configuration['title'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['title'] = $form_state->getValue('title');
}
/**
* {@inheritdoc}
*/
public function access($node, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\node\NodeInterface $node */
$access = $node->access('update', $account, TRUE)
->andIf($node->title->access('edit', $account, TRUE));
return $return_as_object ? $access : $access->isAllowed();
}
/**
* {@inheritdoc}
*/
public function execute($node = NULL) {
/** @var \Drupal\node\NodeInterface $node */
$node->setTitle($this->configuration['title'])->save();
}
}
action_plugin_examples.schema.yml
action_plugin_examples.configuration.action_plugin_examples_update_node_title:
type: mapping
label: 'Configuration for "Update node title" action'
mapping:
title:
type: string
label: Title
system.action.action_plugin_examples_update_node_title.yml
langcode: en
status: true
dependencies:
enforced:
module:
- action_plugin_examples
module:
- node
- pathauto
id: action_plugin_examples_update_node_title
label: 'Update Node Title'
type: node
plugin: action_plugin_examples_update_node_title
configuration: { }
I have seen a similar Action Plugin in core as well but can not find the path to configure the Plugin. AssignOwnerNode Another Contributed module with similar functionality custom pub