broke something
This commit is contained in:
parent
07683cd1b8
commit
ccbac9473b
@ -179,8 +179,8 @@ function opencase_entity_field_access($operation, \Drupal\Core\Field\FieldDefini
|
||||
/*
|
||||
Custom hook
|
||||
*/
|
||||
function opencase_relevant_case_type_ids(string $actorTypeID):array {
|
||||
switch ($actorTypeID) {
|
||||
function opencase_relevant_case_type_ids(string $bundle):array {
|
||||
switch ($bundle) {
|
||||
case 'client':
|
||||
return ['accommodation', 'asylum_support', 'employability', 'health', 'immigration', 'welfare_rights'];
|
||||
case 'volunteer':
|
||||
@ -193,14 +193,24 @@ function opencase_relevant_case_type_ids(string $actorTypeID):array {
|
||||
/*
|
||||
Custom hook
|
||||
*/
|
||||
function opencase_relevant_activity_type_ids(string $actorTypeID):array {
|
||||
switch ($actorTypeID) {
|
||||
case 'volunteer':
|
||||
return ['email', 'phone_call', 'supervision'];
|
||||
case 'client':
|
||||
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
||||
case 'staff_member':
|
||||
return ['application', 'interview'];
|
||||
function opencase_relevant_activity_type_ids(string $entityType, string $bundle):array {
|
||||
if ($entityType == 'oc_actor') {
|
||||
switch ($bundle) {
|
||||
case 'volunteer':
|
||||
return ['email', 'phone_call', 'supervision', 'application', 'interview'];
|
||||
case 'client':
|
||||
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
||||
case 'staff_member':
|
||||
return ['application', 'interview'];
|
||||
}
|
||||
}
|
||||
if ($entityType == 'oc_case') {
|
||||
switch ($bundle) {
|
||||
case 'volunteer_engagement':
|
||||
return ['email', 'phone_call', 'supervision', 'application', 'interview'];
|
||||
default:
|
||||
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
@ -3,12 +3,14 @@
|
||||
namespace Drupal\opencase\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\opencase_cases\Entity\OCCase;
|
||||
use Drupal\opencase_entities\Entity\OCActor;
|
||||
|
||||
/**
|
||||
* Provides a Block with some help text about actor type fields
|
||||
*
|
||||
* @Block(
|
||||
* id = "add_activity",
|
||||
* activity_type = "add_activity",
|
||||
* admin_label = @Translation("Add Activity"),
|
||||
* category = @Translation("Opencase"),
|
||||
* )
|
||||
@ -19,28 +21,57 @@ class AddActivity extends BlockBase {
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build():array {
|
||||
if ($this->isOnACase()) {
|
||||
return $this->makeBlockForAddingActivityToCase();
|
||||
} elseif ($this->isOnAnActor()) {
|
||||
return $this->makeBlockForAddingActivityToActor();
|
||||
}
|
||||
return ['#markup' => 'This block should only be placed on a case or on an actor.'];
|
||||
}
|
||||
|
||||
private function makeBlockForAddingActivityToCase():array {
|
||||
$case = \Drupal::routeMatch()->getParameter('oc_case');
|
||||
$case_id = $case->id();
|
||||
$markup = "<ul>";
|
||||
$bundles = $this->getActivityBundlesFor('oc_case', $case->bundle());
|
||||
foreach($bundles as $bundle => $info) {
|
||||
$label = $info['label'];
|
||||
$markup .= "<li><a href='/opencase/oc_activity/add/$bundle?case_id=$case_id&destination=/opencase/oc_case/$case_id'>$label</a></li>";
|
||||
}
|
||||
$markup .= "</ul>";
|
||||
return array('#markup' => $markup);
|
||||
}
|
||||
private function makeBlockForAddingActivityToActor():array {
|
||||
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
||||
$target_id = $actor->id();
|
||||
$actorType = $actor->bundle();
|
||||
$markup = "<ul>";
|
||||
$activity_types = $this->getActivityTypesToDisplay($actorType);
|
||||
foreach($activity_types as $id => $info) {
|
||||
$bundles = $this->getActivityBundlesFor('oc_actor', $actor->bundle());
|
||||
foreach($bundles as $bundle => $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 .= "<li><a href='/opencase/oc_activity/add/$bundle?target_id=$target_id&destination=/opencase/oc_actor/$target_id'>$label</a></li>";
|
||||
}
|
||||
$markup .= "</ul>";
|
||||
return array('#markup' => $markup);
|
||||
}
|
||||
|
||||
private function isOnACase():bool {
|
||||
return \Drupal::routeMatch()->getParameter('oc_case') instanceof OCCase;
|
||||
}
|
||||
|
||||
private function isOnAnActor():bool {
|
||||
return \Drupal::routeMatch()->getParameter('oc_actor') instanceof OCActor;
|
||||
}
|
||||
|
||||
|
||||
public function getCacheMaxAge():int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function getActivityTypesToDisplay(string $actorType): array {
|
||||
private function getActivityBundlesFor(string $entityType, string $bundle): array {
|
||||
// Client modules will provide a list of what activity types (bundles) are relevant for each actor type.
|
||||
// Check if they are implemented, and if so display them.
|
||||
$implemented_activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
||||
$relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$actorType]);
|
||||
$relevant_activity_type_ids = \Drupal::moduleHandler()->invokeAll('relevant_activity_type_ids', [$entityType, $bundle]);
|
||||
$activity_types_to_display = [];
|
||||
foreach ($relevant_activity_type_ids as $type_id) {
|
||||
if (array_key_exists($type_id, $implemented_activity_types)) {
|
||||
|
Reference in New Issue
Block a user