Skip to content

Commit

Permalink
Merge pull request #1126 from UN-OCHA/release-versions/v1.10.6
Browse files Browse the repository at this point in the history
release versions/v1.10.6
  • Loading branch information
berliner authored Oct 8, 2024
2 parents 532fcc0 + b6e8475 commit 6c2ae8b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ private function attachmentCanBeMapped(AttachmentInterface $attachment) {
if (!$attachment instanceof DataAttachment) {
return FALSE;
}
if (!$attachment->hasDisaggregatedData()) {
return FALSE;
}
$reporting_period = $this->getCurrentReportingPeriod();
return $attachment->canBeMapped($reporting_period);
}
Expand Down Expand Up @@ -863,6 +866,7 @@ public function attachmentsForm(array $form, FormStateInterface $form_state) {
],
'#next_step' => 'map',
'#container_wrapper' => $this->getContainerWrapper(),
'#disagg_warning' => TRUE,
];
return $form;
}
Expand Down Expand Up @@ -1126,10 +1130,13 @@ private function getDefaultAttachment() {
$attachment = reset($attachments);
}
$default_attachment = $attachment;
if (!$attachment instanceof DataAttachment || !$this->attachmentCanBeMapped($attachment)) {
if (!$attachment instanceof DataAttachment) {
$default_attachment = FALSE;
}
elseif (!$this->attachmentCanBeMapped($attachment)) {
$default_attachment = FALSE;
}
if ($attachment && $attachment->getPlanId() != $this->getCurrentPlanId()) {
elseif ($attachment->getPlanId() != $this->getCurrentPlanId()) {
$default_attachment = FALSE;
}
}
Expand All @@ -1148,6 +1155,9 @@ private function getSelectedAttachments() {
return [];
}
$attachments = $this->getConfiguredAttachments();
$attachments = array_filter($attachments, function (AttachmentInterface $attachment) {
return $this->attachmentCanBeMapped($attachment);
});
return $attachments;
}

Expand Down Expand Up @@ -1288,8 +1298,8 @@ public function fixConfigErrors() {

$configured_entities = $this->getConfiguredEntities();
$available_entities = $this->getAvailableEntities();
if (!empty($configured_entities)) {
$valid_entity_ids = array_intersect_key($configured_entities, $available_entities);
$valid_entity_ids = array_intersect_key($configured_entities, $available_entities);
if (!empty($configured_entities) && !empty($valid_entity_ids)) {
$conf['attachments']['entity_attachments']['entities']['entity_ids'] = array_combine($valid_entity_ids, $valid_entity_ids);
}
else {
Expand Down Expand Up @@ -1318,8 +1328,10 @@ public function fixConfigErrors() {
continue;
}
$filtered_attachments = $this->matchDataAttachments($attachment, $available_attachments);
$attachment_ids = array_keys($filtered_attachments);
$conf['attachments']['entity_attachments']['attachments']['attachment_id'] += array_combine($attachment_ids, $attachment_ids);
foreach ($filtered_attachments as $filtered_attachment) {
$conf['attachments']['entity_attachments']['attachments']['attachment_id'][$filtered_attachment->id()] = $filtered_attachment->id();
$conf['attachments']['entity_attachments']['entities']['entity_ids'][$filtered_attachment->source->entity_id] = $filtered_attachment->source->entity_id;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait GlobalMapTrait {
*/
public function getStaticTilesUrlTemplate($style_id = NULL) {
if ($style_id === NULL) {
$style_id = 'clbfjni1x003m15nu67uwtbly';
$style_id = 'ck6kzlftu17uv1ilgsacalu17';
}
$map_config = $this->getGlobalMapSettings();
$use_proxy = !empty($map_config['mapbox_proxy']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getInfo() {
],
'#entity_ids' => [],
'#attachment_type' => NULL,
'#disagg_warning' => FALSE,
];
}

Expand Down Expand Up @@ -231,6 +232,7 @@ public static function processAttachmentSelect(array &$element, FormStateInterfa
$attachment_options = [];
$entities_in_selection = [];
foreach (ArrayHelper::filterArray($attachments, $attachment_filter) as $attachment) {
/** @var \Drupal\ghi_plans\ApiObjects\Attachments\DataAttachment $attachment */
$entities_in_selection[$attachment->source->entity_id] = TRUE;
$attachment_options[$attachment->id] = [
'id' => $attachment->id,
Expand All @@ -240,6 +242,10 @@ public static function processAttachmentSelect(array &$element, FormStateInterfa
'description' => $attachment->description,
'sort_key' => $attachment->getSourceEntity()?->sort_key,
];

if (!empty($element['#disagg_warning'])) {
$attachment_options[$attachment->id]['disagg_data'] = $attachment->hasDisaggregatedData() ? '' : '';
}
}
ArrayHelper::sortArrayByStringKey($attachment_options, 'composed_reference');
ArrayHelper::sortArrayByStringKey($attachment_options, 'sort_key');
Expand Down Expand Up @@ -343,6 +349,9 @@ public static function processAttachmentSelect(array &$element, FormStateInterfa
'prototype' => t('Type'),
'description' => t('Description'),
];
if (!empty($element['#disagg_warning'])) {
$columns['disagg_data'] = t('Disaggregated data');
}

// Build the explanation that should show above the attachment select table.
$header_parts[] = $element['#multiple'] ? t('Select the attachments that you want to use.') : t('Select the attachment that you want to use.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function getInfo() {
'#attachment_options' => NULL,
'#attachment_type' => NULL,
'#element_context' => [],
'#disagg_warning' => FALSE,
];
}

Expand Down Expand Up @@ -110,7 +111,7 @@ public static function processEntityAttachmentSelect(array &$element, FormStateI
// Remove invalid ids from the entity_ids passed in via #default_value.
$context = $element['#element_context'];
$plan_id = $context['plan_object']->get('field_original_id')->value;
$plan_entities = self::getPlanEntitiesQuery($plan_id)->getPlanEntities($context['base_object']);
$plan_entities = self::getPlanEntitiesQuery($plan_id)->getPlanEntities($context['base_object']) ?? [];
$valid_entity_ids = array_merge([$plan_id], array_keys($plan_entities));
$defaults['entities']['entity_ids'] = array_filter($defaults['entities']['entity_ids'] ?? [], function ($_entity_id) use ($valid_entity_ids) {
return in_array($_entity_id, $valid_entity_ids);
Expand Down Expand Up @@ -165,6 +166,7 @@ public static function processEntityAttachmentSelect(array &$element, FormStateI
'#entity_ids' => $defaults['entities']['entity_ids'],
'#available_options' => $element['#attachment_options'] ?? NULL,
'#attachment_type' => $element['#attachment_type'] ?? NULL,
'#disagg_warning' => $element['#disagg_warning'] ?? FALSE,
];
if ($current_action != 'select_attachments') {
$element['attachments']['#hidden'] = TRUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function processEntitySelect(array &$element, FormStateInterface $
$plan_object = $element['#element_context']['plan_object'] ?? NULL;

$plan_id = $plan_object->getSourceId();
$plan_entities = self::getPlanEntitiesQuery($plan_id)->getPlanEntities($base_object);
$plan_entities = self::getPlanEntitiesQuery($plan_id)->getPlanEntities($base_object) ?? [];
$plan_data = self::getPlanEntitiesQuery($plan_id)->getData();

$is_hidden = array_key_exists('#hidden', $element) && $element['#hidden'];
Expand Down

0 comments on commit 6c2ae8b

Please sign in to comment.