diff --git a/modules/opencase_cases/oc_case.page.inc b/modules/opencase_cases/oc_case.page.inc index 6de9601..05f3c06 100644 --- a/modules/opencase_cases/oc_case.page.inc +++ b/modules/opencase_cases/oc_case.page.inc @@ -8,6 +8,7 @@ */ use Drupal\Core\Render\Element; +use Drupal\opencase; /** * Prepares variables for Case templates. @@ -20,18 +21,6 @@ use Drupal\Core\Render\Element; * - attributes: HTML attributes for the containing element. */ function template_preprocess_oc_case(array &$variables) { - // Separate the fields into two sections to be displayed in two columns. - // Remove the name (title) field as this is displayed anyway. - $variables['id'] = $variables['elements']['#oc_case']->get('id')[0]->get('value')->getValue(); - $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, ['created', 'changed', 'files', 'actors_involved', 'status', 'user_id'])) { - $variables['base_fields'][$key] = $variables['elements'][$key]; - } else { - $variables['other_fields'][$key] = $variables['elements'][$key]; - unset($variables['other_fields']['name']); - } - } + _template_preprocess_entity($variables); } + diff --git a/modules/opencase_cases/templates/oc_case.html.twig b/modules/opencase_cases/templates/oc_case.html.twig index 299f447..4427919 100644 --- a/modules/opencase_cases/templates/oc_case.html.twig +++ b/modules/opencase_cases/templates/oc_case.html.twig @@ -16,7 +16,10 @@ */ #} - {% if content %} - {{- content -}} + {% if normal_fields %} +
{{- normal_fields -}}
+ {% endif %} + {% if extra_fields %} +
{{- extra_fields -}}
{% endif %} diff --git a/modules/opencase_entities/oc_organisation.page.inc b/modules/opencase_entities/oc_organisation.page.inc index e7cc6f0..6a8582d 100644 --- a/modules/opencase_entities/oc_organisation.page.inc +++ b/modules/opencase_entities/oc_organisation.page.inc @@ -20,11 +20,5 @@ use Drupal\Core\Render\Element; * - attributes: HTML attributes for the containing element. */ function template_preprocess_oc_organisation(array &$variables) { - // Fetch OCOrganisation Entity Object. - $oc_organisation = $variables['elements']['#oc_organisation']; - - // Helpful $content variable for templates. - foreach (Element::children($variables['elements']) as $key) { - $variables['content'][$key] = $variables['elements'][$key]; - } +_template_preprocess_entity($variables); } diff --git a/modules/opencase_entities/templates/oc_organisation.html.twig b/modules/opencase_entities/templates/oc_organisation.html.twig index 151f6a9..6010d6c 100644 --- a/modules/opencase_entities/templates/oc_organisation.html.twig +++ b/modules/opencase_entities/templates/oc_organisation.html.twig @@ -16,7 +16,10 @@ */ #} - {% if content %} - {{- content -}} + {% if normal_fields %} +
{{- normal_fields -}}
+ {% endif %} + {% if extra_fields %} +
{{- extra_fields -}}
{% endif %} diff --git a/opencase.module b/opencase.module index cb90300..01483fd 100644 --- a/opencase.module +++ b/opencase.module @@ -4,8 +4,9 @@ * Contains opencase.module. */ -use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Render\Element; use Drupal\Core\Access\AccessResult; +use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_element_info_alter(). @@ -14,6 +15,18 @@ function opencase_element_info_alter(array &$types) { $types['datetime']['#process'][] = 'opencase_process_element'; } +function _template_preprocess_entity(&$variables) { + foreach (Element::children($variables['elements']) as $key) { + if (is_extra_field($variables['elements'][$key])) { + $variables['extra_fields'][$key] = $variables['elements'][$key]; + } else { + $variables['normal_fields'][$key] = $variables['elements'][$key]; + } + } +} +function is_extra_field($element){ + return array_key_exists('#field', $element); +} /** * Element process callback for datetime fields. Removes the seconds part.