Skip to content

Commit

Permalink
Refactor resource page blocks helper (#2215)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley authored Jul 18, 2024
1 parent 0ee0598 commit 944984c
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions application/src/View/Helper/ResourcePageBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,43 @@ public function hasBlocks()
}

/**
* Return the block markup for a region of the resource page.
* Get the count of blocks for a region of the resource page.
*
* @return string
* @return int
*/
public function getBlocks()
public function getBlockCount()
{
return $this->hasBlocks()
? count($this->resourcePageBlocks[$this->resourceName][$this->regionName])
: 0;
}

/**
* Return an array of block markup for a region of the resource page.
*
* @return array An array of block markup keyed by the block name
*/
public function getBlocksArray()
{
if (!$this->hasBlocks()) {
return '';
return [];
}
$view = $this->getView();
$blockMarkup = [];
$blocksArray = [];
foreach ($this->resourcePageBlocks[$this->resourceName][$this->regionName] as $blockName) {
$blockLayout = $this->blockLayoutManager->get($blockName);
$blockMarkup[] = $blockLayout->render($view, $this->resource);
$blocksArray[$blockName] = $blockLayout->render($view, $this->resource);
}
return implode('', $blockMarkup);
return $blocksArray;
}

/**
* Return the block markup for a region of the resource page.
*
* @return string
*/
public function getBlocks()
{
return implode('', $this->getBlocksArray());
}
}

0 comments on commit 944984c

Please sign in to comment.