Skip to content

Commit

Permalink
Apply getCurrentMenuSetParent to Controller automatically, with updat…
Browse files Browse the repository at this point in the history
…e hook
  • Loading branch information
dizzystuff committed Aug 2, 2022
1 parent c5b6329 commit c0e3fc1
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
Name: fromholdio-superlinker-menus
---

SilverStripe\Control\Controller:
extensions:
menuSetParent: Fromholdio\SuperLinkerMenus\Extensions\MenuSetParentAccessorExtension
23 changes: 23 additions & 0 deletions src/Extensions/MenuSetParentAccessorExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Fromholdio\SuperLinkerMenus\Extensions;

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()
: SiteConfig::current_site_config();
$this->getOwner()->invokeWithExtensions('updateCurrentMenuSetParent', $parent);
return $parent;
}
}

0 comments on commit c0e3fc1

Please sign in to comment.