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
|
Custom hook
|
||||||
*/
|
*/
|
||||||
function opencase_relevant_case_type_ids(string $actorTypeID):array {
|
function opencase_relevant_case_type_ids(string $bundle):array {
|
||||||
switch ($actorTypeID) {
|
switch ($bundle) {
|
||||||
case 'client':
|
case 'client':
|
||||||
return ['accommodation', 'asylum_support', 'employability', 'health', 'immigration', 'welfare_rights'];
|
return ['accommodation', 'asylum_support', 'employability', 'health', 'immigration', 'welfare_rights'];
|
||||||
case 'volunteer':
|
case 'volunteer':
|
||||||
@ -193,15 +193,25 @@ function opencase_relevant_case_type_ids(string $actorTypeID):array {
|
|||||||
/*
|
/*
|
||||||
Custom hook
|
Custom hook
|
||||||
*/
|
*/
|
||||||
function opencase_relevant_activity_type_ids(string $actorTypeID):array {
|
function opencase_relevant_activity_type_ids(string $entityType, string $bundle):array {
|
||||||
switch ($actorTypeID) {
|
if ($entityType == 'oc_actor') {
|
||||||
|
switch ($bundle) {
|
||||||
case 'volunteer':
|
case 'volunteer':
|
||||||
return ['email', 'phone_call', 'supervision'];
|
return ['email', 'phone_call', 'supervision', 'application', 'interview'];
|
||||||
case 'client':
|
case 'client':
|
||||||
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
return ['email', 'lete', 'phone_call', 'case_note', 'destitution_funds_provided', 'research', 'application'];
|
||||||
case 'staff_member':
|
case 'staff_member':
|
||||||
return ['application', 'interview'];
|
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 [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
namespace Drupal\opencase\Plugin\Block;
|
namespace Drupal\opencase\Plugin\Block;
|
||||||
|
|
||||||
use Drupal\Core\Block\BlockBase;
|
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
|
* Provides a Block with some help text about actor type fields
|
||||||
*
|
*
|
||||||
* @Block(
|
* @Block(
|
||||||
* id = "add_activity",
|
* activity_type = "add_activity",
|
||||||
* admin_label = @Translation("Add Activity"),
|
* admin_label = @Translation("Add Activity"),
|
||||||
* category = @Translation("Opencase"),
|
* category = @Translation("Opencase"),
|
||||||
* )
|
* )
|
||||||
@ -19,28 +21,57 @@ class AddActivity extends BlockBase {
|
|||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function build():array {
|
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');
|
$actor = \Drupal::routeMatch()->getParameter('oc_actor');
|
||||||
$target_id = $actor->id();
|
$target_id = $actor->id();
|
||||||
$actorType = $actor->bundle();
|
|
||||||
$markup = "<ul>";
|
$markup = "<ul>";
|
||||||
$activity_types = $this->getActivityTypesToDisplay($actorType);
|
$bundles = $this->getActivityBundlesFor('oc_actor', $actor->bundle());
|
||||||
foreach($activity_types as $id => $info) {
|
foreach($bundles as $bundle => $info) {
|
||||||
$label = $info['label'];
|
$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>";
|
$markup .= "</ul>";
|
||||||
return array('#markup' => $markup);
|
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 {
|
public function getCacheMaxAge():int {
|
||||||
return 0;
|
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.
|
// 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.
|
// Check if they are implemented, and if so display them.
|
||||||
$implemented_activity_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('oc_activity');
|
$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 = [];
|
$activity_types_to_display = [];
|
||||||
foreach ($relevant_activity_type_ids as $type_id) {
|
foreach ($relevant_activity_type_ids as $type_id) {
|
||||||
if (array_key_exists($type_id, $implemented_activity_types)) {
|
if (array_key_exists($type_id, $implemented_activity_types)) {
|
||||||
|
Reference in New Issue
Block a user