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

EWPP-4833: Remove moment.js dependency. #1522

Open
wants to merge 2 commits into
base: 4.x
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion ecl-builder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ module.exports = {
{ from: path.resolve(nodeModules, '@ecl/preset-eu/dist'), to: path.resolve(outputFolder, 'dist/eu') },
{ from: path.resolve(nodeModules, 'svg4everybody/dist'), patterns: 'svg4everybody.js', to: path.resolve(outputFolder, 'dist/js') },
{ from: path.resolve(nodeModules, 'pikaday'), patterns: 'pikaday.js', to: path.resolve(outputFolder, 'dist/js') },
{ from: path.resolve(nodeModules, 'moment/min'), patterns: 'moment.min.js', to: path.resolve(outputFolder, 'dist/js') },
]
};
4 changes: 1 addition & 3 deletions js/ecl_datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
attach: function attach(context, settings) {
var elements = document.querySelectorAll('[data-ecl-datepicker-toggle]');
for (var i = 0; i < elements.length; i++) {
var datepicker = new ECL.Datepicker(elements[i], {
format: settings.oe_theme.ecl_datepicker_format
});
var datepicker = new ECL.Datepicker(elements[i]);
datepicker.init();
}
}
Expand Down
2 changes: 0 additions & 2 deletions oe_theme.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ component_library_ec:
dist/ec/styles/ecl-ec-print.css: { media: print }
css/style-ec.css: { media: screen }
js:
dist/js/moment.min.js: { minified: true }
dist/ec/scripts/ecl-ec.js: {}
js/ecl_auto_init.js: {}
dependencies:
Expand All @@ -24,7 +23,6 @@ component_library_eu:
dist/eu/styles/ecl-eu-print.css: { media: print }
css/style-eu.css: { media: screen }
js:
dist/js/moment.min.js: { minified: true }
dist/eu/scripts/ecl-eu.js: {}
js/ecl_auto_init.js: {}
dependencies:
Expand Down
9 changes: 0 additions & 9 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,7 @@ function oe_theme_preprocess_input__checkbox(array &$variables): void {
* Implements template_preprocess_input__date().
*/
function oe_theme_preprocess_input__date(array &$variables): void {
$php_date_format = $variables['element']['#date_date_format'] ?? 'Y-m-d';
$format_map = [
// @todo find a cleverer way of mapping PHP date formats to the expected
// ECL ones.
'Y-m-d' => 'YYYY-MM-DD',
];
$ecl_format = $format_map[$php_date_format] ?? 'YYYY-MM-DD';
$variables['#attached']['library'][] = 'oe_theme/ecl_datepicker';
$variables['#attached']['drupalSettings']['oe_theme']['ecl_datepicker_format'] = $ecl_format;
$variables['placeholder'] = $ecl_format;
}

/**
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"chokidar-cli": "3.0.0",
"grunt": "1.6.1",
"grunt-contrib-copy": "1.0.0",
"moment": "2.29.1",
"node-sass": "8.0.0",
"npm-run-all": "4.1.5",
"patch-package": "8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion templates/form/input--date.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
required: element['#required'],
disabled: attributes.disabled is defined,
invalid: element['#errors'] is not empty,
placeholder: placeholder,
placeholder: 'DD-MM-YYYY',
default_value: attributes.value,
extra_classes: classes|default(''),
extra_attributes: extra_attributes|default([]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'date',
'#title' => $this->t('Test date picker two'),
'#description' => $this->t('Date field two.'),
'#default_value' => DrupalDateTime::createFromFormat('Y-m-d', '2020-05-10'),
'#default_value' => DrupalDateTime::createFromFormat('d-m-Y', '10-05-2020', 'UTC'),
'#required' => FALSE,
];

Expand Down Expand Up @@ -94,7 +94,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
if (!$value) {
continue;
}
$date = DrupalDateTime::createFromFormat('Y-m-d', $value);
$date = DrupalDateTime::createFromFormat('d-m-Y', $value);
$this->messenger->addStatus($this->t('Date @key is @date', [
'@key' => $key,
'@date' => $date->format('j F Y'),
Expand Down
3 changes: 0 additions & 3 deletions tests/src/Functional/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function testDefaultLibraryLoading(): void {
$this->assertLinkContainsHref('/oe_theme/dist/ec/styles/optional/ecl-ec-default.css');
$this->assertLinkContainsHref('/oe_theme/css/style-ec.css');

$this->assertScriptContainsSrc('/oe_theme/dist/js/moment.min.js');
$this->assertScriptContainsSrc('/oe_theme/dist/ec/scripts/ecl-ec.js');
$this->assertScriptContainsSrc('/oe_theme/js/ecl_auto_init.js');

Expand Down Expand Up @@ -119,7 +118,6 @@ public function testChangeComponentLibrary(): void {
$this->assertLinkContainsHref('/oe_theme/dist/eu/styles/optional/ecl-eu-default.css');
$this->assertLinkContainsHref('/oe_theme/css/style-eu.css');

$this->assertScriptContainsSrc('/oe_theme/dist/js/moment.min.js');
$this->assertScriptContainsSrc('/oe_theme/dist/eu/scripts/ecl-eu.js');
$this->assertScriptContainsSrc('/oe_theme/js/ecl_auto_init.js');

Expand Down Expand Up @@ -163,7 +161,6 @@ public function testChangeComponentLibrary(): void {

$this->assertScriptContainsSrc('/oe_theme/dist/ec/scripts/ecl-ec.js');
$this->assertScriptContainsSrc('/oe_theme/js/ecl_auto_init.js');
$this->assertScriptContainsSrc('/oe_theme/dist/js/moment.min.js');

// Assert that we don't load rtl styling.
$this->assertLinkNotContainsHref('/oe_theme/dist/ec/styles/optional/ecl-rtl.css');
Expand Down
6 changes: 3 additions & 3 deletions tests/src/FunctionalJavascript/JavascriptBehavioursTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function testEclDatePicker(): void {

// Assert the first date picker.
$input = $this->getSession()->getPage()->find('css', 'input[name="test_datepicker_one"]');
$this->assertEquals('YYYY-MM-DD', $input->getAttribute('placeholder'));
$this->assertEquals('DD-MM-YYYY', $input->getAttribute('placeholder'));
$this->assertNull($input->getAttribute('value'));
$this->assertTrue($input->hasAttribute('data-ecl-datepicker-toggle'));
$this->assertTrue($input->hasAttribute('required'));
Expand Down Expand Up @@ -205,14 +205,14 @@ public function testEclDatePicker(): void {
// Pick a date and assert it was set.
$day = $datepickers[0]->find('css', 'button[data-pika-day=1]');
$day->click();
$this->assertEquals($now->format('Y-m') . '-01', $input->getValue());
$this->assertEquals('01-' . $now->format('m-Y'), $input->getValue());
// Give the datepicker a chance to hide.
sleep(1);
$this->assertFalse($datepickers[0]->isVisible());

// Assert some small differences on the second date input element.
$input = $this->getSession()->getPage()->find('css', 'input[name="test_datepicker_two"]');
$this->assertEquals('YYYY-MM-DD', $input->getAttribute('placeholder'));
$this->assertEquals('DD-MM-YYYY', $input->getAttribute('placeholder'));
$this->assertStringContainsString('2020-05-10', $input->getAttribute('value'));
$this->assertTrue($input->hasAttribute('data-ecl-datepicker-toggle'));
$this->assertFalse($input->hasAttribute('required'));
Expand Down