Skip to content

Commit

Permalink
Merge pull request #1266 from UN-OCHA/berliner/HPC-9971
Browse files Browse the repository at this point in the history
  • Loading branch information
berliner authored Dec 16, 2024
2 parents 2cc14e9 + c7862d9 commit ad24f37
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions html/modules/custom/ghi_blocks/src/Helpers/AttachmentMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ public static function matchDataAttachments(AttachmentInterface $original_attach
* Either the original index if no match can be found or a new index.
*/
public static function matchDataPointOnAttachments($data_point_index, DataAttachment $attachment_1, DataAttachment $attachment_2) {
$prototype_1 = $attachment_1->getPrototype();
$prototype_2 = $attachment_2->getPrototype();
// Reload the prototypes, because depending on how the attachments have
// been loaded, they might not have the full attachment prototype set up,
// some are missing the calculated fields.
// E.g. plan/:ID?content=entities .
$prototype_1 = $attachment_1->getPrototype()?->id() ? self::getPrototype($attachment_1->getPrototype()->id()) : NULL;
$prototype_2 = $attachment_2->getPrototype()?->id() ? self::getPrototype($attachment_2->getPrototype()->id()) : NULL;
if (!$prototype_1 || !$prototype_2) {
return $data_point_index;
}
Expand Down Expand Up @@ -105,4 +109,22 @@ public static function matchDataPointOnAttachmentPrototypes($data_point_index, A
return $new_index !== FALSE ? $new_index : $data_point_index;
}

/**
* Fetch prototype data from the API.
*
* @param int $prototype_id
* The id of the attachment prototype to load.
*
* @return \Drupal\ghi_plans\ApiObjects\AttachmentPrototype\AttachmentPrototype|null
* An attachment prototype object.
*/
private static function getPrototype($prototype_id) {
/** @var \Drupal\ghi_plans\Plugin\EndpointQuery\AttachmentPrototypeQuery $query_handler */
$query_handler = \Drupal::service('plugin.manager.endpoint_query_manager')->createInstance('attachment_prototype_query');
if (!$query_handler) {
return NULL;
}
return $query_handler->getPrototypeById($prototype_id);
}

}

0 comments on commit ad24f37

Please sign in to comment.