Skip to content

Commit 2e8df4b

Browse files
authored
Merge pull request #408 from luyadev/nav-item
ensure getEnvOption('pageObject'') resolves the PageObject
2 parents 5d59cc6 + aac53b7 commit 2e8df4b

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/).
44
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).
55

6-
## 5.0.1
6+
## 5.1.0
77

8+
> This release contains a very small change when using the block `getEnvOption('pageObject')`. Check the [UPGRADE document](UPGRADE.md) to read more about.
9+
10+
+ [#408](https://github.com/luyadev/luya-module-cms/pull/408) Resolved an issue where the CMS `pageObject` returned an ActiveQuery instead of the expected `NavItemPage` object. For more details, refer to the [UPGRADE document](UPGRADE.md).
811
+ [#404](https://github.com/luyadev/luya-module-cms/pull/404) Cmsadmin padding fix for blockholder collapsed
912
+ [#406](https://github.com/luyadev/luya-module-cms/pull/406) Fixed website and theme status ActiveButtons (PHP 8)
1013
+ [#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.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ If you want to contribute, make sure to read the [guidelines](https://luya.io/gu
6767
## Unit Testing
6868

6969
1. `cp phpunit.xml.dist phpunit.xml`
70-
2. `docker-compose up`
71-
3. `docker-compose run luyacmsphpunit tests` to run all tests or `docker-compose run luyacmsphpunit tests/src/helpers/UrlTest.php` to run a specific test.
70+
2. `docker compose up`
71+
3. `docker compose run luyacmsphpunit tests` to run all tests or `docker compose run luyacmsphpunit tests/src/helpers/UrlTest.php` to run a specific test.

UPGRADE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
This document will help you upgrading from a LUYA admin module version into another. For more detailed informations about the breaking changes **click the issue detail link**, there you can examples of how to change your code.
44

5+
## 5.0 to 5.1
6+
7+
**Upgrade Notice: Changes to `Block->getEnvOption('pageObject')` Behavior**
8+
9+
In previous versions, the method `getEnvOption('pageObject')` incorrectly returned an `ActiveQuery` object, which was intended to resolve into a `NavItem` instance. We have corrected this issue in the latest update. Now, `getEnvOption('pageObject')` properly returns a `NavItemPage` object as expected.
10+
11+
**Action Required for Developers:**
12+
13+
If your code utilizes the `getEnvOption('pageObject')` method, you will need to make adjustments to ensure compatibility with the current version. To access the `NavItem` object, which was the original behavior facilitated through an `ActiveQuery`, you should now use the following approach: `getEnvOption('pageObject')->navItem`.
14+
15+
**Example of Required Code Adjustments:**
16+
17+
- **Previous Approach:** To obtain the title of a `NavItem`, you might have used:
18+
```php
19+
getEnvOption('pageObject')->one()->title
20+
```
21+
22+
- **New Approach:** To achieve the same outcome in the updated version, you should modify your code to:
23+
```php
24+
getEnvOption('pageObject')->navItem->title
25+
```
26+
27+
This change ensures more intuitive access to the `NavItem` properties directly through the `NavItemPage` object, streamlining the process of fetching page-related data. Please review your projects and update any relevant code segments to align with this new method of accessing `NavItem` properties.
28+
529
## 4.x to 5.0
630

731
+ This release contains the new migrations which are required for the user and file table. Therefore make sure to run the `./vendor/bin/luya migrate` command after `composer update`.

src/models/Block.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,29 +249,26 @@ public static function findObjectClassesById(array $ids)
249249
}
250250

251251
/**
252-
* Get the object from current object-context (classname).
253-
*
254-
* @param [type] $id
255-
* @param [type] $context
256-
* @param [type] $pageObject
257-
* @return void
252+
* @param int $id
253+
* @param string $context
254+
* @param NavItemPage|null $pageObject
258255
* @since 1.0.6
259256
*/
260-
public function getObject($id, $context, $pageObject = null)
257+
public function getObject($id, $context, NavItemPage $pageObject = null): false|\luya\cms\base\BlockInterface
261258
{
262259
return self::createObject($this->class, $this->id, $id, $context, $pageObject);
263260
}
264261

265262
/**
266263
* Creates the block object and stores the object within a static block container.
267264
*
268-
* @param string $class
269-
* @param integer $blockId The id of the cms_block table
270-
* @param integer $id The context id, the cms_nav_item_page_block_item unique id
265+
* @param string $class The block object class name.
266+
* @param int $blockId The id of the cms_block table
267+
* @param int $id The context id, the cms_nav_item_page_block_item unique id
271268
* @param string $context admin or frontend
272-
* @return \luya\cms\base\BlockInterface
269+
* @param NavItemPage|null $pageObject
273270
*/
274-
public static function createObject($class, $blockId, $id, $context, mixed $pageObject = null)
271+
public static function createObject($class, $blockId, $id, $context, NavItemPage $pageObject = null): false|\luya\cms\base\BlockInterface
275272
{
276273
if (!class_exists($class)) {
277274
return false;

src/models/NavItemPage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* @property string $version_alias
2626
* @property Layout $layout
2727
* @property NavItem $forceNavItem
28+
* @property NavItemPageBlockItems[] $navItemPageBlockItems
2829
*
2930
* @author Basil Suter <basil@nadar.io>
3031
* @since 1.0.0
@@ -241,7 +242,7 @@ private function renderPlaceholderRecursive($navItemPageId, $placeholderVar, $pr
241242
$cacheKey = ['blockcache', (int) $placeholder['id']];
242243

243244
/** @var $blockObject \luya\cms\base\InternalBaseBlock */
244-
$blockObject = Block::createObject($placeholder['class'], $placeholder['block_id'], $placeholder['id'], 'frontend', $this->getNavItem());
245+
$blockObject = Block::createObject($placeholder['class'], $placeholder['block_id'], $placeholder['id'], 'frontend', $this);
245246

246247
if ($blockObject) {
247248
$isCachingEnabled = $blockObject->getIsCacheEnabled() && $this->isGuest();

0 commit comments

Comments
 (0)