Skip to content

Commit

Permalink
POC DO NOT MERGE - Make CMS Main work with other models
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed May 9, 2024
1 parent 117dc25 commit 769136f
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 103 deletions.
335 changes: 251 additions & 84 deletions code/Controllers/CMSMain.php

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions code/Controllers/CMSPageAddController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ class CMSPageAddController extends CMSPageEditController
public function AddForm()
{
$pageTypes = [];
$defaultIcon = Config::inst()->get(SiteTree::class, 'icon_class');
$defaultIcon = Config::inst()->get($this->getTreeClass(), 'icon_class');

foreach ($this->PageTypes() as $type) {
$class = $type->getField('ClassName');
$icon = Config::inst()->get($class, 'icon_class') ?: $defaultIcon;

// If the icon is the SiteTree default and there's some specific icon being provided by `getPageIconURL`
// If the icon is the default and there's some specific icon being provided by `getPageIconURL`
// then we don't need to add the icon class. Otherwise the class take precedence.
if ($icon === $defaultIcon && !empty(singleton($class)->getPageIconURL())) {
$singleton = $class::singleton();
if ($icon === $defaultIcon && !empty($singleton->hasMethod('getPageIconURL') ? $singleton->getPageIconURL() : null)) {
$icon = '';
}

Expand Down Expand Up @@ -90,7 +91,7 @@ public function AddForm()
$parentField = new TreeDropdownField(
"ParentID",
"",
SiteTree::class,
$this->getTreeClass(),
'ID',
'TreeTitle'
),
Expand Down Expand Up @@ -145,7 +146,7 @@ public function AddForm()

// Check if the current user has enough permissions to create top level pages
// If not, then disable the option to do that
if (!SiteConfig::current_site_config()->canCreateTopLevel()) {
if (is_a($this->getTreeClass(), SiteTree::class, true) && !SiteConfig::current_site_config()->canCreateTopLevel()) {
$topField->setDisabled(true);
$parentModeField->setValue('child');
}
Expand Down Expand Up @@ -194,14 +195,14 @@ public function doAdd(array $data, Form $form): HTTPResponse
$parentID = isset($data['ParentID']) ? (int)$data['ParentID'] : 0;

if (!$parentID && isset($data['Parent'])) {
$page = SiteTree::get_by_link($data['Parent']);
$page = $this->getTreeClass()::get_by_link($data['Parent']);
if ($page) {
$parentID = $page->ID;
}
}

if (is_numeric($parentID) && $parentID > 0) {
$parentObj = SiteTree::get()->byID($parentID);
$parentObj = $this->getTreeClass()::get()->byID($parentID);
} else {
$parentObj = null;
}
Expand Down
10 changes: 4 additions & 6 deletions code/Controllers/CMSPageEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace SilverStripe\CMS\Controllers;

use Page;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\CampaignAdmin\AddToCampaignHandler;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
Expand Down Expand Up @@ -57,7 +55,7 @@ public function getClientConfig()
public function addtocampaign(array $data, Form $form): HTTPResponse
{
$id = $data['ID'];
$record = \Page::get()->byID($id);
$record = $this->getTreeClass()::get()->byID($id);

$handler = AddToCampaignHandler::create($this, $record);
$response = $handler->addToCampaign($record, $data);
Expand Down Expand Up @@ -96,14 +94,14 @@ public function AddToCampaignForm($request)
public function getAddToCampaignForm($id)
{
// Get record-specific fields
$record = SiteTree::get()->byID($id);
$record = $this->getTreeClass()::get()->byID($id);

if (!$record) {
$this->httpError(404, _t(
__CLASS__ . '.ErrorNotFound',
'That {Type} couldn\'t be found',
'',
['Type' => Page::singleton()->i18n_singular_name()]
['Type' => $this->getTreeClass()::singleton()->i18n_singular_name()]
));
return null;
}
Expand All @@ -112,7 +110,7 @@ public function getAddToCampaignForm($id)
__CLASS__.'.ErrorItemPermissionDenied',
'It seems you don\'t have the necessary permissions to add {ObjectTitle} to a campaign',
'',
['ObjectTitle' => Page::singleton()->i18n_singular_name()]
['ObjectTitle' => $this->getTreeClass()::singleton()->i18n_singular_name()]
));
return null;
}
Expand Down
8 changes: 6 additions & 2 deletions code/Controllers/CMSPageSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ class CMSPageSettingsController extends CMSMain
public function getEditForm($id = null, $fields = null)
{
$record = $this->getRecord($id ?: $this->currentPageID());

return parent::getEditForm($id, ($record) ? $record->getSettingsFields() : null);
if ($record && $record->hasMethod('getSettingsFields')) {
$fields = $record->getSettingsFields();
} else {
$fields = null;
}
return parent::getEditForm($id, $fields);
}

public function getTabIdentifier()
Expand Down
3 changes: 1 addition & 2 deletions code/Controllers/CMSPagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SilverStripe\CMS\Controllers;

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
Expand Down Expand Up @@ -37,7 +36,7 @@ public function Breadcrumbs($unlinked = false)
$this->beforeExtending('updateBreadcrumbs', function (ArrayList $items) {
//special case for building the breadcrumbs when calling the listchildren Pages ListView action
if ($parentID = $this->getRequest()->getVar('ParentID')) {
$page = SiteTree::get()->byID($parentID);
$page = $this->getTreeClass()::get()->byID($parentID);

//build a reversed list of the parent tree
$pages = [];
Expand Down
18 changes: 17 additions & 1 deletion templates/BreadcrumbsTemplate.ss
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<%-- Loop is all on one line to prevent whitespace bug in older versions of IE --%>
<% if $Pages %>
<% loop $Pages %><% if $IsLast %>$MenuTitle.XML<% else %><% if not Up.Unlinked %><a href="$Link" class="breadcrumb-$Pos"><% end_if %>$MenuTitle.XML<% if not Up.Unlinked %></a><% end_if %> $Up.Delimiter.RAW <% end_if %><% end_loop %>
<% loop $Pages %>
<% if $IsLast %>
<% if $hasField('MenuTitle') %>
$MenuTitle.XML
<% else %>
$Title.XML
<% end_if %>
<% else %>
<% if not Up.Unlinked %><a href="$Link" class="breadcrumb-$Pos"><% end_if %>
<% if $hasField('MenuTitle') %>
$MenuTitle.XML
<% else %>
$Title.XML
<% end_if %>
<% if not Up.Unlinked %></a><% end_if %> $Up.Delimiter.RAW
<% end_if %>
<% end_loop %>
<% end_if %>
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<%t SilverStripe\\CMS\\Controllers\\CMSMain.TabContent 'Content' %>
</a>
</li>
<% if $LinkPageSettings %>
<li class="nav-item content-listview<% if $TabIdentifier == 'settings' %> ui-tabs-active<% end_if %>">
<a href="$LinkPageSettings" class="nav-link cms-panel-link" title="Form_EditForm" data-href="$LinkPageSettings">
<%t SilverStripe\\CMS\\Controllers\\CMSMain.TabSettings 'Settings' %>
</a>
</li>
<% end_if %>
<li class="nav-item content-listview<% if $TabIdentifier == 'history' %> ui-tabs-active<% end_if %>">
<a href="$LinkPageHistory" class="nav-link cms-panel-link" title="Form_EditForm" data-href="$LinkPageHistory">
<%t SilverStripe\\CMS\\Controllers\\CMSMain.TabHistory 'History' %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<li id="record-{$node.ID}" data-id="{$node.ID}" data-pagetype="{$node.ClassName}" class="$markingClasses $extraClass"><ins class="jstree-icon font-icon-right-dir">&nbsp;</ins>
<a href="{$node.CMSEditLink.ATT}" title="{$Title.ATT}"><ins class="jstree-icon font-icon-drag-handle">&nbsp;</ins>
<span class="text">{$node.TreeTitle}</span>
<span class="text">
<% if $node.hasField('TreeTitle') %>
$node.TreeTitle
<% else %>
<% if $node.hasField('MenuTitle') %>
$node.MenuTitle
<% else %>
$node.Title
<% end_if %>
<% end_if %>
</span>
</a>
$SubTree
</li>

0 comments on commit 769136f

Please sign in to comment.