New activity gets its case from the url

This commit is contained in:
naomi 2018-04-30 17:14:51 +02:00
parent 59964e653e
commit 7cf4ee557b
3 changed files with 30 additions and 6 deletions

View File

@ -74,6 +74,13 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
use EntityChangedTrait;
/**
* When creating an activity, it sets the case id from the URL.
*/
public static function defaultVal() {
return \Drupal::request()->query->get('case_id');;
}
/**
* {@inheritdoc}
*/
@ -267,6 +274,7 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
'placeholder' => '',
],
])
->setDefaultValueCallback('Drupal\opencase_entities\Entity\OCActivity::defaultVal')
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')

View File

@ -72,6 +72,7 @@ use Drupal\user\UserInterface;
*/
class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
use EntityChangedTrait;
/**
* When creating a case, it sets the first involved party to the actor
@ -81,8 +82,6 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
return \Drupal::request()->query->get('actor_id');;
}
use EntityChangedTrait;
/**
* {@inheritdoc}
*/

View File

@ -30,6 +30,12 @@ class ContextualMenu extends BlockBase {
case 'view.cases.page_1':
$markup = $this->caseListPage();
break;
case 'entity.oc_case.canonical':
$markup = $this->casePage();
break;
case 'view.activities.page_1':
$markup = $this->activityListPage();
break;
}
$build = [];
@ -68,15 +74,26 @@ class ContextualMenu extends BlockBase {
/**
* Contextual menu for Case page
* - Link to Activity list
*/
private function casePage($case_id) {
private function casePage() {
$case = \Drupal::routeMatch()->getParameter('oc_case');
$url = Url::fromRoute('view.activities.page_1', array('case_id' => $case->id()));
$link = Link::fromTextAndUrl(t("Activity List"), $url)->toString();
return "<div class='opencase_nav_links'><p>$link</p></div>";
}
/**
* Contextual menu for Activity list page
* - Link to case
* - Links to add activities of various types
*/
private function activityListPage($case_id) {
private function activityListPage() {
$case_id = \Drupal::routeMatch()->getParameter('case_id');
$case = \Drupal::entityTypeManager()->getStorage('oc_case')->load($case_id);
$link = $case->toLink()->toString();
$markup = "<div class='opencase_nav_links'><p>$link</p></div>";
$markup .= Utils::generateAddLinks('oc_activity', ['case_id' => $case_id]);
return $markup;
}
}