2018-04-14 16:44:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Drupal\zencrm\Plugin\Block;
|
|
|
|
|
|
|
|
use Drupal\Core\Block\BlockBase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a 'Case Details' block.
|
|
|
|
* It displays the involved parties with links to their persons (as opposed to hats)
|
|
|
|
* and then the content in default view, and then an edit link.
|
|
|
|
*
|
|
|
|
* @Block(
|
|
|
|
* id = "case_details",
|
|
|
|
* admin_label = @Translation("Case Details"),
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
class CaseDetails extends BlockBase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function build() {
|
|
|
|
$case_id = \Drupal::routeMatch()->getParameter('case_entity')->id();
|
|
|
|
$case = $entity = \Drupal::entityTypeManager()->getStorage('case_entity')->load($case_id);
|
|
|
|
$markup .= $this->renderInvolvedParties($case);
|
|
|
|
$markup .= $this->renderEntity($case);
|
|
|
|
$markup .= $this->renderEditLink($case_id);
|
|
|
|
return [
|
|
|
|
'#cache' => [
|
|
|
|
'max-age' => 0,
|
|
|
|
],
|
|
|
|
'#markup' => $markup
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderEditLink($case_id) {
|
2018-04-15 10:44:07 +00:00
|
|
|
return "<p class = 'zencrm_editlink'><a class='use-ajax' data-dialog-type='modal' href='/zencrm/case/$case_id/edit?destination=/zencrm/case/$case_id'>Edit</a></p>";
|
2018-04-14 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderEntity($case) {
|
|
|
|
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('case_entity');
|
|
|
|
$build = $view_builder->view($case, 'default');
|
2018-04-15 10:44:07 +00:00
|
|
|
$markup = render($build);
|
|
|
|
return "<div class='zencrm_inner_sidebar_block'>$markup</div>";
|
2018-04-14 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function renderInvolvedParties($case) {
|
2018-04-15 10:44:07 +00:00
|
|
|
$markup = "<p class='zencrm_title'>Involved Parties</p>";
|
2018-04-14 16:44:38 +00:00
|
|
|
$hats_involved = $case->hats_involved->referencedEntities();
|
2018-04-15 10:44:07 +00:00
|
|
|
$links_markup = "";
|
2018-04-14 16:44:38 +00:00
|
|
|
foreach($hats_involved as $hat) {
|
|
|
|
$person_id = $hat->person->first()->getValue()['target_id'];
|
2018-04-15 10:44:07 +00:00
|
|
|
$links_markup .= "<p><a href='/zencrm/person/$person_id'>" . $hat->name->getString() . "</a></p>";
|
2018-04-14 16:44:38 +00:00
|
|
|
}
|
2018-04-15 10:44:07 +00:00
|
|
|
$markup .= "<div class='zencrm_links'>$links_markup</div>";
|
|
|
|
return "<div class='zencrm_inner_sidebar_block'>$markup</div>";
|
2018-04-14 16:44:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|