Skip to content

Commit 40facc3

Browse files
authored
Merge pull request #868 from UN-OCHA/release-versions/v1.6.5
release versions/v1.6.5
2 parents aba7c11 + 4496713 commit 40facc3

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

composer.patches.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"Issue #2958568: Add a search api processor for view unpublished": "./patches/2958568-view-unpublished-search-api-access-17.patch"
5353
},
5454
"drupal/webp": {
55-
"Issue #3325808: Webp Image not generated for styles using original image.": "https://www.drupal.org/files/issues/2022-12-19/webp-3325808-2.patch",
55+
"Issue #3325808: Webp Image not generated for styles using original image.": "https://www.drupal.org/files/issues/2023-12-07/webp-3325808-11.patch",
5656
"Issue #3281606: Rendering duplicate images when the original images have the same name but different extension": "https://git.drupalcode.org/project/webp/-/merge_requests/30.patch",
5757
"Issue #3153137: Using Image Widget Crop in responsive images does not refresh webp image": "./patches/3153137-custom-fix-3281606.patch"
5858
}

html/modules/custom/ghi_form_elements/src/Element/EntityAttachmentSelect.php

+40-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,18 @@ public static function processEntityAttachmentSelect(array &$element, FormStateI
107107
],
108108
];
109109

110+
// Remove invalid ids from the entity_ids passed in via #default_value.
111+
$context = $element['#element_context'];
112+
$plan_id = $context['plan_object']->get('field_original_id')->value;
113+
$plan_entities = self::getPlanEntitiesQuery($plan_id)->getPlanEntities($context['base_object']);
114+
$valid_entity_ids = [$plan_id] + array_keys($plan_entities);
115+
$defaults['entities']['entity_ids'] = array_filter($defaults['entities']['entity_ids'] ?? [], function ($_entity_id) use ($valid_entity_ids) {
116+
return in_array($_entity_id, $valid_entity_ids);
117+
});
118+
110119
$form_state->set('entities', $defaults['entities']);
111120
$triggering_element = $form_state->getTriggeringElement();
112-
$action = $triggering_element ? end($form_state->getTriggeringElement()['#parents']) : NULL;
121+
$action = $triggering_element && array_key_exists('#parents', $triggering_element) ? end($triggering_element['#parents']) : NULL;
113122
$actions_map = [
114123
'select_entities' => 'select_attachments',
115124
'change_entities' => 'select_entities',
@@ -183,7 +192,7 @@ public static function processEntityAttachmentSelect(array &$element, FormStateI
183192
'wrapper' => $wrapper_id,
184193
],
185194
'#attributes' => [
186-
'class' => [$current_action != 'select_entities' ? 'visually-hidden' : NULL],
195+
'class' => $current_action != 'select_entities' ? ['visually-hidden'] : [],
187196
],
188197
];
189198
$element['actions']['change_entities'] = [
@@ -195,8 +204,10 @@ public static function processEntityAttachmentSelect(array &$element, FormStateI
195204
'wrapper' => $wrapper_id,
196205
],
197206
'#attributes' => [
198-
'class' => [$current_action != 'select_attachments' ? 'visually-hidden' : NULL],
207+
'class' => $current_action != 'select_attachments' ? ['visually-hidden'] : [],
199208
],
209+
'#limit_validation_errors' => [],
210+
'#submit' => [],
200211
];
201212
$element['actions']['select_attachments'] = [
202213
'#type' => 'submit',
@@ -207,7 +218,7 @@ public static function processEntityAttachmentSelect(array &$element, FormStateI
207218
'wrapper' => $wrapper_id,
208219
],
209220
'#attributes' => [
210-
'class' => [$current_action != 'select_attachments' ? 'visually-hidden' : NULL],
221+
'class' => $current_action != 'select_attachments' ? ['visually-hidden'] : [],
211222
],
212223
];
213224
if (!empty($element['#next_step']) && !empty($element['#container_wrapper'])) {
@@ -233,4 +244,29 @@ public static function preRenderEntityAttachmentSelect(array $element) {
233244
return $element;
234245
}
235246

247+
/**
248+
* Get the endpoint query manager service.
249+
*
250+
* @return \Drupal\hpc_api\Query\EndpointQueryManager
251+
* The endpoint query manager service.
252+
*/
253+
private static function getEndpointQueryManager() {
254+
return \Drupal::service('plugin.manager.endpoint_query_manager');
255+
}
256+
257+
/**
258+
* Get the plan entities query service.
259+
*
260+
* @param int $plan_id
261+
* The plan id for which a query should be build.
262+
*
263+
* @return \Drupal\ghi_plans\Plugin\EndpointQuery\PlanEntitiesQuery
264+
* The plan entities query plugin.
265+
*/
266+
public static function getPlanEntitiesQuery($plan_id) {
267+
$query_handler = self::getEndpointQueryManager()->createInstance('plan_entities_query');
268+
$query_handler->setPlaceholder('plan_id', $plan_id);
269+
return $query_handler;
270+
}
271+
236272
}

0 commit comments

Comments
 (0)