From 5fae2dc981b780b30fd4088e71c960ffb1ea9bdb Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Fri, 23 Feb 2024 11:01:38 +1100 Subject: [PATCH] add compatibility with configured multisites --- .../MenuSetParentAccessorExtension.php | 20 +++++++++++++------ src/Extensions/MenuSetParentExtension.php | 18 +++++++++++++---- src/Model/MenuSet.php | 2 +- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Extensions/MenuSetParentAccessorExtension.php b/src/Extensions/MenuSetParentAccessorExtension.php index 2aa5a9e..2cb09ff 100644 --- a/src/Extensions/MenuSetParentAccessorExtension.php +++ b/src/Extensions/MenuSetParentAccessorExtension.php @@ -5,19 +5,27 @@ use SilverStripe\Core\Extension; use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\SiteConfig\SiteConfig; -use Symbiote\Multisites\Multisites; class MenuSetParentAccessorExtension extends Extension { public function getCurrentMenuSetParent() { - $isMultisites = ModuleLoader::inst() - ->getManifest() - ->moduleExists('symbiote/silverstripe-multisites'); - $parent = $isMultisites - ? Multisites::inst()->getCurrentSite() + $parent = ($multisitesClass = $this->getOwner()->getMultisitesClassName()) + ? $multisitesClass::inst()->getCurrentSite() : SiteConfig::current_site_config(); $this->getOwner()->invokeWithExtensions('updateCurrentMenuSetParent', $parent); return $parent; } + + public function getMultisitesClassName(): ?string + { + $manifest = ModuleLoader::inst()->getManifest(); + if ($manifest->moduleExists('symbiote/silverstripe-multisites')) { + return \Symbiote\Multisites\Multisites::class; + } + if ($manifest->moduleExists('fromholdio/silverstripe-configured-multisites')) { + return \Fromholdio\ConfiguredMultisites\Multisites::class; + } + return null; + } } diff --git a/src/Extensions/MenuSetParentExtension.php b/src/Extensions/MenuSetParentExtension.php index f9d5ef3..8b7aba1 100644 --- a/src/Extensions/MenuSetParentExtension.php +++ b/src/Extensions/MenuSetParentExtension.php @@ -13,7 +13,6 @@ use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\Forms\GridField\GridFieldToolbarHeader; use SilverStripe\ORM\DataExtension; -use Symbiote\Multisites\Model\Site; class MenuSetParentExtension extends DataExtension { @@ -63,13 +62,24 @@ public function updateCMSFields(FieldList $fields) public function updateSiteCMSFields(FieldList $fields) { - $multiSitesExists = ModuleLoader::inst()->getManifest() - ->moduleExists('symbiote/silverstripe-multisites'); - if ($multiSitesExists && is_a($this->getOwner(), Site::class)) { + $siteClass = $this->getOwner()->getMultisitesSiteClassName(); + if (!empty($siteClass) && is_a($this->getOwner(), $siteClass)) { $this->updateCMSFields($fields); } } + public function getMultisitesSiteClassName(): ?string + { + $manifest = ModuleLoader::inst()->getManifest(); + if ($manifest->moduleExists('symbiote/silverstripe-multisites')) { + return \Symbiote\Multisites\Model\Site::class; + } + if ($manifest->moduleExists('fromholdio/silverstripe-configured-multisites')) { + return \Fromholdio\ConfiguredMultisites\Model\Site::class; + } + return null; + } + public function getMenuSetsTabPath() { $path = $this->getOwner()->config()->get('menusets_tab_path'); diff --git a/src/Model/MenuSet.php b/src/Model/MenuSet.php index df9b9ee..ef3701f 100644 --- a/src/Model/MenuSet.php +++ b/src/Model/MenuSet.php @@ -85,7 +85,7 @@ public function MenuItems() if (($items = $this->Items()) && $items->exists()) { $output = ArrayList::create(); foreach ($items as $item) { - if ($item->HasTarget()) { + if ($item->isLinkValid()) { $output->push($item); } }