Problem/Motivation
This is a follow-up on
✨
Use the office hours field widget as Element (in a settings form)
Fixed
which allows us to include an office hour widget into a settings form. The captured values then get stored in a config entity like e.g.
'apbs_entities.settings:office_hours':
times:
1:
0:
day: '1'
starthours:
time: ''
endhours:
time: ''
comment: ''
1:
day: '1'
starthours:
time: '07:00'
endhours:
time: '10:00'
comment: ''
day: '1'
starthours:
date: ''
time: '07:00'
object: null
endhours:
date: ''
time: '10:00'
object: null
comment: ''
2:
0:
day: '2'
starthours:
time: '07:00'
endhours:
time: '09:00'
comment: ''
1:
day: '2'
starthours:
time: ''
endhours:
time: ''
comment: ''
day: '2'
starthours:
date: ''
time: '07:00'
object: null
endhours:
date: ''
time: '09:00'
object: null
comment: ''
Now, my question is how to render such values in custom code. I have something in mind like this:
$officeHours = \Drupal::config(Settings::CONFIG_KEY)->get(Settings::OFFICE_HOURS);
$build = [
'#theme' => 'office_hours',
'#parent' => [],
'#office_hours' => [],
'#office_hours_field' => $officeHours,
'#is_open' => TRUE,
'#item_separator' => Xss::filter(
'', ['br', 'hr', 'span', 'div']
),
'#slot_separator' => '',
'#attributes' => [
'class' => ['office-hours'],
],
'#attached' => [
'library' => [
'office_hours/office_hours_formatter',
],
],
];
$rendered = \Drupal::service('renderer')->renderInIsolation($build);
This doesn't work yet. How should one go about this requirement?