Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes date field validation message presents in reverse order #72

Merged
merged 8 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: localgov_forms_date_datetime
label: 'LocalGOV Forms Datetime'
locked: false
pattern: 'd-m-Y\TH:i:sO'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
langcode: en
status: true
dependencies: { }
id: localgov_forms_date_short_date
label: 'LocalGOV Forms Short Date'
locked: false
pattern: d-m-Y
28 changes: 28 additions & 0 deletions modules/localgov_forms_date/localgov_forms_date.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @file
* Install, update and uninstall functions for the LocalGov Forms Date module.
*/

use Drupal\Component\Serialization\Yaml;

/**
* Adds a UK short date style e.g dd-mm-yyyy.
*/
function localgov_forms_date_update_8001() {
$config_id = 'core.date_format.localgov_forms_date_short_date';
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
$uk_short_html_date_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
\Drupal::configFactory()->getEditable($config_id)->setData($uk_short_html_date_config)->save();
}

/**
* Adds a UK short date style e.g dd-mm-yyyy HH:mm:ss.
*/
function localgov_forms_date_update_8002() {
$config_id = 'core.date_format.localgov_forms_date_datetime';
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
$uk_html_datetime_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
\Drupal::configFactory()->getEditable($config_id)->setData($uk_html_datetime_config)->save();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\localgov_forms_date\Plugin\WebformElement;

use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Plugin\WebformElement\DateList;

Expand Down Expand Up @@ -119,4 +120,23 @@ public function setDefaultValue(array &$element) {
$element['#type'] = $orig_type;
}

/**
* {@inheritDoc}
*
* Overrides the Datebase class so that
* date validation error messages display in
* a UK Style format e.g dd-mm-yyyy.
*/
public static function validateDate(&$element, FormStateInterface $form_state, &$complete_form) {

// Adds a short date and short date time format.
$localgov_forms_short_date_format = DateFormat::load('localgov_forms_date_short_date')->getPattern();
$localgov_forms_datetime_format = DateFormat::load('localgov_forms_date_datetime')->getPattern();

$element['#date_date_format'] = $localgov_forms_short_date_format;
$element['#date_time_format'] = $localgov_forms_datetime_format;

parent::validateDate($element, $form_state, $complete_form);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ protected function setUp() :void {
$this->installConfig('system');
$this->installConfig('localgov_forms_date_test');

$this->installConfig('localgov_forms_date');

$empty_submission = WebformSubmission::create(['webform_id' => 'date_test']);
$this->testForm = WebformSubmissionForm::create($this->container);
$this->testForm->setEntityTypeManager($this->container->get('entity_type.manager'));
Expand Down
Loading