Skip to content

Commit

Permalink
Merge pull request #3 from xini/fix-cms-edit-links
Browse files Browse the repository at this point in the history
fix cms edit links
  • Loading branch information
dizzystuff authored Nov 4, 2021
2 parents 4a206b2 + 8a0fd19 commit 229efeb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Model/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,23 @@ public function CMSEditLink()
{
$link = null;
if ($this->ParentID) {
$link = $this->Parent()->CMSEditLink();
$link = preg_replace('/\/item\/([\d]+)\/edit/', '/item/$1', $link);
$link = Controller::join_links(
$this->Parent()->CMSEditLink(),
$link,
'ItemEditForm/field/Children/item',
$this->ID
$this->ID,
'edit'
);
}
else if ($this->MenuSetID) {
$link = $this->MenuSet()->CMSEditLink();
$link = preg_replace('/\/item\/([\d]+)\/edit/', '/item/$1', $link);
$link = Controller::join_links(
$this->MenuSet()->CMSEditLink(),
$link,
'ItemEditForm/field/Items/item',
$this->ID
$this->ID,
'edit'
);
}
$this->extend('updateCMSEditLink', $link);
Expand Down
29 changes: 29 additions & 0 deletions src/Model/MenuSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Fromholdio\GridFieldLimiter\Forms\GridFieldLimiter;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
Expand All @@ -22,6 +24,8 @@
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\SiteConfig\SiteConfigLeftAndMain;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Versioned\Versioned;
Expand Down Expand Up @@ -448,6 +452,31 @@ public function getCMSFields()
return $fields;
}

public function CMSEditLink()
{
$link = null;
if ($this->ParentID) {
if (is_a($this->Parent(), SiteTree::class)) {
$link = Controller::join_links(
singleton(CMSPageEditController::class)->Link('EditForm'),
$this->ParentID,
'field/MenuSets/item',
$this->ID,
'edit'
);
} elseif (is_a($this->Parent(), SiteConfig::class)) {
$link = Controller::join_links(
singleton(SiteConfigLeftAndMain::class)->Link('EditForm'),
'field/MenuSets/item',
$this->ID,
'edit'
);
}
}
$this->extend('updateCMSEditLink', $link);
return $link;
}

public function canCreate($member = null, $context = null)
{
return Permission::checkMember($member, 'CREATE_MENUSETS');
Expand Down

0 comments on commit 229efeb

Please sign in to comment.