Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CrmCaseEncounterForm | |
0.00% |
0 / 49 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
form | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
6 | |||
save | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Drupal\crm_case\Form; |
4 | |
5 | use Drupal\Core\Entity\EntityForm; |
6 | use Drupal\Core\Form\FormStateInterface; |
7 | |
8 | /** |
9 | * Encounter form. |
10 | * |
11 | * @property \Drupal\crm_case\CrmCaseEncounterInterface $entity |
12 | */ |
13 | class CrmCaseEncounterForm extends EntityForm { |
14 | |
15 | /** |
16 | * {@inheritdoc} |
17 | */ |
18 | public function form(array $form, FormStateInterface $form_state) { |
19 | |
20 | $form = parent::form($form, $form_state); |
21 | |
22 | $form['label'] = [ |
23 | '#type' => 'textfield', |
24 | '#title' => $this->t('Label'), |
25 | '#maxlength' => 255, |
26 | '#default_value' => $this->entity->label(), |
27 | '#description' => $this->t('Label for the encounter.'), |
28 | '#required' => TRUE, |
29 | ]; |
30 | |
31 | $form['id'] = [ |
32 | '#type' => 'machine_name', |
33 | '#default_value' => $this->entity->id(), |
34 | '#machine_name' => [ |
35 | 'exists' => '\Drupal\crm_case\Entity\CrmCaseEncounter::load', |
36 | ], |
37 | '#disabled' => !$this->entity->isNew(), |
38 | ]; |
39 | |
40 | $form['status'] = [ |
41 | '#type' => 'checkbox', |
42 | '#title' => $this->t('Enabled'), |
43 | '#default_value' => $this->entity->isNew() ? TRUE : $this->entity->status(), |
44 | ]; |
45 | |
46 | $form['weight'] = [ |
47 | '#type' => 'number', |
48 | '#title' => $this->t('Weight'), |
49 | '#default_value' => $this->entity->get('weight') ?? 0, |
50 | '#description' => $this->t('Weight of the encounter.'), |
51 | ]; |
52 | |
53 | $form['default'] = [ |
54 | '#type' => 'checkbox', |
55 | '#title' => $this->t('Default'), |
56 | '#default_value' => $this->entity->get('default'), |
57 | '#description' => $this->t('Default encounter.'), |
58 | ]; |
59 | |
60 | $form['description'] = [ |
61 | '#type' => 'textarea', |
62 | '#title' => $this->t('Description'), |
63 | '#default_value' => $this->entity->get('description'), |
64 | '#description' => $this->t('Description of the encounter.'), |
65 | ]; |
66 | |
67 | return $form; |
68 | } |
69 | |
70 | /** |
71 | * {@inheritdoc} |
72 | */ |
73 | public function save(array $form, FormStateInterface $form_state) { |
74 | $result = parent::save($form, $form_state); |
75 | $message_args = ['%label' => $this->entity->label()]; |
76 | $message = $result == SAVED_NEW |
77 | ? $this->t('Created new encounter %label.', $message_args) |
78 | : $this->t('Updated encounter %label.', $message_args); |
79 | $this->messenger()->addStatus($message); |
80 | $form_state->setRedirectUrl($this->entity->toUrl('collection')); |
81 | return $result; |
82 | } |
83 | |
84 | } |