Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CrmCaseTypeForm | |
0.00% |
0 / 39 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| form | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
| actions | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| save | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\crm_case\Form; |
| 4 | |
| 5 | use Drupal\Core\Entity\BundleEntityFormBase; |
| 6 | use Drupal\Core\Entity\EntityTypeInterface; |
| 7 | use Drupal\Core\Form\FormStateInterface; |
| 8 | |
| 9 | /** |
| 10 | * Form handler for crm case type forms. |
| 11 | */ |
| 12 | class CrmCaseTypeForm extends BundleEntityFormBase { |
| 13 | |
| 14 | /** |
| 15 | * {@inheritdoc} |
| 16 | */ |
| 17 | public function form(array $form, FormStateInterface $form_state) { |
| 18 | $form = parent::form($form, $form_state); |
| 19 | |
| 20 | $entity_type = $this->entity; |
| 21 | if ($this->operation == 'edit') { |
| 22 | $form['#title'] = $this->t('Edit %label crm case type', ['%label' => $entity_type->label()]); |
| 23 | } |
| 24 | |
| 25 | $form['label'] = [ |
| 26 | '#title' => $this->t('Label'), |
| 27 | '#type' => 'textfield', |
| 28 | '#default_value' => $entity_type->label(), |
| 29 | '#description' => $this->t('The human-readable name of this crm case type.'), |
| 30 | '#required' => TRUE, |
| 31 | '#size' => 30, |
| 32 | ]; |
| 33 | |
| 34 | $form['id'] = [ |
| 35 | '#type' => 'machine_name', |
| 36 | '#default_value' => $entity_type->id(), |
| 37 | '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, |
| 38 | '#machine_name' => [ |
| 39 | 'exists' => ['Drupal\crm_case\Entity\CrmCaseType', 'load'], |
| 40 | 'source' => ['label'], |
| 41 | ], |
| 42 | '#description' => $this->t('A unique machine-readable name for this crm case type. It must only contain lowercase letters, numbers, and underscores.'), |
| 43 | ]; |
| 44 | |
| 45 | return $this->protectBundleIdElement($form); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * {@inheritdoc} |
| 50 | */ |
| 51 | protected function actions(array $form, FormStateInterface $form_state) { |
| 52 | $actions = parent::actions($form, $form_state); |
| 53 | $actions['submit']['#value'] = $this->t('Save crm case type'); |
| 54 | $actions['delete']['#value'] = $this->t('Delete crm case type'); |
| 55 | return $actions; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * {@inheritdoc} |
| 60 | */ |
| 61 | public function save(array $form, FormStateInterface $form_state) { |
| 62 | $entity_type = $this->entity; |
| 63 | |
| 64 | $entity_type->set('id', trim($entity_type->id())); |
| 65 | $entity_type->set('label', trim($entity_type->label())); |
| 66 | |
| 67 | $status = $entity_type->save(); |
| 68 | |
| 69 | $t_args = ['%name' => $entity_type->label()]; |
| 70 | if ($status == SAVED_UPDATED) { |
| 71 | $message = $this->t('The crm case type %name has been updated.', $t_args); |
| 72 | } |
| 73 | elseif ($status == SAVED_NEW) { |
| 74 | $message = $this->t('The crm case type %name has been added.', $t_args); |
| 75 | } |
| 76 | $this->messenger()->addStatus($message); |
| 77 | |
| 78 | $form_state->setRedirectUrl($entity_type->toUrl('collection')); |
| 79 | |
| 80 | return $status; |
| 81 | } |
| 82 | |
| 83 | } |