From 944984c96a4f1ee72fa21184ef8a02cbf673e373 Mon Sep 17 00:00:00 2001 From: Jim Safley Date: Thu, 18 Jul 2024 14:17:53 -0400 Subject: [PATCH] Refactor resource page blocks helper (#2215) --- .../src/View/Helper/ResourcePageBlocks.php | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/application/src/View/Helper/ResourcePageBlocks.php b/application/src/View/Helper/ResourcePageBlocks.php index c7e7751ef..eb6ed2c47 100644 --- a/application/src/View/Helper/ResourcePageBlocks.php +++ b/application/src/View/Helper/ResourcePageBlocks.php @@ -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()); } }