templating for activities

This commit is contained in:
Naomi 2020-06-05 19:26:59 +01:00
parent be45fd2d42
commit 5d1844304a
2 changed files with 28 additions and 3 deletions

View File

@ -22,9 +22,23 @@ use Drupal\Core\Render\Element;
function template_preprocess_oc_activity(array &$variables) {
// Fetch OCActivity Entity Object.
$oc_activity = $variables['elements']['#oc_activity'];
$variables['id'] = $oc_activity->get('id')[0]->get('value')->getValue();
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
// Separate the fields into two sections to be displayed in two columns.
// Remove the name (title) field as this is displayed anyway.
$variables['base_fields'] = array();
$variables['other_fields'] = array();
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
if (in_array($key, ['activity_date_time', 'time_taken', 'description', 'user_id'])) {
$variables['base_fields'][$key] = $variables['elements'][$key];
} else {
$variables['other_fields'][$key] = $variables['elements'][$key];
unset($variables['other_fields']['name']);
}
}
}

View File

@ -16,7 +16,18 @@
*/
#}
<div{{ attributes.addClass('oc_activity') }}>
{% if content %}
{{- content -}}
{% endif %}
<h2>{{ title }}</h2>
<div class="oc_entity">
<div class="left">
{{ base_fields.activity_date_time }}
{{ base_fields.description }}
{{ base_fields.time_taken }}
{{ base_fields.user_id }}
</div>
<div class="right">
{% for field in other_fields %}
{{ field }}
{% endfor %}
</div>
</div>
</div>