Added Event entity type.

This commit is contained in:
2021-01-28 10:22:20 +00:00
parent 53648faff7
commit b48ba012cb
36 changed files with 1353 additions and 0 deletions

View File

@ -0,0 +1,51 @@
<?php
namespace Drupal\opencase\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Builds the form to delete Event entities.
*/
class OCEventDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.oc_event.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
$this->messenger()->addMessage(
$this->t('content @type: deleted @label.', [
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label(),
])
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}

65
src/Form/OCEventForm.php Normal file
View File

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