-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] move BE validation to external JS
- Loading branch information
1 parent
b6c18d5
commit 3b6bac8
Showing
3 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
return [ | ||
'dependencies' => [ | ||
'backend', | ||
], | ||
'imports' => [ | ||
'@t3brightside/youtubevideo/' => 'EXT:youtubevideo/Resources/Public/JavaScript/BackEnd/', | ||
], | ||
]; |
31 changes: 31 additions & 0 deletions
31
Resources/Public/JavaScript/BackEnd/form-engine-evaluation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import FormEngineValidation from "@typo3/backend/form-engine-validation.js"; | ||
export class FormEngineEvaluation { | ||
static registerCustomEvaluation(t) { | ||
FormEngineValidation.registerCustomEvaluation(t, FormEngineEvaluation.evaluateSourceHost) | ||
} | ||
static evaluateSourceHost(t) { | ||
// Replace characters | ||
t = t.replace(/[-|_|,|.|–|']+/g, ':'); | ||
t = t.replace(/[^\d:]+/g, ''); | ||
t = t.replace(/^:|:$/g, ''); | ||
|
||
// Calculate time | ||
var p = t.split(':'); | ||
var s = 0, | ||
m = 1; | ||
while (p.length > 0) { | ||
s += m * parseInt(p.pop(), 10); | ||
m *= 60; | ||
} | ||
|
||
// Check if valid time | ||
if (s > 0) { | ||
var date = new Date(0); | ||
date.setSeconds(s); | ||
t = date.toISOString().substr(11, 8); | ||
return t; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
} |