diff --git a/CHANGELOG.md b/CHANGELOG.md index e64280a3..c4330f77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ In order to read more about upgrading and BC breaks have a look at the [UPGRADE ## 5.0.1 + [#400](https://github.com/luyadev/luya-module-cms/pull/400) Improved translations (bg, cn, es, fr, hu, id, kr, nl, pl) and updated link to new guide. ++ [#401](https://github.com/luyadev/luya-module-cms/issues/401) Fixed issue with missing env options. ## 5.0.0 (30. November 2023) diff --git a/src/models/NavItemPage.php b/src/models/NavItemPage.php index 758093bb..096159fb 100644 --- a/src/models/NavItemPage.php +++ b/src/models/NavItemPage.php @@ -432,9 +432,27 @@ public static function getPlaceholder($placeholderVar, $prevId, NavItemPage $nav ->all(); $data = []; + $i = 0; + $equalIndex = 1; + $blocksCount = count($nav_item_page_block_item_data); - foreach ($nav_item_page_block_item_data as $blockItem) { - $item = self::getBlockItem($blockItem, $navItemPage); + foreach ($nav_item_page_block_item_data as $key => $blockItem) { + $i++; + $prev = $key - 1; + $next = $key + 1; + $prevIsEqual = array_key_exists($prev, $nav_item_page_block_item_data) && $blockItem['block_id'] == $nav_item_page_block_item_data[$prev]['block_id']; + + $envOptions = [ + 'index' => $i, + 'itemsCount' => $blocksCount, + 'isFirst' => ($i == 1), + 'isLast' => ($i == $blocksCount), + 'isPrevEqual' => $prevIsEqual, + 'isNextEqual' => array_key_exists($next, $nav_item_page_block_item_data) && $blockItem['block_id'] == $nav_item_page_block_item_data[$next]['block_id'], + 'equalIndex' => (!$prevIsEqual) ? ($equalIndex = 1) : ($equalIndex++) + ]; + + $item = self::getBlockItem($blockItem, $navItemPage, $envOptions); if ($item) { $data[] = $item; } @@ -451,7 +469,7 @@ public static function getPlaceholder($placeholderVar, $prevId, NavItemPage $nav * @param integer $blockId * @return array */ - public static function getBlockItem(NavItemPageBlockItem $blockItem, NavItemPage $navItemPage) + public static function getBlockItem(NavItemPageBlockItem $blockItem, NavItemPage $navItemPage, array $envOptions = []) { // if the block relation could be found, return false. if (!$blockItem->block) { @@ -471,7 +489,9 @@ public static function getBlockItem(NavItemPageBlockItem $blockItem, NavItemPage $blockObject->setVarValues((empty($blockValue)) ? [] : $blockValue); $blockObject->setCfgValues((empty($blockCfgValue)) ? [] : $blockCfgValue); - + foreach ($envOptions as $envKey => $envValue) { + $blockObject->setEnvOption($envKey, $envValue); + } $placeholders = []; foreach ($blockObject->getConfigPlaceholdersByRowsExport() as $rowKey => $row) {