1 layout_renderer_standard.inc LayoutRendererStandard::prepareRegions(array $region_block_list, array $settings)

Prepare the list of regions to be rendered.

This method is primarily about properly initializing the style plugin that will be used to render the region. This is crucial as regions cannot be rendered without a style plugin (in keeping with Layout's philosophy of hardcoding none of its output), but for most regions no style has been explicitly set. The logic here is what accommodates that situation:

  • If a region has had its style explicitly set, then we fetch that plugin and continue.
  • If the region has no explicit style, but a style was set at the layout level, then inherit the style from the layout.
  • If neither the region nor the layout have explicitly set styles, then fall back to the hardcoded 'default' style, a very minimal style.

The other important task accomplished by this method is ensuring that even regions without any blocks are still properly prepared for the rendering process. This is essential because the way layouts are loaded, results only in a list of regions that contain blocks - not necessarily all the regions defined by the layout plugin, which can only be determined by asking the plugin at runtime. This method consults that retrieved list of regions and prepares all of those, ensuring none are inadvertently skipped.

Parameters

array $region_block_list: An associative array of block IDs, keyed on the region to which those IDs are assigned.

array $settings: All known region style settings, including both the top-level layout's settings (if any) and all region-specific settings (if any).

Return value

array: An array of regions prepared for rendering.

File

core/modules/layout/plugins/renderers/layout_renderer_standard.inc, line 299

Class

LayoutRendererStandard
The standard render for a Layout display object.

Code

function prepareRegions(array $region_block_list, array $settings) {
  // Initialize defaults to be used for regions without their own explicit
  // settings. Use display settings if they exist, else hardcoded defaults.
  $default = array(
    'style' => !empty($settings['style']) ? $settings['style'] : 'default',
    'style settings' => isset($settings['style_settings']['default']) ? $settings['style_settings']['default'] : array(),
  );
  $regions = array();
  if (empty($settings)) {
    // No region settings exist, init all with the defaults.
    foreach ($this->layout_info['regions'] as $region_id => $title) {
      // Ensure this region has at least an empty block array.
      $blocks = array();
      if (isset($region_block_list[$region_id])) {
        $blocks = $region_block_list[$region_id];
      }

      $regions[$region_id] = $default;
      $regions[$region_id]['uuids'] = $blocks;
    }
  }
  else {
    // Some settings exist; iterate through each region and set individually.
    foreach ($this->layout_info['regions'] as $region_id => $title) {
      // Ensure this region has at least an empty blocks array.
      $blocks = !empty($region_block_list[$region_id]) ? $region_block_list[$region_id] : array();

      if (empty($settings[$region_id]['style']) || $settings[$region_id]['style'] == -1) {
        $regions[$region_id] = $default;
      }
      else {
        $regions[$region_id]['style'] = $settings[$region_id]['style'];
      }

      $regions[$region_id]['style settings'] = isset($settings[$region_id]) ? $settings[$region_id] : array();
      $regions[$region_id]['uuids'] = $blocks;
    }
  }

  $this->prepared['regions'] = $regions;
  return $this->prepared['regions'];
}