Skip to content

Commit

Permalink
Merge pull request #35 from nyeholt/master
Browse files Browse the repository at this point in the history
NEW Allow a blockset to be bound to parent node
  • Loading branch information
sheadawson committed Sep 17, 2015
2 parents 8e24fd0 + aea471f commit 8235f36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion code/dataobjects/BlockSet.php
Expand Up @@ -11,7 +11,8 @@ class BlockSet extends DataObject implements PermissionProvider{
**/
private static $db = array(
'Title' => 'Varchar(255)',
'PageTypes' => 'MultiValueField'
'PageTypes' => 'MultiValueField',
'IncludePageParent' => 'Boolean',
);

/**
Expand Down Expand Up @@ -51,6 +52,7 @@ public function getCMSFields(){
$fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', 'Only apply to these Page Types:', $this->pageTypeOptions())
->setDescription('Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.'));
$fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', 'Only apply to children of these Pages:', 'SiteTree'));
$fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', 'Apply block set to selected page parents as well as children'));

if(!$this->ID){
$fields->addFieldToTab('Root.Main', LiteralField::create('NotSaved', "<p class='message warning'>You can add Blocks to this set once you have saved it for the first time</p>"));
Expand Down
19 changes: 14 additions & 5 deletions code/extensions/BlocksSiteTreeExtension.php
Expand Up @@ -195,11 +195,20 @@ public function getAppliedSets() {

foreach ($sets as $set) {
$restrictedToParerentIDs = $set->PageParents()->column('ID');
if (count($restrictedToParerentIDs) && count($ancestors)) {
foreach ($ancestors as $ancestor) {
if (in_array($ancestor, $restrictedToParerentIDs)) {
$list->add($set);
continue;
if (count($restrictedToParerentIDs)) {
// check whether the set should include selected parent, in which case check whether
// it was in the restricted parents list. If it's not, or if include parentpage
// wasn't selected, we check the ancestors of this page.
if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) {
$list->add($set);
} else {
if (count($ancestors)) {
foreach ($ancestors as $ancestor) {
if (in_array($ancestor, $restrictedToParerentIDs)) {
$list->add($set);
continue;
}
}
}
}
} else {
Expand Down

0 comments on commit 8235f36

Please sign in to comment.