-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathReactionRuleEditForm.php
More file actions
117 lines (100 loc) · 3.07 KB
/
ReactionRuleEditForm.php
File metadata and controls
117 lines (100 loc) · 3.07 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
/**
* @file
* Contains \Drupal\rules\Form\ReactionRuleEditForm.
*/
namespace Drupal\rules\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\rules\Core\RulesEventManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form to edit a reaction rule.
*/
class ReactionRuleEditForm extends RulesComponentFormBase {
use TempStoreTrait;
/**
* The event plugin manager.
*
* @var \Drupal\rules\Core\RulesEventManager
*/
protected $eventManager;
/**
* Constructs a new object of this class.
*
* @param \Drupal\rules\Core\RulesEventManager $event_manager
* The event plugin 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}
*/
public function form(array $form, FormStateInterface $form_state) {
$this->addLockInformation($form);
foreach ($this->entity->getEvents() as $key => $event) {
$event_definition = $this->eventManager->getDefinition($event['event_name']);
$form['event'][$key] = [
'#type' => 'item',
'#title' => $this->t('Events') . ':',
'#markup' => $this->t('@label (@name)', [
'@label' => $event_definition['label'],
'@name' => $event['event_name'],
]),
];
}
$form_handler = $this->entity->getExpression()->getFormHandler();
$form = $form_handler->form($form, $form_state);
return parent::form($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$actions['submit']['#value'] = $this->t('Save');
$actions['cancel'] = [
'#type' => 'submit',
'#value' => $this->t('Cancel'),
'#submit' => ['::cancel'],
];
return $actions;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
// Also remove the temporarily stored rule, it has been persisted now.
$this->deleteFromTempStore();
drupal_set_message($this->t('Reaction rule %label has been updated.', ['%label' => $this->entity->label()]));
}
/**
* Form submission handler for the 'cancel' action.
*/
public function cancel(array $form, FormStateInterface $form_state) {
$this->deleteFromTempStore();
drupal_set_message($this->t('Canceled.'));
$form_state->setRedirect('entity.rules_reaction_rule.collection');
}
/**
* Title callback: also display the rule label.
*/
public function getTitle($rules_reaction_rule) {
return $this->t('Edit reaction rule "@label"', ['@label' => $rules_reaction_rule->label()]);
}
/**
* Returns the entity object, which is the rules config on this class.
*
* @see \Drupal\rules\Form\TempStoreTrait
*/
protected function getRuleConfig() {
return $this->entity;
}
}