Add hook_farm_ui_theme_region_items() for defining asset, log, and plan content region items.

This commit is contained in:
Michael Stenta 2021-09-08 08:37:18 -04:00
parent 98aa8b5ee0
commit c6112ff7f6
2 changed files with 119 additions and 22 deletions

View File

@ -0,0 +1,49 @@
<?php
/**
* @file
* Hooks provided by farm_ui_theme.
*
* This file contains no working PHP code; it exists to provide additional
* documentation for doxygen as well as to document hooks in the standard
* Drupal manner.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Specify the regions that asset, log, and plan content items should be in.
*
* @param string $entity_type
* The entity type ('asset', 'log', or 'plan').
*
* @return array
* An array of item name arrays, keyed by region name ('top', 'first',
* 'second', 'bottom'). For example:
* [
* 'top' => [],
* 'first' => [],
* 'second' => [
* 'status',
* 'type',
* ],
* 'bottom' => [],
* ];
*/
function hook_farm_ui_theme_region_items(string $entity_type) {
if ($entity_type == 'log') {
return [
'second' => [
'is_movement',
],
];
}
return [];
}
/**
* @} End of "addtogroup hooks".
*/

View File

@ -61,21 +61,21 @@ function farm_ui_theme_preprocess_field__flag(array &$variables) {
* Implements hook_preprocess_HOOK().
*/
function farm_ui_theme_preprocess_asset__full(&$variables) {
farm_ui_theme_build_stacked_twocol_layout($variables);
farm_ui_theme_build_stacked_twocol_layout($variables, 'asset');
}
/**
* Implements hook_preprocess_HOOK().
*/
function farm_ui_theme_preprocess_log__full(&$variables) {
farm_ui_theme_build_stacked_twocol_layout($variables);
farm_ui_theme_build_stacked_twocol_layout($variables, 'log');
}
/**
* Implements hook_preprocess_HOOK().
*/
function farm_ui_theme_preprocess_plan__full(&$variables) {
farm_ui_theme_build_stacked_twocol_layout($variables);
farm_ui_theme_build_stacked_twocol_layout($variables, 'plan');
}
/**
@ -84,27 +84,13 @@ function farm_ui_theme_preprocess_plan__full(&$variables) {
* @param array $variables
* A $variables array that contains a 'content' item, which will be replaced
* by a stacked two-column layout.
* @param string $entity_type
* The entity type.
*/
function farm_ui_theme_build_stacked_twocol_layout(array &$variables) {
function farm_ui_theme_build_stacked_twocol_layout(array &$variables, string $entity_type) {
// Define the region items.
$region_items = [
'top' => [
'geometry',
],
'first' => [],
'second' => [
'image',
'is_location',
'is_fixed',
'location',
'status',
'type',
],
'bottom' => [
'file',
],
];
// Ask modules for a list of region items.
$region_items = \Drupal::moduleHandler()->invokeAll('farm_ui_theme_region_items', [$entity_type]);
// Split the content items into regions.
$regions = [];
@ -124,3 +110,65 @@ function farm_ui_theme_build_stacked_twocol_layout(array &$variables) {
$layout = \Drupal::service('plugin.manager.core.layout')->createInstance('layout_twocol', []);
$variables['content'] = $layout->build($regions);
}
/**
* Implements hook_farm_ui_theme_region_items().
*/
function farm_ui_theme_farm_ui_theme_region_items(string $entity_type) {
// Define common asset, log, and plan region items on behalf of core modules.
switch ($entity_type) {
case 'asset':
return [
'top' => [
'geometry',
],
'first' => [],
'second' => [
'image',
'is_location',
'is_fixed',
'location',
'status',
'type',
],
'bottom' => [
'file',
],
];
case 'log':
return [
'top' => [
'geometry',
],
'first' => [],
'second' => [
'image',
'status',
'type',
],
'bottom' => [
'file',
],
];
case 'plan':
return [
'top' => [],
'first' => [],
'second' => [
'image',
'status',
'type',
],
'bottom' => [
'file',
],
];
default:
return [];
}
}