Added block for adding cases to actors

This commit is contained in:
2022-07-07 12:50:02 +01:00
parent 03c826087a
commit 2b4b9696db
3 changed files with 80 additions and 4 deletions
modules/opencase_cases/src/Form
opencase.module
src/Plugin/Block

@ -36,7 +36,7 @@ class OCCaseForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
public function save(array $form, FormStateInterface $form_state): void {
$entity = $this->entity;
$entity->setNewRevision();
$entity->setRevisionCreationTime(REQUEST_TIME);
@ -57,7 +57,7 @@ class OCCaseForm extends ContentEntityForm {
]));
}
// If you have unpublished the entity and you can't see unpublished entities, redirect to a more informative message than just "Access Denied".
if (!$form_state->getValue('status')['value'] && !\Drupal::currentUser()->hasPermission('view unpublished case entities')) {
if (!$this->isPublished($form_state) && !\Drupal::currentUser()->hasPermission('view unpublished case entities')) {
\Drupal::messenger()->addMessage($this->t('The record for "%label" is now unpublished & hidden from you.', [
'%label' => $entity->label(),
]));
@ -67,4 +67,12 @@ class OCCaseForm extends ContentEntityForm {
}
}
private function isPublished(FormStateInterface $form_state): bool {
if (is_null($form_state->getValue('status'))) {
return false; // some entities have nothing set for the status in which case we want to treat them as published by default.
// TODO why don't they??
}
return $form_state->getValue('status')['value'];
}
}