Skip to content

Commit

Permalink
API Make CMSMain more generic
Browse files Browse the repository at this point in the history
Remove hardcoded references to pages and SiteTree
Remove assumption that records are versioned
Remove or validate assumptions about methods on the model class
Improve general architecture of CMSMain
  • Loading branch information
GuySartorelli committed Oct 21, 2024
1 parent bd48b04 commit 2faf391
Show file tree
Hide file tree
Showing 34 changed files with 888 additions and 920 deletions.
4 changes: 0 additions & 4 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php

use SilverStripe\Admin\CMSMenu;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Controllers\CMSPageAddController;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\CMS\Controllers\CMSPageSettingsController;
use SilverStripe\CMS\Model\SiteTree;
Expand Down Expand Up @@ -32,7 +30,5 @@
[SiteTree::class, 'link_shortcode_handler']
);

CMSMenu::remove_menu_class(CMSMain::class);
CMSMenu::remove_menu_class(CMSPageEditController::class);
CMSMenu::remove_menu_class(CMSPageSettingsController::class);
CMSMenu::remove_menu_class(CMSPageAddController::class);
2 changes: 1 addition & 1 deletion _config/adminpanels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Name: cmsdefaultadmin
---
SilverStripe\Admin\AdminRootController:
default_panel: SilverStripe\CMS\Controllers\CMSPagesController
default_panel: SilverStripe\CMS\Controllers\CMSMain
6 changes: 3 additions & 3 deletions _config/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ After:
- '#corecache'
---
SilverStripe\Core\Injector\Injector:
Psr\SimpleCache\CacheInterface.CMSMain_SiteTreeHints:
Psr\SimpleCache\CacheInterface.CMSMain_TreeHints:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
namespace: "CMSMain_SiteTreeHints"
namespace: "CMSMain_TreeHints"
Psr\SimpleCache\CacheInterface.SiteTree_CreatableChildren:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
namespace: "SiteTree_CreatableChildren"
Psr\SimpleCache\CacheInterface.SiteTree_PageIcons:
factory: SilverStripe\Core\Cache\CacheFactory
constructor:
namespace: "SiteTree_PageIcons"
namespace: "SiteTree_PageIcons"
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions client/src/legacy/CMSMain.AddForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ $.entwine('ss', function($){
* @param {string} defaultChildClass
*/
updateSelectionFilter: function(disallowedChildren, defaultChildClass) {
var currentSelection = this.find('#Form_AddForm_PageType div.radio.selected')[0];
var currentSelection = this.find('#Form_AddForm_RecordType div.radio.selected')[0];
var keepSelection = false;

// Limit selection
var allAllowed = null; // troolian
this.find('#Form_AddForm_PageType div.radio').each(function (i, el) {
this.find('#Form_AddForm_RecordType div.radio').each(function (i, el) {
var className = $(this).find('input').val(),
isAllowed = ($.inArray(className, disallowedChildren) === -1);

// Avoid changing the selected pagetype if still allowed
// Avoid changing the selected record type if still allowed
if (el === currentSelection && isAllowed) {
keepSelection = true;
}
Expand All @@ -153,16 +153,16 @@ $.entwine('ss', function($){
var selectedEl = $(currentSelection).parents('li:first');
} else if (defaultChildClass) {
var selectedEl = this
.find('#Form_AddForm_PageType div.radio input[value=' + defaultChildClass + ']')
.find('#Form_AddForm_RecordType div.radio input[value=' + defaultChildClass + ']')
.parents('li:first');
} else {
var selectedEl = this.find('#Form_AddForm_PageType div.radio:not(.disabled):first');
var selectedEl = this.find('#Form_AddForm_RecordType div.radio:not(.disabled):first');
}
selectedEl.setSelected(true);
selectedEl.siblings().setSelected(false);

// Disable the "Create" button if none of the pagetypes are available
if(this.find('#Form_AddForm_PageType div.radio:not(.disabled)').length) {
// Disable the "Create" button if none of the record types are available
if(this.find('#Form_AddForm_RecordType div.radio:not(.disabled)').length) {
this.find('button[name=action_doAdd]').removeAttr('disabled');
} else {
this.find('button[name=action_doAdd]').attr('disabled', 'disabled');
Expand All @@ -172,7 +172,7 @@ $.entwine('ss', function($){
}
});

$(".cms-add-form #Form_AddForm_PageType div.radio").entwine({
$(".cms-add-form #Form_AddForm_RecordType div.radio").entwine({
onclick: function(e) {
this.setSelected(true);
},
Expand Down
Loading

0 comments on commit 2faf391

Please sign in to comment.