Drupal Answers Asked on October 26, 2021
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 Drupalaction_plugin_examplesPluginAction;
use DrupalCoreActionConfigurableActionBase;
use DrupalCoreFormFormStateInterface;
use DrupalCoreSessionAccountInterface;
/**
* 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 DrupalnodeNodeInterface $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 DrupalnodeNodeInterface $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
You need to install the core module Actions first to be able to configure action plugins in UI.
Then you can access the actions overview page:
/admin/config/system/actions
On the top of the page your new plugin should be present in the select list for creating advanced actions. When you select the plugin you should see the configuration form of your plugin:
/admin/config/system/actions/add/action_plugin_examples_update_node_title
Since you have already provided an action configuration in a YAML file you should also see a configured instance of your plugin in the available actions list.
Answered by 4k4 on October 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP