Added block for adding activities
This commit is contained in:
parent
4a222153af
commit
ae7c333179
@ -156,11 +156,14 @@ function _opencase_cases_redirect_to_home($form, &$form_state) {
|
||||
|
||||
// Upon deletion of an activity, go to the related case if there is one, otherwise to its target.
|
||||
function _opencase_cases_delete_activity_redirect($form, &$form_state) {
|
||||
if (!IsEmpty($form_state->getFormObject()->getEntity()->oc_case)) {
|
||||
$case_id = $form_state->getFormObject()->getEntity()->oc_case->target_id;
|
||||
$entity = $form_state->getFormObject()->getEntity();
|
||||
// for some reason this fires when deleting an activity type, shouldn't do but.s
|
||||
if ($entity instanceof \Drupal\opencase_entities\Entity\OCActivityType) return;
|
||||
if (!IsEmpty($entity->oc_case)) {
|
||||
$case_id = $entity->oc_case->target_id;
|
||||
$form_state->setRedirect('entity.oc_case.canonical', ['oc_case' => $case_id]);
|
||||
} else {
|
||||
$target_actor_id = $form_state->getFormObject()->getEntity()->oc_target->target_id;
|
||||
$target_actor_id = $entity->oc_target->target_id;
|
||||
$form_state->setRedirect('entity.oc_actor.canonical', ['oc_actor' => $target_actor_id]);
|
||||
}
|
||||
}
|
||||
|
37
src/Plugin/Block/AddActivity.php
Normal file
37
src/Plugin/Block/AddActivity.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\opencase\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a Block with some help text about actor type fields
|
||||
*
|
||||
* @Block(
|
||||
* id = "add_activity",
|
||||
* admin_label = @Translation("Add Activity"),
|
||||
* category = @Translation("Opencase"),
|
||||
* )
|
||||
*/
|
||||
class AddActivity extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build():array {
|
||||
$target_id = \Drupal::routeMatch()->getParameter('oc_actor')->id();
|
||||
$activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||
$markup = "<ul>";
|
||||
foreach($activity_types as $id => $info) {
|
||||
$label = $info['label'];
|
||||
$markup .= "<li><a href='/opencase/oc_activity/add/$id?target_id=$target_id&destination=/opencase/oc_actor/$target_id'>$label</a></li>";
|
||||
}
|
||||
$markup .= "</ul>";
|
||||
return array('#markup' => $markup);
|
||||
}
|
||||
|
||||
public function getCacheMaxAge():int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user