-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathReactionRuleAddForm.php
More file actions
90 lines (75 loc) · 2.25 KB
/
ReactionRuleAddForm.php
File metadata and controls
90 lines (75 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @file
* Contains \Drupal\rules\Form\ReactionRuleAddForm.
*/
namespace Drupal\rules\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\rules\Core\RulesEventManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form to add a reaction rule.
*/
class ReactionRuleAddForm extends RulesComponentFormBase {
/**
* The Rules event manager.
*
* @var \Drupal\rules\Core\RulesEventManager
*/
protected $eventManager;
/**
* Constructs a new reaction rule form.
*
* @param \Drupal\rules\Core\RulesEventManager $event_manager
* The Rules event manager.
*/
public function __construct(RulesEventManager $event_manager) {
$this->eventManager = $event_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.rules_event')
);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->t('Save');
return $actions;
}
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$event_definitions = $this->eventManager->getGroupedDefinitions();
$options = [];
foreach ($event_definitions as $group => $definitions) {
foreach ($definitions as $id => $definition) {
$options[$group][$id] = $definition['label'];
}
}
$form['events']['#tree'] = TRUE;
$form['events'][]['event_name'] = [
'#type' => 'select',
'#title' => $this->t('React on event'),
'#options' => $options,
'#required' => TRUE,
'#description' => $this->t('Whenever the event occurs, rule evaluation is triggered.'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
drupal_set_message($this->t('Reaction rule %label has been created.', ['%label' => $this->entity->label()]));
$form_state->setRedirect('entity.rules_reaction_rule.edit_form', ['rules_reaction_rule' => $this->entity->id()]);
}
}