Added Involved Parties block for case page

This commit is contained in:
naomi 2018-04-14 17:20:51 +02:00
parent 171eaa73a2
commit 483d1ac9d9
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
<?php
namespace Drupal\zencrm\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides a 'Involved Parties' block.
* Block contains links to the people involved in a case
*
* @Block(
* id = "involved_parties",
* admin_label = @Translation("Involved Parties"),
* )
*/
class InvolvedParties extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
$case_id = \Drupal::routeMatch()->getParameter('case_entity')->id();
$markup = "";
$case = $entity = \Drupal::entityTypeManager()->getStorage('case_entity')->load($case_id);
$hats_involved = $case->hats_involved->referencedEntities();
foreach($hats_involved as $hat) {
$person_id = $hat->person->first()->getValue()['target_id'];
$markup .= "<p><a href='/zencrm/person/$person_id?backto=case&backtoid=$case_id'>" . $hat->name->getString() . "</a></p>";
}
return [
'#cache' => [
'max-age' => 0,
],
'#markup' => "<div class='zencrm_links'>$markup</div>"
];
}
}