Skip to content

Commit

Permalink
Merge pull request #8 from xini/pull-configured-multisites
Browse files Browse the repository at this point in the history
add compatibility with configured multisites
  • Loading branch information
dizzystuff authored Mar 30, 2024
2 parents 07a2e55 + 5fae2dc commit f1f7f39
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
20 changes: 14 additions & 6 deletions src/Extensions/MenuSetParentAccessorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
18 changes: 14 additions & 4 deletions src/Extensions/MenuSetParentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Model/MenuSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit f1f7f39

Please sign in to comment.