diff --git a/modules/localgov_forms_date/src/Plugin/WebformElement/LocalgovFormsDate.php b/modules/localgov_forms_date/src/Plugin/WebformElement/LocalgovFormsDate.php index 4c25ad7..d8d08bd 100644 --- a/modules/localgov_forms_date/src/Plugin/WebformElement/LocalgovFormsDate.php +++ b/modules/localgov_forms_date/src/Plugin/WebformElement/LocalgovFormsDate.php @@ -2,6 +2,8 @@ namespace Drupal\localgov_forms_date\Plugin\WebformElement; +use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Datetime\Element\Datelist as CoreDatelist; use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Form\FormStateInterface; use Drupal\webform\Plugin\WebformElement\DateList; @@ -139,4 +141,27 @@ public static function validateDate(&$element, FormStateInterface $form_state, & parent::validateDate($element, $form_state, $complete_form); } + /** + * {@inheritdoc} + * + * Ensure the datetime object gets added to the user input. + * https://github.com/localgovdrupal/localgov_forms/issues/124 + */ + public static function preValidateDate(&$element, FormStateInterface $form_state, &$complete_form) { + parent::preValidateDate($element, $form_state, $complete_form); + + // Repeating parent workaround to place datetime object on form_state + // input. + $input_exists = FALSE; + $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); + if (!isset($input['object'])) { + if (isset($element['#date_time_element']) && $element['#date_time_element'] === 'timepicker') { + $element['#date_time_format'] = 'H:i:s'; + } + $input = CoreDatelist::valueCallback($element, $input, $form_state); + $form_state->setValueForElement($element, $input); + $element['#value'] = $input; + } + } + } diff --git a/src/Element/AddressLookupElement.php b/src/Element/AddressLookupElement.php index 88dc0f4..be4bc64 100644 --- a/src/Element/AddressLookupElement.php +++ b/src/Element/AddressLookupElement.php @@ -109,6 +109,18 @@ public static function processAddressLookupElement(&$element, FormStateInterface 'class' => ['js-address-searchstring'], ], ]; + // Display title, description and help on the active element. + $properties = [ + '#title' => '#title', + '#title_display' => '#title_display', + // phpcs:ignore DrupalPractice.General.DescriptionT.DescriptionT + '#description' => '#description', + '#help' => '#help', + ]; + $element['address_search']['address_searchstring'] = array_merge( + $element['address_search']['address_searchstring'], + array_intersect_key($element, $properties) + ); $element['address_search']['address_actions'] = [ '#type' => 'container',