Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing env informations to block #401 #403

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
28 changes: 24 additions & 4 deletions src/models/NavItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Loading