Skip to content

Commit

Permalink
Merge pull request #1252 from UN-OCHA/berliner/HPC-9968
Browse files Browse the repository at this point in the history
HPC-9968: Link to disag modal for last non-empty monitoring period for cumulative reach fields
  • Loading branch information
berliner authored Dec 10, 2024
2 parents fb389eb + 05e079e commit 3773703
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getRenderArray() {
$link_url = Url::fromRoute('ghi_plans.modal_content.dissaggregation', [
'attachment' => $attachment->id(),
'metric' => $data_point_index,
'reporting_period' => $attachment->getLatestPublishedReportingPeriod($attachment->getPlanId()) ?? 'latest',
'reporting_period' => $build['#reporting_period'] ?: 'latest',
]);
$link_url->setOptions([
'attributes' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,7 @@ public function formatValue(array $conf) {
// Prepare the build.
$build = [
'#type' => 'container',
'#reporting_period' => $this->getLatestPublishedReportingPeriod($this->getPlanId()) ?? 'latest',
];
// Create a render array for the actual value.
if (empty($conf['widget']) || $conf['widget'] == 'none') {
Expand All @@ -1369,6 +1370,13 @@ public function formatValue(array $conf) {
$build[] = $this->formatAsWidget($conf);
}

$data_point_index = $conf['data_points'][0]['index'];
$field = $this->getFieldByIndex($data_point_index);
if ($this->isCumulativeReachFieldType($field->type)) {
$period = $this->getLastNonEmptyReportingPeriod($data_point_index);
$build['#reporting_period'] = $period?->id ?? $build['#reporting_period'];
}

// Prepare the tooltips.
$build['tooltips'] = [
'#theme' => 'hpc_tooltip_wrapper',
Expand Down Expand Up @@ -1409,7 +1417,7 @@ protected function getTooltip($conf) {
if ($cumulative_reach_field || $cumulative_reach_source) {
$format_string = '@data_range_cumulative';
if ($monitoring_period_id == 'latest') {
$monitoring_period_id = $this->getLastNonEmptyReportingPeriod($index)?->id();
$monitoring_period_id = $this->getLastNonEmptyReportingPeriod($index)?->id() ?? $monitoring_period_id;
}
}
$monitoring_tooltip = $this->isMeasurement($conf) ? $this->formatMonitoringPeriod('icon', $monitoring_period_id, $format_string) : NULL;
Expand Down

0 comments on commit 3773703

Please sign in to comment.