3 namespace Drupal\action\Form;
5 use Drupal\Core\Form\FormBase;
6 use Drupal\Component\Utility\Crypt;
7 use Drupal\Core\Action\ActionManager;
8 use Drupal\Core\Form\FormStateInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Provides a configuration form for configurable actions.
14 class ActionAdminManageForm extends FormBase {
17 * The action plugin manager.
19 * @var \Drupal\Core\Action\ActionManager
24 * Constructs a new ActionAdminManageForm.
26 * @param \Drupal\Core\Action\ActionManager $manager
27 * The action plugin manager.
29 public function __construct(ActionManager $manager) {
30 $this->manager = $manager;
36 public static function create(ContainerInterface $container) {
38 $container->get('plugin.manager.action')
45 public function getFormId() {
46 return 'action_admin_manage';
52 public function buildForm(array $form, FormStateInterface $form_state) {
54 foreach ($this->manager->getDefinitions() as $id => $definition) {
55 if (is_subclass_of($definition['class'], '\Drupal\Core\Plugin\PluginFormInterface')) {
56 $key = Crypt::hashBase64($id);
57 $actions[$key] = $definition['label'] . '...';
62 '#title' => $this->t('Create an advanced action'),
63 '#attributes' => ['class' => ['container-inline']],
66 $form['parent']['action'] = [
68 '#title' => $this->t('Action'),
69 '#title_display' => 'invisible',
70 '#options' => $actions,
71 '#empty_option' => $this->t('Choose an advanced action'),
73 $form['parent']['actions'] = [
76 $form['parent']['actions']['submit'] = [
78 '#value' => $this->t('Create'),
86 public function submitForm(array &$form, FormStateInterface $form_state) {
87 if ($form_state->getValue('action')) {
88 $form_state->setRedirect(
90 ['action_id' => $form_state->getValue('action')]