Skip to content

Commit

Permalink
Merge pull request #408 from luyadev/nav-item
Browse files Browse the repository at this point in the history
ensure getEnvOption('pageObject'') resolves the PageObject
  • Loading branch information
nadar authored Feb 7, 2024
2 parents 5d59cc6 + aac53b7 commit 2e8df4b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 5.0.1
## 5.1.0

> This release contains a very small change when using the block `getEnvOption('pageObject')`. Check the [UPGRADE document](UPGRADE.md) to read more about.
+ [#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).
+ [#404](https://github.com/luyadev/luya-module-cms/pull/404) Cmsadmin padding fix for blockholder collapsed
+ [#406](https://github.com/luyadev/luya-module-cms/pull/406) Fixed website and theme status ActiveButtons (PHP 8)
+ [#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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ If you want to contribute, make sure to read the [guidelines](https://luya.io/gu
## Unit Testing

1. `cp phpunit.xml.dist phpunit.xml`
2. `docker-compose up`
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.
2. `docker compose up`
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.
24 changes: 24 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

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.

## 5.0 to 5.1

**Upgrade Notice: Changes to `Block->getEnvOption('pageObject')` Behavior**

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.

**Action Required for Developers:**

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`.

**Example of Required Code Adjustments:**

- **Previous Approach:** To obtain the title of a `NavItem`, you might have used:
```php
getEnvOption('pageObject')->one()->title
```

- **New Approach:** To achieve the same outcome in the updated version, you should modify your code to:
```php
getEnvOption('pageObject')->navItem->title
```

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.

## 4.x to 5.0

+ 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`.
Expand Down
21 changes: 9 additions & 12 deletions src/models/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,26 @@ public static function findObjectClassesById(array $ids)
}

/**
* Get the object from current object-context (classname).
*
* @param [type] $id
* @param [type] $context
* @param [type] $pageObject
* @return void
* @param int $id
* @param string $context
* @param NavItemPage|null $pageObject
* @since 1.0.6
*/
public function getObject($id, $context, $pageObject = null)
public function getObject($id, $context, NavItemPage $pageObject = null): false|\luya\cms\base\BlockInterface
{
return self::createObject($this->class, $this->id, $id, $context, $pageObject);
}

/**
* Creates the block object and stores the object within a static block container.
*
* @param string $class
* @param integer $blockId The id of the cms_block table
* @param integer $id The context id, the cms_nav_item_page_block_item unique id
* @param string $class The block object class name.
* @param int $blockId The id of the cms_block table
* @param int $id The context id, the cms_nav_item_page_block_item unique id
* @param string $context admin or frontend
* @return \luya\cms\base\BlockInterface
* @param NavItemPage|null $pageObject
*/
public static function createObject($class, $blockId, $id, $context, mixed $pageObject = null)
public static function createObject($class, $blockId, $id, $context, NavItemPage $pageObject = null): false|\luya\cms\base\BlockInterface
{
if (!class_exists($class)) {
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/models/NavItemPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @property string $version_alias
* @property Layout $layout
* @property NavItem $forceNavItem
* @property NavItemPageBlockItems[] $navItemPageBlockItems
*
* @author Basil Suter <[email protected]>
* @since 1.0.0
Expand Down Expand Up @@ -241,7 +242,7 @@ private function renderPlaceholderRecursive($navItemPageId, $placeholderVar, $pr
$cacheKey = ['blockcache', (int) $placeholder['id']];

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

if ($blockObject) {
$isCachingEnabled = $blockObject->getIsCacheEnabled() && $this->isGuest();
Expand Down

0 comments on commit 2e8df4b

Please sign in to comment.