ActionAdminManageForm.php in Drupal 10
File
core/modules/action/src/Form/ActionAdminManageForm.php
View source
<?php
namespace Drupal\action\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Action\ActionManager;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ActionAdminManageForm extends FormBase {
protected $manager;
public function __construct(ActionManager $manager) {
$this->manager = $manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.action'));
}
public function getFormId() {
return 'action_admin_manage';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$actions = [];
foreach ($this->manager
->getDefinitions() as $id => $definition) {
if (is_subclass_of($definition['class'], '\\Drupal\\Core\\Plugin\\PluginFormInterface')) {
$actions[$id] = $definition['label'];
}
}
asort($actions);
$form['parent'] = [
'#type' => 'details',
'#title' => $this
->t('Create an advanced action'),
'#attributes' => [
'class' => [
'container-inline',
],
],
'#open' => TRUE,
];
$form['parent']['action'] = [
'#type' => 'select',
'#title' => $this
->t('Action'),
'#title_display' => 'invisible',
'#options' => $actions,
'#empty_option' => $this
->t('- Select -'),
];
$form['parent']['actions'] = [
'#type' => 'actions',
];
$form['parent']['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Create'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('action')) {
$form_state
->setRedirect('action.admin_add', [
'action_id' => $form_state
->getValue('action'),
]);
}
}
}