Skip to content
This repository was archived by the owner on Feb 23, 2020. It is now read-only.

Commit 8dc6113

Browse files
committed
Added 'Done' button to multi arity registrants element.
Closes #119
1 parent 0fa5961 commit 8dc6113

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

css/elements/registrants.layout.css

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sass/elements/registrants.layout.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,19 @@
2727
.entities {
2828
&> .details-wrapper {
2929
display: flex;
30+
31+
> .person-controls {
32+
display: flex;
33+
flex-direction: column;
34+
}
3035
}
3136
}
3237

3338
fieldset.person-type {
3439
/* Need fieldset selector since you cannot define different attributes for
3540
the container and each child radio */
41+
flex: 1;
42+
3643
div.form-type-radio {
3744
position: relative;
3845

src/Element/Registrants.php

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,15 @@ public static function processIdentityElement(array &$element, FormStateInterfac
274274
],
275275
];
276276

277-
$element['entities']['for_bundle'] = [
277+
$element['entities']['controls'] = [
278+
'#type' => 'container',
279+
'#tree' => TRUE,
280+
'#attributes' => [
281+
'class' => ['person-controls'],
282+
],
283+
];
284+
285+
$element['entities']['controls']['for_bundle'] = [
278286
'#type' => 'radios',
279287
'#title' => t('Person type'),
280288
'#options' => $for_bundles,
@@ -294,8 +302,33 @@ public static function processIdentityElement(array &$element, FormStateInterfac
294302
'#attributes' => [
295303
'class' => ['person-type'],
296304
],
305+
'#parents' => array_merge($parents, ['entities', 'for_bundle']),
297306
];
298307

308+
$element['entities']['controls']['actions'] = [
309+
'#type' => 'actions',
310+
'#tree' => TRUE,
311+
];
312+
313+
// Display a close button if there are people and arity is multiple.
314+
if ($arity_is_multiple && count($people) > 0) {
315+
$element['entities']['controls']['actions']['done'] = [
316+
'#type' => 'submit',
317+
'#value' => t('Done'),
318+
'#ajax' => [
319+
'callback' => [static::class, 'ajaxElementRoot'],
320+
'wrapper' => $ajax_wrapper_id_root,
321+
],
322+
'#limit_validation_errors' => [],
323+
'#validate' => [
324+
[static::class, 'decoyValidator'],
325+
],
326+
'#submit' => [
327+
[static::class, 'submitClose'],
328+
],
329+
];
330+
}
331+
299332
$element['entities']['person'] = [
300333
'#type' => 'container',
301334
'#tree' => TRUE,
@@ -801,6 +834,24 @@ public static function submitChangeDefault(array $form, FormStateInterface $form
801834
}
802835
}
803836

837+
/**
838+
* Submission callback to close the selection interface.
839+
*
840+
* @param array $form
841+
* The complete form.
842+
* @param \Drupal\Core\Form\FormStateInterface $form_state
843+
* The current state of the form.
844+
*/
845+
public static function submitClose(array $form, FormStateInterface $form_state) {
846+
$form_state->setRebuild();
847+
848+
$element = RegistrantsElement::findElement($form, $form_state);
849+
$utility = new RegistrantsElement($element, $form_state);
850+
851+
$utility->setChangeIt(FALSE);
852+
$utility->clearPeopleFormInput();
853+
}
854+
804855
/**
805856
* For_arity radios submission handler.
806857
*

0 commit comments

Comments
 (0)