1. 8.2.x core/modules/action/src/ActionAddForm.php
  2. 8.0.x core/modules/action/src/ActionAddForm.php
  3. 8.1.x core/modules/action/src/ActionAddForm.php
  4. 8.3.x core/modules/action/src/ActionAddForm.php

Namespace

Drupal\action

File

core/modules/action/src/ActionAddForm.php
View source
  1. <?php
  2. namespace Drupal\action;
  3. use Drupal\Component\Utility\Crypt;
  4. use Drupal\Core\Action\ActionManager;
  5. use Drupal\Core\Entity\EntityStorageInterface;
  6. use Drupal\Core\Form\FormStateInterface;
  7. use Symfony\Component\DependencyInjection\ContainerInterface;
  8. /**
  9. * Provides a form for action add forms.
  10. */
  11. class ActionAddForm extends ActionFormBase {
  12. /**
  13. * The action manager.
  14. *
  15. * @var \Drupal\Core\Action\ActionManager
  16. */
  17. protected $actionManager;
  18. /**
  19. * Constructs a new ActionAddForm.
  20. *
  21. * @param \Drupal\Core\Entity\EntityStorageInterface $storage
  22. * The action storage.
  23. * @param \Drupal\Core\Action\ActionManager $action_manager
  24. * The action plugin manager.
  25. */
  26. public function __construct(EntityStorageInterface $storage, ActionManager $action_manager) {
  27. parent::__construct($storage);
  28. $this->actionManager = $action_manager;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function create(ContainerInterface $container) {
  34. return new static(
  35. $container->get('entity.manager')->getStorage('action'),
  36. $container->get('plugin.manager.action')
  37. );
  38. }
  39. /**
  40. * {@inheritdoc}
  41. *
  42. * @param string $action_id
  43. * The hashed version of the action ID.
  44. */
  45. public function buildForm(array $form, FormStateInterface $form_state, $action_id = NULL) {
  46. // In \Drupal\action\Form\ActionAdminManageForm::buildForm() the action
  47. // are hashed. Here we have to decrypt it to find the desired action ID.
  48. foreach ($this->actionManager->getDefinitions() as $id => $definition) {
  49. $key = Crypt::hashBase64($id);
  50. if ($key === $action_id) {
  51. $this->entity->setPlugin($id);
  52. // Derive the label and type from the action definition.
  53. $this->entity->set('label', $definition['label']);
  54. $this->entity->set('type', $definition['type']);
  55. break;
  56. }
  57. }
  58. return parent::buildForm($form, $form_state);
  59. }
  60. }

Classes

Namesort descending Description
ActionAddForm Provides a form for action add forms.