Skip to content

Commit

Permalink
FIX Page type blacklist not matching classes correctly (Fixes 297)
Browse files Browse the repository at this point in the history
Tidied up the UI, removed custom javascript in favour of core Toggle field.
  • Loading branch information
wilr committed Sep 11, 2017
1 parent 32385e5 commit 188b02d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 46 deletions.
41 changes: 10 additions & 31 deletions javascript/LeftAndMain_Subsites.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*jslint browser: true, nomen: true*/
/*global $, window, jQuery*/

(function($) {
'use strict';
$.entwine('ss', function($) {
Expand All @@ -13,8 +12,8 @@
}
});

/*
* Reload subsites dropdown when links are processed
/*
* Reload subsites dropdown when links are processed
*/
$('.cms-container .cms-menu-list li a').entwine({
onclick: function(e) {
Expand All @@ -23,8 +22,8 @@
}
});

/*
* Reload subsites dropdown when the admin area reloads (for deleting sites)
/*
* Reload subsites dropdown when the admin area reloads (for deleting sites)
*/
$('.cms-container .SubsiteAdmin .cms-edit-form fieldset.ss-gridfield').entwine({
onreload: function(e) {
Expand All @@ -35,8 +34,8 @@



/*

/*
* Reload subsites dropdown when subsites are added or names are modified
*/
$('.cms-container .cms-content-fields .subsite-model').entwine({
Expand All @@ -45,26 +44,26 @@
this._super(e);
}
});

// Subsite tab of Group editor
$('#Form_ItemEditForm_AccessAllSubsites').entwine({
/**
* Constructor: onmatch
*/
onmatch: function () {
this.showHideSubsiteList();

var ref=this;
$('#Form_ItemEditForm_AccessAllSubsites input').change(function() {
ref.showHideSubsiteList();
});
},

showHideSubsiteList: function () {
$('#Form_ItemEditForm_Subsites').parent().parent().css('display', ($('#Form_ItemEditForm_AccessAllSubsites_1').is(':checked') ? 'none':''));
}
});

$('.cms-edit-form').entwine({
/**
* TODO: Fix with Entwine API extension. See https://github.com/silverstripe/silverstripe-subsites/pull/125
Expand All @@ -89,26 +88,6 @@
return opts;
}
});

/**
* Binding a visibility toggle anchor to a longer list of checkboxes.
* Hidden by default, unless either the toggle checkbox, or any of the
* actual value checkboxes are selected.
*/
$('#PageTypeBlacklist').entwine({
onmatch: function() {
var hasLimits=Boolean($('#PageTypeBlacklist').find('input:checked').length);
jQuery('#PageTypeBlacklist').toggle(hasLimits);


//Bind listener
$('a#PageTypeBlacklistToggle').click(function(e) {
jQuery('#PageTypeBlacklist').toggle();
e.stopPropagation();
return false;
});
}
});

$('.cms-edit-form input[name=action_copytosubsite]').entwine({
onclick: function(e) {
Expand Down
7 changes: 5 additions & 2 deletions src/Extension/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,12 @@ public function canCreate($member = null)
{
// Typically called on a singleton, so we're not using the Subsite() relation
$subsite = Subsite::currentSubsite();

if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
$blacklisted = explode(',', $subsite->PageTypeBlacklist);
// All subclasses need to be listed explicitly
$blacklist = str_replace(['[', '"', ']'], '', $subsite->PageTypeBlacklist);
$blacklist = str_replace(['\\\\'], '\\', $blacklist);
$blacklisted = explode(',', $blacklist);

if (in_array(get_class($this->owner), $blacklisted)) {
return false;
}
Expand Down
21 changes: 8 additions & 13 deletions src/Model/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\i18n\Data\Intl\IntlLocales;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayLib;
Expand All @@ -34,6 +35,7 @@
use SilverStripe\Security\Security;
use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\Versioned\Versioned;

use UnexpectedValueException;

/**
Expand Down Expand Up @@ -697,18 +699,12 @@ public function getCMSFields()
// new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL),
CheckboxField::create('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite),
CheckboxField::create('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic),
LiteralField::create(
ToggleCompositeField::create(
'PageTypeBlacklistToggle',
sprintf(
'<div class="field"><a href="#" id="PageTypeBlacklistToggle">%s</a></div>',
_t(__CLASS__ . '.PageTypeBlacklistField', 'Disallow page types?')
)
),
CheckboxSetField::create(
'PageTypeBlacklist',
false,
$pageTypeMap
)
_t(__CLASS__ . '.PageTypeBlacklistField', 'Disallow page types?'),
[CheckboxSetField::create('PageTypeBlacklist', '', $pageTypeMap)]
)->setHeadingLevel(4)

)
),
HiddenField::create('ID', '', $this->ID),
Expand All @@ -721,8 +717,7 @@ public function getCMSFields()
$fields->addFieldToTab(
'Root.Configuration',
DropdownField::create('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme)
->setEmptyString(_t(__CLASS__ . '.ThemeFieldEmptyString', '-')),
'PageTypeBlacklistToggle'
->setEmptyString(_t(__CLASS__ . '.ThemeFieldEmptyString', '-'))
);
}

Expand Down

0 comments on commit 188b02d

Please sign in to comment.