Skip to content

Commit

Permalink
Merge pull request #4 from xini/pull-php82
Browse files Browse the repository at this point in the history
use dynamicData methods instead of dynamic properties for PHP 8.2 compatibility
  • Loading branch information
dizzystuff authored Aug 1, 2023
2 parents fdc80f0 + 0d449f9 commit 58640fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/Extensions/ListingsControllerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

class ListingsControllerExtension extends Extension
{
protected $listedPages;

/**
* Only applicable if no associated Page extended with ListingsPageExtension.
*/
Expand All @@ -24,8 +22,8 @@ public function onBeforeInit()

public function getListedPages()
{
if ($this->owner->listedPages) {
return $this->owner->listedPages;
if ($this->owner->hasDynamicData('listedPages')) {
return $this->owner->getDynamicData('listedPages');
}

$listingsPage = $this->owner->getListingsPage();
Expand Down Expand Up @@ -57,7 +55,7 @@ public function setListedPages($pages)
);
}

$this->owner->listedPages = $pages;
$this->owner->setDynamicData('listedPages', $pages);
return $this;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Extensions/ListingsRootPageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class ListingsRootPageExtension extends ListingsSiteTreeExtension
const ADMIN_MODE_GRIDFIELD = 'gridfield';
const ADMIN_MODE_ADMIN = 'admin';

protected $excludedSiteTreeClassNames;

/*
* Flag to set whether this Listed Pages Root can have only children
* that are in its $listed_pages_classes array.
Expand Down Expand Up @@ -306,8 +304,8 @@ public function updateAllowedChildren(&$allowedChildren)

public function getExcludedSiteTreeClassNames()
{
if (is_null($this->owner->excludedSiteTreeClassNames)) {
$this->owner->excludedSiteTreeClassNames = [];
if ($this->owner->hasDynamicData('excludedSiteTreeClassNames')) {
return $this->owner->getDynamicData('excludedSiteTreeClassNames');
}

$classes = [];
Expand All @@ -323,10 +321,12 @@ public function getExcludedSiteTreeClassNames()
}
}

$this->owner->setDynamicData('excludedSiteTreeClassNames', $classes);

return $classes;
}

public function augmentAllChildrenIncludingDeleted(&$stageChildren, &$context)
public function augmentAllChildrenIncludingDeleted(&$stageChildren)
{
if ($this->shouldFilter()) {
$stageChildren = $stageChildren->exclude('ClassName', $this->getExcludedSiteTreeClassNames());
Expand Down
10 changes: 3 additions & 7 deletions src/Extensions/ListingsSiteTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

class ListingsSiteTreeExtension extends SiteTreeExtension
{
protected $listedPagesCommonClass;
protected $listedPagesCommonSingularName;
protected $listedPagesCommonPluralName;

/**
* You must supply an array of at least one SiteTree class extended
* by ListedPageExtension, identifying which Listed Pages are to be
Expand Down Expand Up @@ -64,12 +60,12 @@ public function getListedPagesParentIDs()

public function getListedPagesCommonClass()
{
if ($this->owner->listedPagesCommonClass) {
return $this->owner->listedPagesCommonClass;
if ($this->owner->hasDynamicData('listedPagesCommonClass')) {
return $this->owner->getDynamicData('listedPagesCommonClass');
}

$class = ListedPages::get_common_class($this->getListedPagesClasses());
$this->owner->listedPagesCommonClass = $class;
$this->owner->setDynamicData('listedPagesCommonClass', $class);

return $class;
}
Expand Down

0 comments on commit 58640fb

Please sign in to comment.