You are here

function farm_ui_theme_build_stacked_twocol_layout in farmOS 2.x

Splits content into a stacked two-column layout.

Parameters

array $variables: A $variables array that contains a 'content' item, which will be replaced by a stacked two-column layout.

string $entity_type: The entity type.

3 calls to farm_ui_theme_build_stacked_twocol_layout()
farm_ui_theme_preprocess_asset__full in modules/core/ui/theme/farm_ui_theme.module
Implements hook_preprocess_HOOK().
farm_ui_theme_preprocess_log__full in modules/core/ui/theme/farm_ui_theme.module
Implements hook_preprocess_HOOK().
farm_ui_theme_preprocess_plan__full in modules/core/ui/theme/farm_ui_theme.module
Implements hook_preprocess_HOOK().

File

modules/core/ui/theme/farm_ui_theme.module, line 93
The farmOS UI Theme module.

Code

function farm_ui_theme_build_stacked_twocol_layout(array &$variables, string $entity_type) {

  // 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 = [];
  foreach ($variables['content'] as $index => $item) {
    foreach ($region_items as $region_name => $items) {
      $region = 'first';
      if (in_array($index, $items)) {
        $region = $region_name;
        break;
      }
    }
    $regions[$region][$index] = $item;
  }

  // Build the layout.

  /** @var \Drupal\Core\Layout\LayoutInterface $layoutInstance */
  $layout = \Drupal::service('plugin.manager.core.layout')
    ->createInstance('layout_twocol', []);
  $variables['content'] = $layout
    ->build($regions);
}