This repository has been archived on 2022-07-12. You can view files and clone it, but cannot push or open issues or pull requests.
opencase/modules/opencase_reporting/src/Form/OpenCaseReportForm.php

66 lines
1.6 KiB
PHP

<?php
namespace Drupal\opencase_reporting\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Class OpenCaseReportForm.
*/
class OpenCaseReportForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$opencase_report = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $opencase_report->label(),
'#description' => $this->t("Label for the OpenCase Report."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $opencase_report->id(),
'#machine_name' => [
'exists' => '\Drupal\opencase_reporting\Entity\OpenCaseReport::load',
],
'#disabled' => !$opencase_report->isNew(),
];
/* You will need additional form elements for your custom properties. */
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$opencase_report = $this->entity;
$status = $opencase_report->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label OpenCase Report.', [
'%label' => $opencase_report->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label OpenCase Report.', [
'%label' => $opencase_report->label(),
]));
}
$form_state->setRedirectUrl($opencase_report->toUrl('collection'));
}
}