1.20.x layout.class.inc Layout::addBlock($block_module, $block_delta, $region_name, $position = NULL)

Add a block to a particular region.

Parameters

string $block_module: The module providing the block to be positioned.

string $block_delta: The block delta from hook_block_info().

string $region_name: The name of the region within the layout.

int $position: The position of the block within the region. If not specified, the block will be the last block within the specified region.

Return value

Block: The newly added block instance.

File

modules/layout/includes/layout.class.inc, line 519
Class for loading, modifying, and executing a layout.

Class

Layout
@file Class for loading, modifying, and executing a layout.

Code

function addBlock($block_module, $block_delta, $region_name, $position = NULL) {
  $block = layout_create_handler('block', $block_module . ':' . $block_delta);
  $uuid = new Uuid();
  $block->uuid = $uuid->generate();

  $this->content[$block->uuid] = $block;
  $this->positions[$region_name][] = $block->uuid;

  // Move the block into the correct position.
  if ($position) {
    $positions = array();
    foreach ($this->positions[$region_name] as $n => $uuid) {
      if ($position == $n) {
        $positions[] = $block->uuid;
      }
      if ($uuid != $block->uuid) {
        $positions[] = $uuid;
      }
    }
    $this->positions[$region_name] = $positions;
  }

  return $block;
}