Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
177ec262
Commit
177ec262
authored
Sep 13, 2018
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2992580
by Vj, Arez, andypost, jhedstrom: Custom callbacks doesn't work
parent
0875ceba
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Datetime/Element/Datetime.php
+1
-1
1 addition, 1 deletion
core/lib/Drupal/Core/Datetime/Element/Datetime.php
core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php
+100
-0
100 additions, 0 deletions
...pal/KernelTests/Core/Datetime/DatetimeElementFormTest.php
with
101 additions
and
1 deletion
core/lib/Drupal/Core/Datetime/Element/Datetime.php
+
1
−
1
View file @
177ec262
...
@@ -274,7 +274,7 @@ public static function processDatetime(&$element, FormStateInterface $form_state
...
@@ -274,7 +274,7 @@ public static function processDatetime(&$element, FormStateInterface $form_state
// Allows custom callbacks to alter the element.
// Allows custom callbacks to alter the element.
if
(
!
empty
(
$element
[
'#date_date_callbacks'
]))
{
if
(
!
empty
(
$element
[
'#date_date_callbacks'
]))
{
foreach
(
$element
[
'#date_date_callbacks'
]
as
$callback
)
{
foreach
(
$element
[
'#date_date_callbacks'
]
as
$callback
)
{
if
(
function_exists
(
$callback
))
{
if
(
is_callable
(
$callback
))
{
$callback
(
$element
,
$form_state
,
$date
);
$callback
(
$element
,
$form_state
,
$date
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php
0 → 100644
+
100
−
0
View file @
177ec262
<?php
namespace
Drupal\KernelTests\Core\Datetime
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\Form\FormInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\KernelTests\KernelTestBase
;
/**
* Tests DatetimeElement functionality.
*
* @group Form
*/
class
DatetimeElementFormTest
extends
KernelTestBase
implements
FormInterface
{
/**
* The variable under test.
*/
protected
$flag
;
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
[
'datetime'
,
'system'
];
/**
* Sets up the test.
*/
protected
function
setUp
()
{
parent
::
setUp
();
}
/**
* {@inheritdoc}
*/
public
function
getFormId
()
{
return
'test_datetime_element'
;
}
/**
* {@inheritdoc}
*/
public
function
datetimecallback
(
$date
)
{
$this
->
flag
=
'Date time callback called.'
;
}
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'datetime_element'
]
=
[
'#title'
=>
'datelist test'
,
'#type'
=>
'datetime'
,
'#default_value'
=>
new
DrupalDateTime
(
'2000-01-01 00:00:00'
),
'#date_date_format'
=>
[
'Y-m-d'
],
'#date_time_format'
=>
[
'H:i:s'
],
'#date_date_element'
=>
'HTML Date'
,
'#date_time_element'
=>
'HTML Time'
,
'#date_increment'
=>
1
,
'#date_date_callbacks'
=>
[[
$this
,
'datetimecallback'
]],
];
$form
[
'submit'
]
=
[
'#type'
=>
'submit'
,
'#value'
=>
t
(
'Submit'
),
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{}
/**
* Form validation handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public
function
validateForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{}
/**
* Tests that default handlers are added even if custom are specified.
*/
public
function
testDatetimeElement
()
{
$form
=
\Drupal
::
formBuilder
()
->
getForm
(
$this
);
$this
->
render
(
$form
);
$this
->
assertEqual
(
t
(
'Date time callback called.'
),
$this
->
flag
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment