- Issue created by @johnv
In
✨
Use the office hours field widget as Element (in a settings form)
Fixed
, the Weektable was separated into a widget and an element.
This calls for a test, that makes sure the functionality is preserved.
Create a for like this:
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = [];
$config = \Drupal::configFactory()->get('example.settings');
$field_settings = OfficeHoursItem::defaultStorageSettings();
$widget_settings = OfficeHoursWeekWidget::defaultSettings();
$office_hours = $config->get('office_hours') ?? [];
$form['office_hours'] = [
'#type' => 'office_hours_table',
'#title' => $this->t('Office hours'),
'#default_value' => $office_hours,
'#field_settings' => $field_settings,
'#widget_settings' => $widget_settings,
'#field_type' => $week_season_id = 0,
];
$form['actions'] = [
'#type' => 'actions',
'submit' => [
'#type' => 'submit',
'#value' => $this->t('Save'),
],
];
return $form;
}
And test if the submitted values are preserved the next time the form is displayed.
As per #23 in above issue, for the ECA module, some form submission tests exist and you can find an example at https://git.drupalcode.org/project/eca/-/blob/2.0.x/modules/form/tests/s...
Add task.
Active
1.0
Code - widget
The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.