Skip to content

Commit 6df2c2f

Browse files
authored
Merge pull request #74 from localgovdrupal/1.x
1.0.0-beta5 release
2 parents 044fc79 + e092414 commit 6df2c2f

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
langcode: en
2+
status: true
3+
dependencies: { }
4+
id: localgov_forms_date_datetime
5+
label: 'LocalGOV Forms Datetime'
6+
locked: false
7+
pattern: 'd-m-Y\TH:i:sO'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
langcode: en
2+
status: true
3+
dependencies: { }
4+
id: localgov_forms_date_short_date
5+
label: 'LocalGOV Forms Short Date'
6+
locked: false
7+
pattern: d-m-Y
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Install, update and uninstall functions for the LocalGov Forms Date module.
6+
*/
7+
8+
use Drupal\Component\Serialization\Yaml;
9+
10+
/**
11+
* Adds a UK short date style e.g dd-mm-yyyy.
12+
*/
13+
function localgov_forms_date_update_8001() {
14+
$config_id = 'core.date_format.localgov_forms_date_short_date';
15+
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
16+
$uk_short_html_date_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
17+
\Drupal::configFactory()->getEditable($config_id)->setData($uk_short_html_date_config)->save();
18+
}
19+
20+
/**
21+
* Adds a UK short date style e.g dd-mm-yyyy HH:mm:ss.
22+
*/
23+
function localgov_forms_date_update_8002() {
24+
$config_id = 'core.date_format.localgov_forms_date_datetime';
25+
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
26+
$uk_html_datetime_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
27+
\Drupal::configFactory()->getEditable($config_id)->setData($uk_html_datetime_config)->save();
28+
}

modules/localgov_forms_date/src/Plugin/WebformElement/LocalgovFormsDate.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\localgov_forms_date\Plugin\WebformElement;
44

5+
use Drupal\Core\Datetime\Entity\DateFormat;
56
use Drupal\Core\Form\FormStateInterface;
67
use Drupal\webform\Plugin\WebformElement\DateList;
78

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

123+
/**
124+
* {@inheritDoc}
125+
*
126+
* Overrides the Datebase class so that
127+
* date validation error messages display in
128+
* a UK Style format e.g dd-mm-yyyy.
129+
*/
130+
public static function validateDate(&$element, FormStateInterface $form_state, &$complete_form) {
131+
132+
// Adds a short date and short date time format.
133+
$localgov_forms_short_date_format = DateFormat::load('localgov_forms_date_short_date')->getPattern();
134+
$localgov_forms_datetime_format = DateFormat::load('localgov_forms_date_datetime')->getPattern();
135+
136+
$element['#date_date_format'] = $localgov_forms_short_date_format;
137+
$element['#date_time_format'] = $localgov_forms_datetime_format;
138+
139+
parent::validateDate($element, $form_state, $complete_form);
140+
}
141+
122142
}

modules/localgov_forms_date/tests/src/Kernel/DateWebformElementTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ protected function setUp() :void {
9595
$this->installConfig('system');
9696
$this->installConfig('localgov_forms_date_test');
9797

98+
$this->installConfig('localgov_forms_date');
99+
98100
$empty_submission = WebformSubmission::create(['webform_id' => 'date_test']);
99101
$this->testForm = WebformSubmissionForm::create($this->container);
100102
$this->testForm->setEntityTypeManager($this->container->get('entity_type.manager'));

0 commit comments

Comments
 (0)