div around fields and static fields at top, for orgs and cases

This commit is contained in:
naomi 2022-05-16 20:18:49 +01:00
parent d483b3f47e
commit cfec9be05c
5 changed files with 28 additions and 26 deletions

View File

@ -8,6 +8,7 @@
*/ */
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\opencase;
/** /**
* Prepares variables for Case templates. * Prepares variables for Case templates.
@ -20,18 +21,6 @@ use Drupal\Core\Render\Element;
* - attributes: HTML attributes for the containing element. * - attributes: HTML attributes for the containing element.
*/ */
function template_preprocess_oc_case(array &$variables) { function template_preprocess_oc_case(array &$variables) {
// Separate the fields into two sections to be displayed in two columns. _template_preprocess_entity($variables);
// 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']);
}
}
} }

View File

@ -16,7 +16,10 @@
*/ */
#} #}
<div{{ attributes.addClass('oc_case') }}> <div{{ attributes.addClass('oc_case') }}>
{% if content %} {% if normal_fields %}
{{- content -}} <div id='static_data'>{{- normal_fields -}}</div>
{% endif %}
{% if extra_fields %}
<div id='dynamic_data'>{{- extra_fields -}}</div>
{% endif %} {% endif %}
</div> </div>

View File

@ -20,11 +20,5 @@ use Drupal\Core\Render\Element;
* - attributes: HTML attributes for the containing element. * - attributes: HTML attributes for the containing element.
*/ */
function template_preprocess_oc_organisation(array &$variables) { function template_preprocess_oc_organisation(array &$variables) {
// Fetch OCOrganisation Entity Object. _template_preprocess_entity($variables);
$oc_organisation = $variables['elements']['#oc_organisation'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
} }

View File

@ -16,7 +16,10 @@
*/ */
#} #}
<div{{ attributes.addClass('oc_organisation') }}> <div{{ attributes.addClass('oc_organisation') }}>
{% if content %} {% if normal_fields %}
{{- content -}} <div id='static_data'>{{- normal_fields -}}</div>
{% endif %}
{% if extra_fields %}
<div id='dynamic_data'>{{- extra_fields -}}</div>
{% endif %} {% endif %}
</div> </div>

View File

@ -4,8 +4,9 @@
* Contains opencase.module. * Contains opencase.module.
*/ */
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Render\Element;
use Drupal\Core\Access\AccessResult; use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatchInterface;
/** /**
* Implements hook_element_info_alter(). * Implements hook_element_info_alter().
@ -14,6 +15,18 @@ function opencase_element_info_alter(array &$types) {
$types['datetime']['#process'][] = 'opencase_process_element'; $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. * Element process callback for datetime fields. Removes the seconds part.