Commit 3f5645f3 authored by catch's avatar catch
Browse files

Issue #3250335 by alexpott, beatrizrodrigues, paulocs, longwave:...

Issue #3250335 by alexpott, beatrizrodrigues, paulocs, longwave: #date_date_callbacks is broken in Drupal 9.3

(cherry picked from commit 1a8a51ac)
parent 17999022
......@@ -274,7 +274,7 @@ public static function processDatetime(&$element, FormStateInterface $form_state
if (!empty($element['#date_date_callbacks'])) {
foreach ($element['#date_date_callbacks'] as $callback) {
$message = sprintf('DateTime element #date_date_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in drupal:9.3.0 and will be removed in drupal:10.0.0. See https://www.drupal.org/node/3217966', Variable::callableToString($callback));
StaticTrustedCallbackHelper::callback($callback, [$element, $form_state, $date], $message, TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION);
StaticTrustedCallbackHelper::callback($callback, [&$element, $form_state, $date], $message, TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION);
}
}
}
......@@ -305,7 +305,7 @@ public static function processDatetime(&$element, FormStateInterface $form_state
if (!empty($element['#date_time_callbacks'])) {
foreach ($element['#date_time_callbacks'] as $callback) {
$message = sprintf('DateTime element #date_time_callbacks callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in drupal:9.3.0 and will be removed in drupal:10.0.0. See https://www.drupal.org/node/3217966', Variable::callableToString($callback));
StaticTrustedCallbackHelper::callback($callback, [$element, $form_state, $date], $message, TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION);
StaticTrustedCallbackHelper::callback($callback, [&$element, $form_state, $date], $message, TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION);
}
}
}
......
......@@ -5,6 +5,7 @@
use Drupal\Component\Utility\Variable;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\KernelTests\KernelTestBase;
......@@ -16,20 +17,6 @@
*/
class DatetimeElementFormTest extends KernelTestBase implements FormInterface, TrustedCallbackInterface {
/**
* Tracks whether a date-time date callback was executed.
*
* @var bool
*/
protected $dateCallbackExecuted = FALSE;
/**
* Tracks whether a date-time time callback was executed.
*
* @var bool
*/
protected $timeCallbackExecuted = FALSE;
/**
* Modules to enable.
*
......@@ -54,29 +41,41 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function datetimeDateCallbackTrusted() {
$this->dateCallbackExecuted = TRUE;
public function datetimeDateCallbackTrusted(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
$element['datetimeDateCallbackExecuted'] = [
'#value' => TRUE,
];
$form_state->set('datetimeDateCallbackExecuted', TRUE);
}
/**
* {@inheritdoc}
*/
public function datetimeDateCallback() {
$this->dateCallbackExecuted = TRUE;
public function datetimeDateCallback(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
$element['datetimeDateCallbackExecuted'] = [
'#value' => TRUE,
];
$form_state->set('datetimeDateCallbackExecuted', TRUE);
}
/**
* {@inheritdoc}
*/
public function datetimeTimeCallbackTrusted() {
$this->timeCallbackExecuted = TRUE;
public function datetimeTimeCallbackTrusted(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
$element['timeCallbackExecuted'] = [
'#value' => TRUE,
];
$form_state->set('timeCallbackExecuted', TRUE);
}
/**
* {@inheritdoc}
*/
public function datetimeTimeCallback() {
$this->timeCallbackExecuted = TRUE;
public function datetimeTimeCallback(array &$element, FormStateInterface $form_state, DrupalDateTime $date = NULL) {
$element['timeCallbackExecuted'] = [
'#value' => TRUE,
];
$form_state->set('timeCallbackExecuted', TRUE);
}
/**
......@@ -133,11 +132,14 @@ 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);
$form_state = new FormState();
$form = \Drupal::formBuilder()->buildForm($this, $form_state);
$this->render($form);
$this->assertTrue($this->dateCallbackExecuted);
$this->assertTrue($this->timeCallbackExecuted);
$this->assertTrue($form['datetime_element']['datetimeDateCallbackExecuted']['#value']);
$this->assertTrue($form['datetime_element']['timeCallbackExecuted']['#value']);
$this->assertTrue($form_state->get('datetimeDateCallbackExecuted'));
$this->assertTrue($form_state->get('timeCallbackExecuted'));
}
/**
......@@ -161,8 +163,8 @@ public function testDatetimeElementUntrustedCallbacks(string $date_callback = 'd
}
$this->render($form);
$this->assertTrue($this->dateCallbackExecuted);
$this->assertTrue($this->timeCallbackExecuted);
$this->assertTrue($form['datetime_element']['datetimeDateCallbackExecuted']['#value']);
$this->assertTrue($form['datetime_element']['timeCallbackExecuted']['#value']);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment