1. 8.3.x core/modules/action/src/Form/ActionAdminManageForm.php
  2. 8.0.x core/modules/action/src/Form/ActionAdminManageForm.php
  3. 8.1.x core/modules/action/src/Form/ActionAdminManageForm.php
  4. 8.2.x core/modules/action/src/Form/ActionAdminManageForm.php
  5. 8.4.x core/modules/action/src/Form/ActionAdminManageForm.php

Namespace

Drupal\action\Form

File

core/modules/action/src/Form/ActionAdminManageForm.php
View source
  1. <?php
  2. namespace Drupal\action\Form;
  3. use Drupal\Core\Form\FormBase;
  4. use Drupal\Component\Utility\Crypt;
  5. use Drupal\Core\Action\ActionManager;
  6. use Drupal\Core\Form\FormStateInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. /**
  9. * Provides a configuration form for configurable actions.
  10. */
  11. class ActionAdminManageForm extends FormBase {
  12. /**
  13. * The action plugin manager.
  14. *
  15. * @var \Drupal\Core\Action\ActionManager
  16. */
  17. protected $manager;
  18. /**
  19. * Constructs a new ActionAdminManageForm.
  20. *
  21. * @param \Drupal\Core\Action\ActionManager $manager
  22. * The action plugin manager.
  23. */
  24. public function __construct(ActionManager $manager) {
  25. $this->manager = $manager;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function create(ContainerInterface $container) {
  31. return new static(
  32. $container->get('plugin.manager.action')
  33. );
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function getFormId() {
  39. return 'action_admin_manage';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function buildForm(array $form, FormStateInterface $form_state) {
  45. $actions = array();
  46. foreach ($this->manager->getDefinitions() as $id => $definition) {
  47. if (is_subclass_of($definition['class'], '\Drupal\Core\Plugin\PluginFormInterface')) {
  48. $key = Crypt::hashBase64($id);
  49. $actions[$key] = $definition['label'] . '...';
  50. }
  51. }
  52. $form['parent'] = array(
  53. '#type' => 'details',
  54. '#title' => $this->t('Create an advanced action'),
  55. '#attributes' => array('class' => array('container-inline')),
  56. '#open' => TRUE,
  57. );
  58. $form['parent']['action'] = array(
  59. '#type' => 'select',
  60. '#title' => $this->t('Action'),
  61. '#title_display' => 'invisible',
  62. '#options' => $actions,
  63. '#empty_option' => $this->t('Choose an advanced action'),
  64. );
  65. $form['parent']['actions'] = array(
  66. '#type' => 'actions'
  67. );
  68. $form['parent']['actions']['submit'] = array(
  69. '#type' => 'submit',
  70. '#value' => $this->t('Create'),
  71. );
  72. return $form;
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function submitForm(array &$form, FormStateInterface $form_state) {
  78. if ($form_state->getValue('action')) {
  79. $form_state->setRedirect(
  80. 'action.admin_add',
  81. array('action_id' => $form_state->getValue('action'))
  82. );
  83. }
  84. }
  85. }

Classes

Namesort descending Description
ActionAdminManageForm Provides a configuration form for configurable actions.