function template_preprocess_office_hours in Office Hours 8
Prepares variables for office hours templates.
Default template: office-hours.html.twig.
Parameters
object $variables: The variables array.
File
- ./
office_hours.module, line 62 - Creates a field and widget for inserting working or office hours per day.
Code
function template_preprocess_office_hours(&$variables) {
$office_hours = $variables['office_hours'];
// Minimum width for day labels. Adjusted when adding new labels.
$label_length = 3;
$items = [];
// Schema part.
// @todo Move to ..._preprocess_office_hours_schema, or use RDF module's twig.
if (isset($office_hours['schema'])) {
$schema_items = [];
foreach ($office_hours['schema'] as $schema) {
$schema_items[] = [
'label' => $schema['label'],
'slots' => [
'#type' => 'markup',
'#markup' => $schema['formatted_slots'],
],
];
}
$variables['schema'] = $schema_items;
unset($office_hours['schema']);
}
foreach ($office_hours as $info) {
$label = $info['label'];
$label_length = max($label_length, mb_strlen($label));
$items[] = [
'label' => $label,
'slots' => [
'#type' => 'markup',
'#markup' => $info['formatted_slots'],
],
'comments' => [
'#type' => 'markup',
'#markup' => $info['comments'],
],
'suffix' => $variables['item_separator'],
];
}
$variables['items'] = $items;
$variables['label_length'] = $label_length;
}