@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | public function VisibleTo() { |
| 42 | 42 | if (strlen(trim($this->MemberVisibility)) > 0) { |
| 43 | 43 | $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility); |
| 44 | - }else{ |
|
| 44 | + } else{ |
|
| 45 | 45 | $lists = '<em><All></em>'; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | if ($this->showBlockbyClass) { |
| 57 | 57 | if (strlen(trim($this->shownInClass)) > 0) { |
| 58 | 58 | $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass); |
| 59 | - }else{ |
|
| 59 | + } else{ |
|
| 60 | 60 | $lists = '<em><not assigned></em>'; |
| 61 | 61 | } |
| 62 | - }else{ |
|
| 62 | + } else{ |
|
| 63 | 63 | if ($this->Pages()->count() > 0) { |
| 64 | 64 | $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title')); |
| 65 | - }else{ |
|
| 65 | + } else{ |
|
| 66 | 66 | $lists = '<em><not assigned></em>'; |
| 67 | 67 | } |
| 68 | 68 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Block extends DataObject { |
| 3 | - private static $db = array ( |
|
| 3 | + private static $db = array( |
|
| 4 | 4 | 'SortOrder' => 'Int', |
| 5 | 5 | 'Title' => 'Varchar(64)', |
| 6 | 6 | 'TitleWrapper' => 'Enum("h2,h3,h4,h5,h6")', |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | 'addPaddingBottom' => 'Boolean' |
| 16 | 16 | ); |
| 17 | 17 | |
| 18 | - private static $many_many = array ( |
|
| 18 | + private static $many_many = array( |
|
| 19 | 19 | 'Pages' => 'Page' |
| 20 | 20 | ); |
| 21 | 21 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | 'MySQLDatabase' => 'ENGINE=MyISAM' |
| 29 | 29 | ); |
| 30 | 30 | |
| 31 | - private static $extensions = array ( |
|
| 31 | + private static $extensions = array( |
|
| 32 | 32 | 'StandardPermissions' |
| 33 | 33 | ); |
| 34 | 34 | |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | public function VisibleTo() { |
| 51 | 51 | if (strlen(trim($this->MemberVisibility)) > 0) { |
| 52 | - $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility); |
|
| 53 | - }else{ |
|
| 52 | + $lists = 'Group: '.str_replace(',', '<br />Group: ', $this->MemberVisibility); |
|
| 53 | + } else { |
|
| 54 | 54 | $lists = '<em><All></em>'; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - return new LiteralField('VisibleTo',$lists); |
|
| 57 | + return new LiteralField('VisibleTo', $lists); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | public function BlockType() { |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | public function shownOn() { |
| 65 | 65 | if ($this->showBlockbyClass) { |
| 66 | 66 | if (strlen(trim($this->shownInClass)) > 0) { |
| 67 | - $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass); |
|
| 68 | - }else{ |
|
| 67 | + $lists = 'Type: '.str_replace(',', '<br />Type: ', $this->shownInClass); |
|
| 68 | + } else { |
|
| 69 | 69 | $lists = '<em><not assigned></em>'; |
| 70 | 70 | } |
| 71 | - }else{ |
|
| 71 | + } else { |
|
| 72 | 72 | if ($this->Pages()->count() > 0) { |
| 73 | - $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title')); |
|
| 74 | - }else{ |
|
| 73 | + $lists = 'Page: '.implode('<br />Page: ', $this->Pages()->column('Title')); |
|
| 74 | + } else { |
|
| 75 | 75 | $lists = '<em><not assigned></em>'; |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | - return new LiteralField('shownOn',$lists); |
|
| 78 | + return new LiteralField('shownOn', $lists); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | public function getCMSFields() { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 'MemberVisibility' |
| 89 | 89 | )); |
| 90 | 90 | |
| 91 | - $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title'); |
|
| 91 | + $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: '.$this->Published()), 'Title'); |
|
| 92 | 92 | |
| 93 | 93 | $memberGroups = Group::get(); |
| 94 | 94 | $sourcemap = $memberGroups->map('Code', 'Title'); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $pageSelector = new CheckboxSetField( |
| 132 | 132 | $name = "Pages", |
| 133 | 133 | $title = "Show on Page(s)", |
| 134 | - $availablePages->map('ID','Title') |
|
| 134 | + $availablePages->map('ID', 'Title') |
|
| 135 | 135 | ); |
| 136 | 136 | |
| 137 | 137 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | public function onAfterWrite() { |
| 175 | 175 | parent::onAfterWrite(); |
| 176 | 176 | if (isset($this->readmode)) { |
| 177 | - Versioned::set_reading_mode('Stage.' . $this->readmode); |
|
| 177 | + Versioned::set_reading_mode('Stage.'.$this->readmode); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /*if ($this->isPublished()) { |
@@ -1,185 +1,185 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class Block extends DataObject { |
| 3 | - private static $db = array ( |
|
| 4 | - 'SortOrder' => 'Int', |
|
| 5 | - 'Title' => 'Varchar(64)', |
|
| 6 | - 'TitleWrapper' => 'Enum("h2,h3,h4,h5,h6")', |
|
| 7 | - 'hideTitle' => 'Boolean', |
|
| 8 | - 'showBlockbyClass' => 'Boolean', |
|
| 9 | - 'Description' => 'Varchar(128)', |
|
| 10 | - 'MemberVisibility' => 'Varchar(255)', |
|
| 11 | - 'shownInClass' => 'Text', |
|
| 12 | - 'addMarginTop' => 'Boolean', |
|
| 13 | - 'addMarginBottom' => 'Boolean', |
|
| 14 | - 'addPaddingTop' => 'Boolean', |
|
| 15 | - 'addPaddingBottom' => 'Boolean' |
|
| 16 | - ); |
|
| 17 | - |
|
| 18 | - private static $many_many = array ( |
|
| 19 | - 'Pages' => 'Page' |
|
| 20 | - ); |
|
| 21 | - |
|
| 22 | - private static $default_sort = array( |
|
| 23 | - 'SortOrder' => 'ASC', |
|
| 24 | - 'ID' => 'DESC' |
|
| 25 | - ); |
|
| 26 | - |
|
| 27 | - private static $create_table_options = array( |
|
| 28 | - 'MySQLDatabase' => 'ENGINE=MyISAM' |
|
| 3 | + private static $db = array ( |
|
| 4 | + 'SortOrder' => 'Int', |
|
| 5 | + 'Title' => 'Varchar(64)', |
|
| 6 | + 'TitleWrapper' => 'Enum("h2,h3,h4,h5,h6")', |
|
| 7 | + 'hideTitle' => 'Boolean', |
|
| 8 | + 'showBlockbyClass' => 'Boolean', |
|
| 9 | + 'Description' => 'Varchar(128)', |
|
| 10 | + 'MemberVisibility' => 'Varchar(255)', |
|
| 11 | + 'shownInClass' => 'Text', |
|
| 12 | + 'addMarginTop' => 'Boolean', |
|
| 13 | + 'addMarginBottom' => 'Boolean', |
|
| 14 | + 'addPaddingTop' => 'Boolean', |
|
| 15 | + 'addPaddingBottom' => 'Boolean' |
|
| 29 | 16 | ); |
| 30 | 17 | |
| 31 | - private static $extensions = array ( |
|
| 32 | - 'StandardPermissions' |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - private static $summary_fields = array( |
|
| 36 | - 'BlockType', |
|
| 37 | - 'Title', |
|
| 38 | - 'Description', |
|
| 39 | - 'shownOn', |
|
| 40 | - 'VisibleTo', |
|
| 41 | - 'Published' |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - private static $field_labels = array( |
|
| 45 | - 'BlockType' => 'Block type', |
|
| 46 | - 'shownOn' => 'is shown on', |
|
| 47 | - 'VisibleTo' => 'Visible to' |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - public function VisibleTo() { |
|
| 51 | - if (strlen(trim($this->MemberVisibility)) > 0) { |
|
| 52 | - $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility); |
|
| 53 | - }else{ |
|
| 54 | - $lists = '<em><All></em>'; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - return new LiteralField('VisibleTo',$lists); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function BlockType() { |
|
| 61 | - return $this->singular_name(); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - public function shownOn() { |
|
| 65 | - if ($this->showBlockbyClass) { |
|
| 66 | - if (strlen(trim($this->shownInClass)) > 0) { |
|
| 67 | - $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass); |
|
| 68 | - }else{ |
|
| 69 | - $lists = '<em><not assigned></em>'; |
|
| 70 | - } |
|
| 71 | - }else{ |
|
| 72 | - if ($this->Pages()->count() > 0) { |
|
| 73 | - $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title')); |
|
| 74 | - }else{ |
|
| 75 | - $lists = '<em><not assigned></em>'; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - return new LiteralField('shownOn',$lists); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function getCMSFields() { |
|
| 82 | - $fields = parent::getCMSFields(); |
|
| 83 | - $fields->removeFieldFromTab('Root', 'Pages'); |
|
| 84 | - $fields->removeFieldsFromTab('Root.Main', array( |
|
| 85 | - 'SortOrder', |
|
| 86 | - 'showBlockbyClass', |
|
| 87 | - 'shownInClass', |
|
| 88 | - 'MemberVisibility' |
|
| 89 | - )); |
|
| 90 | - |
|
| 91 | - $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title'); |
|
| 92 | - |
|
| 93 | - $memberGroups = Group::get(); |
|
| 94 | - $sourcemap = $memberGroups->map('Code', 'Title'); |
|
| 95 | - $source = array( |
|
| 96 | - 'anonymous' => 'Anonymous visitors' |
|
| 97 | - ); |
|
| 98 | - foreach ($sourcemap as $mapping => $key) { |
|
| 99 | - $source[$mapping] = $key; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $memberVisibility = new CheckboxSetField( |
|
| 103 | - $name = "MemberVisibility", |
|
| 104 | - $title = "Show block for specific groups", |
|
| 105 | - $source |
|
| 106 | - ); |
|
| 107 | - |
|
| 108 | - $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); |
|
| 109 | - |
|
| 110 | - $availabelClasses = $this->availableClasses(); |
|
| 111 | - $inClass = new CheckboxSetField( |
|
| 112 | - $name = "shownInClass", |
|
| 113 | - $title = "Show block for specific content types", |
|
| 114 | - $availabelClasses |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - $filterSelector = OptionsetField::create( |
|
| 118 | - 'showBlockbyClass', |
|
| 119 | - 'Choose filter set', |
|
| 120 | - array( |
|
| 121 | - '0' => 'by page', |
|
| 122 | - '1' => 'by page/data type' |
|
| 123 | - ) |
|
| 124 | - )->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>'); |
|
| 125 | - |
|
| 126 | - $availablePages = Page::get()->exclude('ClassName', array( |
|
| 127 | - 'ErrorPage', |
|
| 128 | - 'RedirectorPage', |
|
| 129 | - 'VirtualPage' |
|
| 130 | - )); |
|
| 131 | - $pageSelector = new CheckboxSetField( |
|
| 132 | - $name = "Pages", |
|
| 133 | - $title = "Show on Page(s)", |
|
| 134 | - $availablePages->map('ID','Title') |
|
| 135 | - ); |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - if ($this->canConfigPageAndType(Member::currentUser())) { |
|
| 139 | - $fields->addFieldsToTab('Root.VisibilitySettings', array( |
|
| 140 | - $filterSelector, |
|
| 141 | - $pageSelector, |
|
| 142 | - $inClass |
|
| 143 | - )); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if ($this->canConfigMemberVisibility(Member::currentUser())) { |
|
| 147 | - $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - if (!$fields->fieldByName('Options')) { |
|
| 151 | - $fields->insertBefore($right = RightSidebar::create('Options'), 'Root'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $fields->addFieldsToTab('Options', array( |
|
| 155 | - CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'), |
|
| 156 | - CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper'), |
|
| 157 | - CheckboxField::create('addPaddingTop', 'add "padding-top" class to block wrapper'), |
|
| 158 | - CheckboxField::create('addPaddingBottom', 'add "padding-bottom" class to block wrapper') |
|
| 159 | - )); |
|
| 160 | - |
|
| 161 | - return $fields; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - public function doPublish() { |
|
| 165 | - $this->writeToStage('Live'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - public function onBeforeWrite() { |
|
| 169 | - parent::onBeforeWrite(); |
|
| 170 | - if (empty($this->byPass)) { |
|
| 171 | - $this->readmode = Versioned::get_reading_mode(); |
|
| 172 | - Versioned::set_reading_mode('Stage.Stage'); |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - public function onAfterWrite() { |
|
| 177 | - parent::onAfterWrite(); |
|
| 178 | - if (isset($this->readmode)) { |
|
| 179 | - Versioned::set_reading_mode('Stage.' . $this->readmode); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /*if ($this->isPublished()) { |
|
| 18 | + private static $many_many = array ( |
|
| 19 | + 'Pages' => 'Page' |
|
| 20 | + ); |
|
| 21 | + |
|
| 22 | + private static $default_sort = array( |
|
| 23 | + 'SortOrder' => 'ASC', |
|
| 24 | + 'ID' => 'DESC' |
|
| 25 | + ); |
|
| 26 | + |
|
| 27 | + private static $create_table_options = array( |
|
| 28 | + 'MySQLDatabase' => 'ENGINE=MyISAM' |
|
| 29 | + ); |
|
| 30 | + |
|
| 31 | + private static $extensions = array ( |
|
| 32 | + 'StandardPermissions' |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + private static $summary_fields = array( |
|
| 36 | + 'BlockType', |
|
| 37 | + 'Title', |
|
| 38 | + 'Description', |
|
| 39 | + 'shownOn', |
|
| 40 | + 'VisibleTo', |
|
| 41 | + 'Published' |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + private static $field_labels = array( |
|
| 45 | + 'BlockType' => 'Block type', |
|
| 46 | + 'shownOn' => 'is shown on', |
|
| 47 | + 'VisibleTo' => 'Visible to' |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + public function VisibleTo() { |
|
| 51 | + if (strlen(trim($this->MemberVisibility)) > 0) { |
|
| 52 | + $lists = 'Group: ' . str_replace(',','<br />Group: ', $this->MemberVisibility); |
|
| 53 | + }else{ |
|
| 54 | + $lists = '<em><All></em>'; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + return new LiteralField('VisibleTo',$lists); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function BlockType() { |
|
| 61 | + return $this->singular_name(); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + public function shownOn() { |
|
| 65 | + if ($this->showBlockbyClass) { |
|
| 66 | + if (strlen(trim($this->shownInClass)) > 0) { |
|
| 67 | + $lists = 'Type: ' . str_replace(',','<br />Type: ', $this->shownInClass); |
|
| 68 | + }else{ |
|
| 69 | + $lists = '<em><not assigned></em>'; |
|
| 70 | + } |
|
| 71 | + }else{ |
|
| 72 | + if ($this->Pages()->count() > 0) { |
|
| 73 | + $lists = 'Page: ' . implode('<br />Page: ', $this->Pages()->column('Title')); |
|
| 74 | + }else{ |
|
| 75 | + $lists = '<em><not assigned></em>'; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + return new LiteralField('shownOn',$lists); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function getCMSFields() { |
|
| 82 | + $fields = parent::getCMSFields(); |
|
| 83 | + $fields->removeFieldFromTab('Root', 'Pages'); |
|
| 84 | + $fields->removeFieldsFromTab('Root.Main', array( |
|
| 85 | + 'SortOrder', |
|
| 86 | + 'showBlockbyClass', |
|
| 87 | + 'shownInClass', |
|
| 88 | + 'MemberVisibility' |
|
| 89 | + )); |
|
| 90 | + |
|
| 91 | + $fields->addFieldToTab('Root.Main', LiteralField::create('Status', 'Published: ' . $this->Published()), 'Title'); |
|
| 92 | + |
|
| 93 | + $memberGroups = Group::get(); |
|
| 94 | + $sourcemap = $memberGroups->map('Code', 'Title'); |
|
| 95 | + $source = array( |
|
| 96 | + 'anonymous' => 'Anonymous visitors' |
|
| 97 | + ); |
|
| 98 | + foreach ($sourcemap as $mapping => $key) { |
|
| 99 | + $source[$mapping] = $key; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $memberVisibility = new CheckboxSetField( |
|
| 103 | + $name = "MemberVisibility", |
|
| 104 | + $title = "Show block for specific groups", |
|
| 105 | + $source |
|
| 106 | + ); |
|
| 107 | + |
|
| 108 | + $memberVisibility->setDescription('Show this block only for the selected group(s). If you select no groups, the block will be visible to all members.'); |
|
| 109 | + |
|
| 110 | + $availabelClasses = $this->availableClasses(); |
|
| 111 | + $inClass = new CheckboxSetField( |
|
| 112 | + $name = "shownInClass", |
|
| 113 | + $title = "Show block for specific content types", |
|
| 114 | + $availabelClasses |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + $filterSelector = OptionsetField::create( |
|
| 118 | + 'showBlockbyClass', |
|
| 119 | + 'Choose filter set', |
|
| 120 | + array( |
|
| 121 | + '0' => 'by page', |
|
| 122 | + '1' => 'by page/data type' |
|
| 123 | + ) |
|
| 124 | + )->setDescription('<p><br /><strong>by page</strong>: block will be displayed in the selected page(s)<br /><strong>by page/data type</strong>: block will be displayed on the pages created with the particular page/data type. e.g. is <strong>"InternalPage"</strong> is picked, the block will be displayed, and will ONLY be displayed on all <strong>Internal Pages</strong></p>'); |
|
| 125 | + |
|
| 126 | + $availablePages = Page::get()->exclude('ClassName', array( |
|
| 127 | + 'ErrorPage', |
|
| 128 | + 'RedirectorPage', |
|
| 129 | + 'VirtualPage' |
|
| 130 | + )); |
|
| 131 | + $pageSelector = new CheckboxSetField( |
|
| 132 | + $name = "Pages", |
|
| 133 | + $title = "Show on Page(s)", |
|
| 134 | + $availablePages->map('ID','Title') |
|
| 135 | + ); |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + if ($this->canConfigPageAndType(Member::currentUser())) { |
|
| 139 | + $fields->addFieldsToTab('Root.VisibilitySettings', array( |
|
| 140 | + $filterSelector, |
|
| 141 | + $pageSelector, |
|
| 142 | + $inClass |
|
| 143 | + )); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if ($this->canConfigMemberVisibility(Member::currentUser())) { |
|
| 147 | + $fields->addFieldToTab('Root.VisibilitySettings', $memberVisibility); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + if (!$fields->fieldByName('Options')) { |
|
| 151 | + $fields->insertBefore($right = RightSidebar::create('Options'), 'Root'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $fields->addFieldsToTab('Options', array( |
|
| 155 | + CheckboxField::create('addMarginTop', 'add "margin-top" class to block wrapper'), |
|
| 156 | + CheckboxField::create('addMarginBottom', 'add "margin-bottom" class to block wrapper'), |
|
| 157 | + CheckboxField::create('addPaddingTop', 'add "padding-top" class to block wrapper'), |
|
| 158 | + CheckboxField::create('addPaddingBottom', 'add "padding-bottom" class to block wrapper') |
|
| 159 | + )); |
|
| 160 | + |
|
| 161 | + return $fields; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + public function doPublish() { |
|
| 165 | + $this->writeToStage('Live'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + public function onBeforeWrite() { |
|
| 169 | + parent::onBeforeWrite(); |
|
| 170 | + if (empty($this->byPass)) { |
|
| 171 | + $this->readmode = Versioned::get_reading_mode(); |
|
| 172 | + Versioned::set_reading_mode('Stage.Stage'); |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + public function onAfterWrite() { |
|
| 177 | + parent::onAfterWrite(); |
|
| 178 | + if (isset($this->readmode)) { |
|
| 179 | + Versioned::set_reading_mode('Stage.' . $this->readmode); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /*if ($this->isPublished()) { |
|
| 183 | 183 | $live = Versioned::get_by_stage('Block', 'Live')->byID($this->ID); |
| 184 | 184 | $stage = Versioned::get_by_stage('Block', 'Stage')->byID($this->ID); |
| 185 | 185 | if ($live->SortOrder != $stage->SortOrder) { |
@@ -188,74 +188,74 @@ discard block |
||
| 188 | 188 | $this->doPublish(); |
| 189 | 189 | } |
| 190 | 190 | }*/ |
| 191 | - } |
|
| 192 | - |
|
| 193 | - public function availableClasses() { |
|
| 194 | - $Classes = array_diff( |
|
| 195 | - ClassInfo::subclassesFor('Page'), |
|
| 196 | - ClassInfo::subclassesFor('RedirectorPage'), |
|
| 197 | - ClassInfo::subclassesFor('VirtualPage') |
|
| 198 | - ); |
|
| 199 | - return $Classes; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - public function forTemplate() { |
|
| 203 | - if ($this->canDisplayMemberCheck()) { |
|
| 204 | - return $this->renderWith(array($this->getClassName(), 'BaseBlock')); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - public function canDisplayMemberCheck() { |
|
| 211 | - $rawVisibility = $this->MemberVisibility; |
|
| 212 | - |
|
| 213 | - if (empty($rawVisibility)) { |
|
| 214 | - return true; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $visibility = explode(',', $rawVisibility); |
|
| 218 | - $member = Member::currentUser(); |
|
| 219 | - |
|
| 220 | - if (!$member && in_array('anonymous', $visibility)) { |
|
| 221 | - return true; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - if ($member) { |
|
| 225 | - $memberGroups = $member->Groups()->column('Code'); |
|
| 226 | - foreach ($memberGroups as $memberGroup) { |
|
| 227 | - if (in_array($memberGroup, $visibility)) { |
|
| 228 | - return true; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return false; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - public function frontendEditable() { |
|
| 237 | - $member = Member::currentUser(); |
|
| 238 | - return $this->canEdit($member) && Config::inst()->get('Block', 'FrontendEditable'); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - public function Type2Class() { |
|
| 242 | - return strtolower(str_replace(' ', '-', $this->singular_name())); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /*public function doPublish() { |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + public function availableClasses() { |
|
| 194 | + $Classes = array_diff( |
|
| 195 | + ClassInfo::subclassesFor('Page'), |
|
| 196 | + ClassInfo::subclassesFor('RedirectorPage'), |
|
| 197 | + ClassInfo::subclassesFor('VirtualPage') |
|
| 198 | + ); |
|
| 199 | + return $Classes; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + public function forTemplate() { |
|
| 203 | + if ($this->canDisplayMemberCheck()) { |
|
| 204 | + return $this->renderWith(array($this->getClassName(), 'BaseBlock')); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + public function canDisplayMemberCheck() { |
|
| 211 | + $rawVisibility = $this->MemberVisibility; |
|
| 212 | + |
|
| 213 | + if (empty($rawVisibility)) { |
|
| 214 | + return true; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $visibility = explode(',', $rawVisibility); |
|
| 218 | + $member = Member::currentUser(); |
|
| 219 | + |
|
| 220 | + if (!$member && in_array('anonymous', $visibility)) { |
|
| 221 | + return true; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + if ($member) { |
|
| 225 | + $memberGroups = $member->Groups()->column('Code'); |
|
| 226 | + foreach ($memberGroups as $memberGroup) { |
|
| 227 | + if (in_array($memberGroup, $visibility)) { |
|
| 228 | + return true; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return false; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + public function frontendEditable() { |
|
| 237 | + $member = Member::currentUser(); |
|
| 238 | + return $this->canEdit($member) && Config::inst()->get('Block', 'FrontendEditable'); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + public function Type2Class() { |
|
| 242 | + return strtolower(str_replace(' ', '-', $this->singular_name())); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /*public function doPublish() { |
|
| 246 | 246 | $this->writeToStage('Live'); |
| 247 | 247 | }*/ |
| 248 | 248 | |
| 249 | - public function Published() { |
|
| 250 | - return $this->isPublished() ? 'Yes' : 'No'; |
|
| 251 | - } |
|
| 249 | + public function Published() { |
|
| 250 | + return $this->isPublished() ? 'Yes' : 'No'; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - public function isPublished() { |
|
| 254 | - if (!empty(Versioned::get_by_stage('Block', 'Live')->byID($this->ID))) { |
|
| 255 | - return true; |
|
| 256 | - } |
|
| 253 | + public function isPublished() { |
|
| 254 | + if (!empty(Versioned::get_by_stage('Block', 'Live')->byID($this->ID))) { |
|
| 255 | + return true; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return false; |
|
| 259 | - } |
|
| 258 | + return false; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | 261 | } |
@@ -1,37 +1,37 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class CustomBlockPermission extends DataExtension implements PermissionProvider { |
| 4 | - public function canConfigPageAndType($member = false) { |
|
| 5 | - return Permission::check(get_class($this->owner) . '_config_page_and_type'); |
|
| 6 | - } |
|
| 4 | + public function canConfigPageAndType($member = false) { |
|
| 5 | + return Permission::check(get_class($this->owner) . '_config_page_and_type'); |
|
| 6 | + } |
|
| 7 | 7 | |
| 8 | - public function canConfigMemberVisibility($member = false) { |
|
| 9 | - return Permission::check(get_class($this->owner) . '_config_member_visibility'); |
|
| 10 | - } |
|
| 8 | + public function canConfigMemberVisibility($member = false) { |
|
| 9 | + return Permission::check(get_class($this->owner) . '_config_member_visibility'); |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function providePermissions() { |
|
| 13 | - $permissions = array(); |
|
| 14 | - foreach ($this->getClassList() as $class) { |
|
| 15 | - foreach (array( |
|
| 16 | - 'config_page_and_type', |
|
| 17 | - 'config_member_visibility' |
|
| 18 | - ) as $name) { |
|
| 19 | - $permissions[$class . '_' . $name] = $class . '_' . $name; |
|
| 20 | - } |
|
| 21 | - } |
|
| 22 | - return $permissions; |
|
| 23 | - } |
|
| 12 | + public function providePermissions() { |
|
| 13 | + $permissions = array(); |
|
| 14 | + foreach ($this->getClassList() as $class) { |
|
| 15 | + foreach (array( |
|
| 16 | + 'config_page_and_type', |
|
| 17 | + 'config_member_visibility' |
|
| 18 | + ) as $name) { |
|
| 19 | + $permissions[$class . '_' . $name] = $class . '_' . $name; |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | + return $permissions; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - private function getClassList() { |
|
| 26 | - $classes = array(); |
|
| 27 | - foreach (ClassInfo::subclassesFor('DataObject') as $class => $file) { |
|
| 28 | - $extensions = Config::inst()->get($class, 'extensions'); |
|
| 29 | - if (!is_null($extensions)) { |
|
| 30 | - if (in_array(get_class($this), $extensions)) { |
|
| 31 | - $classes[] = $class; |
|
| 32 | - } |
|
| 33 | - } |
|
| 34 | - } |
|
| 35 | - return $classes; |
|
| 36 | - } |
|
| 25 | + private function getClassList() { |
|
| 26 | + $classes = array(); |
|
| 27 | + foreach (ClassInfo::subclassesFor('DataObject') as $class => $file) { |
|
| 28 | + $extensions = Config::inst()->get($class, 'extensions'); |
|
| 29 | + if (!is_null($extensions)) { |
|
| 30 | + if (in_array(get_class($this), $extensions)) { |
|
| 31 | + $classes[] = $class; |
|
| 32 | + } |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | + return $classes; |
|
| 36 | + } |
|
| 37 | 37 | } |
| 38 | 38 | \ No newline at end of file |
@@ -2,11 +2,11 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class CustomBlockPermission extends DataExtension implements PermissionProvider { |
| 4 | 4 | public function canConfigPageAndType($member = false) { |
| 5 | - return Permission::check(get_class($this->owner) . '_config_page_and_type'); |
|
| 5 | + return Permission::check(get_class($this->owner).'_config_page_and_type'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | public function canConfigMemberVisibility($member = false) { |
| 9 | - return Permission::check(get_class($this->owner) . '_config_member_visibility'); |
|
| 9 | + return Permission::check(get_class($this->owner).'_config_member_visibility'); |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | public function providePermissions() { |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | 'config_page_and_type', |
| 17 | 17 | 'config_member_visibility' |
| 18 | 18 | ) as $name) { |
| 19 | - $permissions[$class . '_' . $name] = $class . '_' . $name; |
|
| 19 | + $permissions[$class.'_'.$name] = $class.'_'.$name; |
|
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | return $permissions; |
@@ -1,46 +1,46 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class MultiClassSelector extends GridFieldAddNewMultiClass { |
| 4 | - private static $allowed_actions = array( |
|
| 5 | - 'handleAdd' |
|
| 6 | - ); |
|
| 4 | + private static $allowed_actions = array( |
|
| 5 | + 'handleAdd' |
|
| 6 | + ); |
|
| 7 | 7 | |
| 8 | - // Should we add an empty string to the add class dropdown? |
|
| 9 | - private static $showEmptyString = true; |
|
| 8 | + // Should we add an empty string to the add class dropdown? |
|
| 9 | + private static $showEmptyString = true; |
|
| 10 | 10 | |
| 11 | - private $fragment; |
|
| 11 | + private $fragment; |
|
| 12 | 12 | |
| 13 | - private $title; |
|
| 13 | + private $title; |
|
| 14 | 14 | |
| 15 | - private $classes; |
|
| 15 | + private $classes; |
|
| 16 | 16 | |
| 17 | - private $defaultClass; |
|
| 17 | + private $defaultClass; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - public function getHTMLFragments($grid) { |
|
| 21 | - $classes = $this->getClasses($grid); |
|
| 20 | + public function getHTMLFragments($grid) { |
|
| 21 | + $classes = $this->getClasses($grid); |
|
| 22 | 22 | |
| 23 | - if(!count($classes)) { |
|
| 24 | - return array(); |
|
| 25 | - } |
|
| 23 | + if(!count($classes)) { |
|
| 24 | + return array(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - GridFieldExtensions::include_requirements(); |
|
| 27 | + GridFieldExtensions::include_requirements(); |
|
| 28 | 28 | |
| 29 | - $field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes, $this->defaultClass); |
|
| 30 | - $field->setAttribute('id', uniqid()); |
|
| 31 | - if (Config::inst()->get('GridFieldAddNewMultiClass', 'showEmptyString')) { |
|
| 32 | - $field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)')); |
|
| 33 | - } |
|
| 34 | - $field->addExtraClass('no-change-track'); |
|
| 29 | + $field = new DropdownField(sprintf('%s[ClassName]', __CLASS__), '', $classes, $this->defaultClass); |
|
| 30 | + $field->setAttribute('id', uniqid()); |
|
| 31 | + if (Config::inst()->get('GridFieldAddNewMultiClass', 'showEmptyString')) { |
|
| 32 | + $field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)')); |
|
| 33 | + } |
|
| 34 | + $field->addExtraClass('no-change-track'); |
|
| 35 | 35 | |
| 36 | - $data = new ArrayData(array( |
|
| 37 | - 'Title' => $this->getTitle(), |
|
| 38 | - 'Link' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'), |
|
| 39 | - 'ClassField' => $field |
|
| 40 | - )); |
|
| 36 | + $data = new ArrayData(array( |
|
| 37 | + 'Title' => $this->getTitle(), |
|
| 38 | + 'Link' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'), |
|
| 39 | + 'ClassField' => $field |
|
| 40 | + )); |
|
| 41 | 41 | |
| 42 | - return array( |
|
| 43 | - $this->getFragment() => $data->renderWith('GridFieldAddNewMultiClass') |
|
| 44 | - ); |
|
| 45 | - } |
|
| 42 | + return array( |
|
| 43 | + $this->getFragment() => $data->renderWith('GridFieldAddNewMultiClass') |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | \ No newline at end of file |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | public function getHTMLFragments($grid) { |
| 21 | 21 | $classes = $this->getClasses($grid); |
| 22 | 22 | |
| 23 | - if(!count($classes)) { |
|
| 23 | + if (!count($classes)) { |
|
| 24 | 24 | return array(); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -1,7 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -use SaltedHerring\Debugger as Debugger; |
|
| 4 | - |
|
| 5 | 3 | class VersionedForm extends GridFieldDetailForm { |
| 6 | 4 | |
| 7 | 5 | } |
@@ -7,47 +7,47 @@ |
||
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | class VersionedForm_ItemRequest extends GridFieldDetailForm_ItemRequest { |
| 10 | - private static $allowed_actions = array( |
|
| 11 | - 'edit', |
|
| 12 | - 'view', |
|
| 13 | - 'ItemEditForm', |
|
| 14 | - 'doPublish', |
|
| 15 | - 'doUnpublish' |
|
| 16 | - ); |
|
| 10 | + private static $allowed_actions = array( |
|
| 11 | + 'edit', |
|
| 12 | + 'view', |
|
| 13 | + 'ItemEditForm', |
|
| 14 | + 'doPublish', |
|
| 15 | + 'doUnpublish' |
|
| 16 | + ); |
|
| 17 | 17 | |
| 18 | - public function ItemEditForm() { |
|
| 19 | - $form = parent::ItemEditForm(); |
|
| 20 | - if ($form instanceof Form) { |
|
| 21 | - $actions = $form->Actions(); |
|
| 22 | - $record = $this->record; |
|
| 23 | - $actions->insertBefore('action_doDelete', $btnPublish = FormAction::create('doPublish','Save & Publish')); |
|
| 24 | - $btnPublish->addExtraClass('ss-ui-action-constructive'); |
|
| 25 | - if (!empty($record->ID)) { |
|
| 26 | - if ($record->isPublished()) { |
|
| 27 | - $actions->removeByName('action_doDelete'); |
|
| 28 | - $actions->push(FormAction::create('doUnpublish', 'Unpublish')->addExtraClass('ss-ui-action-destructive')); |
|
| 29 | - } |
|
| 30 | - } |
|
| 18 | + public function ItemEditForm() { |
|
| 19 | + $form = parent::ItemEditForm(); |
|
| 20 | + if ($form instanceof Form) { |
|
| 21 | + $actions = $form->Actions(); |
|
| 22 | + $record = $this->record; |
|
| 23 | + $actions->insertBefore('action_doDelete', $btnPublish = FormAction::create('doPublish','Save & Publish')); |
|
| 24 | + $btnPublish->addExtraClass('ss-ui-action-constructive'); |
|
| 25 | + if (!empty($record->ID)) { |
|
| 26 | + if ($record->isPublished()) { |
|
| 27 | + $actions->removeByName('action_doDelete'); |
|
| 28 | + $actions->push(FormAction::create('doUnpublish', 'Unpublish')->addExtraClass('ss-ui-action-destructive')); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $form->setActions($actions); |
|
| 33 | - } |
|
| 34 | - return $form; |
|
| 35 | - } |
|
| 32 | + $form->setActions($actions); |
|
| 33 | + } |
|
| 34 | + return $form; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function doUnpublish($data, $form) { |
|
| 38 | - $this->record->deleteFromStage('Live'); |
|
| 39 | - $controller = Controller::curr(); |
|
| 40 | - $form->sessionMessage('Block unpublished', 'good', false); |
|
| 41 | - return $this->edit($controller->getRequest()); |
|
| 42 | - } |
|
| 37 | + public function doUnpublish($data, $form) { |
|
| 38 | + $this->record->deleteFromStage('Live'); |
|
| 39 | + $controller = Controller::curr(); |
|
| 40 | + $form->sessionMessage('Block unpublished', 'good', false); |
|
| 41 | + return $this->edit($controller->getRequest()); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function doPublish($data, $form) { |
|
| 45 | - $form->saveInto($this->record); |
|
| 46 | - $this->record->write(); |
|
| 47 | - $this->record->byPass = true; |
|
| 48 | - $this->record->doPublish(); |
|
| 49 | - $form->sessionMessage('Block published', 'good', false); |
|
| 50 | - $controller = Controller::curr(); |
|
| 51 | - return $this->edit($controller->getRequest()); |
|
| 52 | - } |
|
| 44 | + public function doPublish($data, $form) { |
|
| 45 | + $form->saveInto($this->record); |
|
| 46 | + $this->record->write(); |
|
| 47 | + $this->record->byPass = true; |
|
| 48 | + $this->record->doPublish(); |
|
| 49 | + $form->sessionMessage('Block published', 'good', false); |
|
| 50 | + $controller = Controller::curr(); |
|
| 51 | + return $this->edit($controller->getRequest()); |
|
| 52 | + } |
|
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | if ($form instanceof Form) { |
| 21 | 21 | $actions = $form->Actions(); |
| 22 | 22 | $record = $this->record; |
| 23 | - $actions->insertBefore('action_doDelete', $btnPublish = FormAction::create('doPublish','Save & Publish')); |
|
| 23 | + $actions->insertBefore('action_doDelete', $btnPublish = FormAction::create('doPublish', 'Save & Publish')); |
|
| 24 | 24 | $btnPublish->addExtraClass('ss-ui-action-constructive'); |
| 25 | 25 | if (!empty($record->ID)) { |
| 26 | 26 | if ($record->isPublished()) { |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php use SaltedHerring\Debugger as Debugger; |
|
| 1 | +<?php |
|
| 2 | 2 | /** |
| 3 | 3 | * @file BlocksAdmin.php |
| 4 | 4 | * |
@@ -5,60 +5,60 @@ |
||
| 5 | 5 | * Left-hand-side tab : Admin Blocks |
| 6 | 6 | * */ |
| 7 | 7 | class BlocksAdmin extends ModelAdmin { |
| 8 | - private static $managed_models = array('Block'); |
|
| 9 | - private static $url_segment = 'blocks'; |
|
| 10 | - private static $menu_title = 'Blocks'; |
|
| 11 | - private static $menu_priority = 10; |
|
| 12 | - private static $menu_icon = 'silverstripe-block/images/icon-block.png'; |
|
| 8 | + private static $managed_models = array('Block'); |
|
| 9 | + private static $url_segment = 'blocks'; |
|
| 10 | + private static $menu_title = 'Blocks'; |
|
| 11 | + private static $menu_priority = 10; |
|
| 12 | + private static $menu_icon = 'silverstripe-block/images/icon-block.png'; |
|
| 13 | 13 | |
| 14 | - public function getEditForm($id = null, $fields = null) { |
|
| 15 | - $form = parent::getEditForm($id, $fields); |
|
| 14 | + public function getEditForm($id = null, $fields = null) { |
|
| 15 | + $form = parent::getEditForm($id, $fields); |
|
| 16 | 16 | |
| 17 | - $grid = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass)); |
|
| 17 | + $grid = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass)); |
|
| 18 | 18 | |
| 19 | - $grid->getConfig() |
|
| 20 | - ->removeComponentsByType('GridFieldPaginator') |
|
| 21 | - ->removeComponentsByType('GridFieldAddNewButton') |
|
| 22 | - ->removeComponentsByType('GridFieldPrintButton') |
|
| 23 | - ->removeComponentsByType('GridFieldExportButton') |
|
| 24 | - ->removeComponentsByType('GridFieldDetailForm') |
|
| 25 | - ->addComponents( |
|
| 26 | - new VersionedForm(), |
|
| 27 | - new GridFieldPaginatorWithShowAll(30), |
|
| 28 | - $multiClass = new MultiClassSelector(), |
|
| 29 | - $sortable = new GridFieldOrderableRows('SortOrder') |
|
| 30 | - ); |
|
| 19 | + $grid->getConfig() |
|
| 20 | + ->removeComponentsByType('GridFieldPaginator') |
|
| 21 | + ->removeComponentsByType('GridFieldAddNewButton') |
|
| 22 | + ->removeComponentsByType('GridFieldPrintButton') |
|
| 23 | + ->removeComponentsByType('GridFieldExportButton') |
|
| 24 | + ->removeComponentsByType('GridFieldDetailForm') |
|
| 25 | + ->addComponents( |
|
| 26 | + new VersionedForm(), |
|
| 27 | + new GridFieldPaginatorWithShowAll(30), |
|
| 28 | + $multiClass = new MultiClassSelector(), |
|
| 29 | + $sortable = new GridFieldOrderableRows('SortOrder') |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - $subBlocks = self::getAvaiableTypes(); |
|
| 33 | - $multiClass->setClasses($subBlocks); |
|
| 34 | - $grid->setTitle('All Blcoks'); |
|
| 35 | - return $form; |
|
| 36 | - } |
|
| 32 | + $subBlocks = self::getAvaiableTypes(); |
|
| 33 | + $multiClass->setClasses($subBlocks); |
|
| 34 | + $grid->setTitle('All Blcoks'); |
|
| 35 | + return $form; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public function getList() { |
|
| 39 | - $list = Versioned::get_by_stage('Block', 'Stage'); |
|
| 38 | + public function getList() { |
|
| 39 | + $list = Versioned::get_by_stage('Block', 'Stage'); |
|
| 40 | 40 | |
| 41 | - return $list; |
|
| 41 | + return $list; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - public static function getAvaiableTypes() { |
|
| 45 | - $subBlocks = ClassInfo::subclassesFor('Block'); |
|
| 46 | - if (is_null($subBlocks)) { |
|
| 47 | - $subBlocks = array('Block'); |
|
| 48 | - }else{ |
|
| 49 | - $disabledTypes = Config::inst()->get('Block','DisabledBlocks'); |
|
| 50 | - if (!empty($disabledTypes)) { |
|
| 51 | - foreach ($disabledTypes as $disabledType) { |
|
| 52 | - unset($subBlocks[$disabledType]); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - foreach ($subBlocks as $key => &$value) { |
|
| 56 | - $value = empty($key::$singular_name) ? ucwords(trim(strtolower(preg_replace('/_?([A-Z])/', ' $1', $value)))) : $key::$singular_name; |
|
| 57 | - } |
|
| 58 | - } |
|
| 44 | + public static function getAvaiableTypes() { |
|
| 45 | + $subBlocks = ClassInfo::subclassesFor('Block'); |
|
| 46 | + if (is_null($subBlocks)) { |
|
| 47 | + $subBlocks = array('Block'); |
|
| 48 | + }else{ |
|
| 49 | + $disabledTypes = Config::inst()->get('Block','DisabledBlocks'); |
|
| 50 | + if (!empty($disabledTypes)) { |
|
| 51 | + foreach ($disabledTypes as $disabledType) { |
|
| 52 | + unset($subBlocks[$disabledType]); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + foreach ($subBlocks as $key => &$value) { |
|
| 56 | + $value = empty($key::$singular_name) ? ucwords(trim(strtolower(preg_replace('/_?([A-Z])/', ' $1', $value)))) : $key::$singular_name; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - return $subBlocks; |
|
| 61 | - } |
|
| 60 | + return $subBlocks; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | } |
@@ -45,8 +45,8 @@ |
||
| 45 | 45 | $subBlocks = ClassInfo::subclassesFor('Block'); |
| 46 | 46 | if (is_null($subBlocks)) { |
| 47 | 47 | $subBlocks = array('Block'); |
| 48 | - }else{ |
|
| 49 | - $disabledTypes = Config::inst()->get('Block','DisabledBlocks'); |
|
| 48 | + } else { |
|
| 49 | + $disabledTypes = Config::inst()->get('Block', 'DisabledBlocks'); |
|
| 50 | 50 | if (!empty($disabledTypes)) { |
| 51 | 51 | foreach ($disabledTypes as $disabledType) { |
| 52 | 52 | unset($subBlocks[$disabledType]); |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | $subBlocks = ClassInfo::subclassesFor('Block'); |
| 46 | 46 | if (is_null($subBlocks)) { |
| 47 | 47 | $subBlocks = array('Block'); |
| 48 | - }else{ |
|
| 48 | + } else{ |
|
| 49 | 49 | $disabledTypes = Config::inst()->get('Block','DisabledBlocks'); |
| 50 | 50 | if (!empty($disabledTypes)) { |
| 51 | 51 | foreach ($disabledTypes as $disabledType) { |
@@ -1,41 +1,41 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | class PrintBlocks extends Extension { |
| 3 | 3 | |
| 4 | - public function getAllBlocks() { |
|
| 5 | - $blocks = new ArrayList(); |
|
| 6 | - $blocks->merge($this->getMyBlocks()); |
|
| 7 | - $blocks->merge($this->getDockedBlocks()); |
|
| 8 | - return $blocks; |
|
| 9 | - } |
|
| 4 | + public function getAllBlocks() { |
|
| 5 | + $blocks = new ArrayList(); |
|
| 6 | + $blocks->merge($this->getMyBlocks()); |
|
| 7 | + $blocks->merge($this->getDockedBlocks()); |
|
| 8 | + return $blocks; |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public function getMyBlocks() { |
|
| 12 | - $blocks = $this->owner->Blocks()->sort(array('SortOrder' => 'ASC', 'ID' => 'DESC')); |
|
| 13 | - $published_blocks = new ArrayList(); |
|
| 14 | - foreach ($blocks as $block) { |
|
| 15 | - if ($block->isPublished()) { |
|
| 16 | - $published_blocks->push($block); |
|
| 17 | - } |
|
| 18 | - } |
|
| 11 | + public function getMyBlocks() { |
|
| 12 | + $blocks = $this->owner->Blocks()->sort(array('SortOrder' => 'ASC', 'ID' => 'DESC')); |
|
| 13 | + $published_blocks = new ArrayList(); |
|
| 14 | + foreach ($blocks as $block) { |
|
| 15 | + if ($block->isPublished()) { |
|
| 16 | + $published_blocks->push($block); |
|
| 17 | + } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - return $published_blocks; |
|
| 21 | - } |
|
| 20 | + return $published_blocks; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function getDockedBlocks() { |
|
| 24 | - $blocks = Block::get()->filter(array('showBlockbyClass' => true)); |
|
| 25 | - $blocks_map = $blocks->map('ID', 'shownInClass'); |
|
| 26 | - foreach ($blocks_map as $blockID => $Classes) { |
|
| 27 | - $Classes = explode(',', $Classes); |
|
| 28 | - if (!in_array($this->owner->ClassName, $Classes)) { |
|
| 29 | - $blocks = $blocks->exclude('ID', $blockID); |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - $published_blocks = new ArrayList(); |
|
| 33 | - foreach ($blocks as $block) { |
|
| 34 | - if ($block->isPublished()) { |
|
| 35 | - $published_blocks->push($block); |
|
| 36 | - } |
|
| 37 | - } |
|
| 23 | + public function getDockedBlocks() { |
|
| 24 | + $blocks = Block::get()->filter(array('showBlockbyClass' => true)); |
|
| 25 | + $blocks_map = $blocks->map('ID', 'shownInClass'); |
|
| 26 | + foreach ($blocks_map as $blockID => $Classes) { |
|
| 27 | + $Classes = explode(',', $Classes); |
|
| 28 | + if (!in_array($this->owner->ClassName, $Classes)) { |
|
| 29 | + $blocks = $blocks->exclude('ID', $blockID); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + $published_blocks = new ArrayList(); |
|
| 33 | + foreach ($blocks as $block) { |
|
| 34 | + if ($block->isPublished()) { |
|
| 35 | + $published_blocks->push($block); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $published_blocks->sort('SortOrder', 'ASC'); |
|
| 40 | - } |
|
| 39 | + return $published_blocks->sort('SortOrder', 'ASC'); |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -1,29 +1,29 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class OrderableBlocks extends GridFieldOrderableRows { |
| 4 | - protected function reorderItems($list, array $values, array $order) { |
|
| 5 | - $pool = array_values($values); |
|
| 6 | - sort($pool); |
|
| 4 | + protected function reorderItems($list, array $values, array $order) { |
|
| 5 | + $pool = array_values($values); |
|
| 6 | + sort($pool); |
|
| 7 | 7 | |
| 8 | - foreach(array_values($order) as $pos => $id) { |
|
| 9 | - if($values[$id] != $pool[$pos]) { |
|
| 10 | - DB::query(sprintf( |
|
| 11 | - 'UPDATE "%s" SET "%s" = %d WHERE %s', |
|
| 12 | - $this->getSortTable($list), |
|
| 13 | - $this->getSortField(), |
|
| 14 | - $pool[$pos], |
|
| 15 | - $this->getSortTableClauseForIds($list, $id) |
|
| 16 | - )); |
|
| 17 | - DB::query(sprintf( |
|
| 18 | - 'UPDATE "%s_Live" SET "%s" = %d WHERE %s', |
|
| 19 | - $this->getSortTable($list), |
|
| 20 | - $this->getSortField(), |
|
| 21 | - $pool[$pos], |
|
| 22 | - $this->getSortTableClauseForIds($list, $id) |
|
| 23 | - )); |
|
| 24 | - } |
|
| 25 | - } |
|
| 8 | + foreach(array_values($order) as $pos => $id) { |
|
| 9 | + if($values[$id] != $pool[$pos]) { |
|
| 10 | + DB::query(sprintf( |
|
| 11 | + 'UPDATE "%s" SET "%s" = %d WHERE %s', |
|
| 12 | + $this->getSortTable($list), |
|
| 13 | + $this->getSortField(), |
|
| 14 | + $pool[$pos], |
|
| 15 | + $this->getSortTableClauseForIds($list, $id) |
|
| 16 | + )); |
|
| 17 | + DB::query(sprintf( |
|
| 18 | + 'UPDATE "%s_Live" SET "%s" = %d WHERE %s', |
|
| 19 | + $this->getSortTable($list), |
|
| 20 | + $this->getSortField(), |
|
| 21 | + $pool[$pos], |
|
| 22 | + $this->getSortTableClauseForIds($list, $id) |
|
| 23 | + )); |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - $this->extend('onAfterReorderItems', $list); |
|
| 28 | - } |
|
| 27 | + $this->extend('onAfterReorderItems', $list); |
|
| 28 | + } |
|
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | $pool = array_values($values); |
| 6 | 6 | sort($pool); |
| 7 | 7 | |
| 8 | - foreach(array_values($order) as $pos => $id) { |
|
| 9 | - if($values[$id] != $pool[$pos]) { |
|
| 8 | + foreach (array_values($order) as $pos => $id) { |
|
| 9 | + if ($values[$id] != $pool[$pos]) { |
|
| 10 | 10 | DB::query(sprintf( |
| 11 | 11 | 'UPDATE "%s" SET "%s" = %d WHERE %s', |
| 12 | 12 | $this->getSortTable($list), |
@@ -1,62 +1,62 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class BlockinPage extends Extension { |
| 4 | - private static $belongs_many_many = array ( |
|
| 5 | - 'Blocks' => 'Block' |
|
| 6 | - ); |
|
| 4 | + private static $belongs_many_many = array ( |
|
| 5 | + 'Blocks' => 'Block' |
|
| 6 | + ); |
|
| 7 | 7 | |
| 8 | - public function updateCMSFields( FieldList $fields ) { |
|
| 9 | - $ancestry = ClassInfo::ancestry($this->owner->ClassName); |
|
| 10 | - if (!in_array('RedirectorPage', $ancestry) && !in_array('VirtualPage', $ancestry)) { |
|
| 11 | - $blocks = $this->owner->Blocks(); |
|
| 12 | - $blocks_grid = $this->gridBuilder('Blocks', $blocks, '', true,'GridFieldConfig_RelationEditor'); |
|
| 13 | - $docked_grid = $this->gridBuilder('DockedBlocks', $this->dockedBlocks(), ''); |
|
| 8 | + public function updateCMSFields( FieldList $fields ) { |
|
| 9 | + $ancestry = ClassInfo::ancestry($this->owner->ClassName); |
|
| 10 | + if (!in_array('RedirectorPage', $ancestry) && !in_array('VirtualPage', $ancestry)) { |
|
| 11 | + $blocks = $this->owner->Blocks(); |
|
| 12 | + $blocks_grid = $this->gridBuilder('Blocks', $blocks, '', true,'GridFieldConfig_RelationEditor'); |
|
| 13 | + $docked_grid = $this->gridBuilder('DockedBlocks', $this->dockedBlocks(), ''); |
|
| 14 | 14 | |
| 15 | - $fields->addFieldToTab('Root.MyBlocks', $blocks_grid); |
|
| 16 | - $fields->addFieldToTab('Root.DockedBlocks', $docked_grid); |
|
| 17 | - } |
|
| 18 | - } |
|
| 15 | + $fields->addFieldToTab('Root.MyBlocks', $blocks_grid); |
|
| 16 | + $fields->addFieldToTab('Root.DockedBlocks', $docked_grid); |
|
| 17 | + } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - private function gridBuilder($name, $source, $label = '', $canAdd = false, $gridHeaderType = 'GridFieldConfig_RecordEditor') { |
|
| 21 | - /* |
|
| 20 | + private function gridBuilder($name, $source, $label = '', $canAdd = false, $gridHeaderType = 'GridFieldConfig_RecordEditor') { |
|
| 21 | + /* |
|
| 22 | 22 | GridFieldConfig_Base |
| 23 | 23 | GridFieldConfig_RecordViewer |
| 24 | 24 | GridFieldConfig_RecordEditor |
| 25 | 25 | GridFieldConfig_RelationEditor |
| 26 | 26 | */ |
| 27 | - if ($label == '') { $label = $name; } |
|
| 28 | - $grid = new GridField($name, $label, $source); |
|
| 29 | - $config = $gridHeaderType::create(); |
|
| 30 | - $config->removeComponentsByType('GridFieldAddNewButton'); |
|
| 31 | - if ( $canAdd ) { |
|
| 32 | - $config |
|
| 33 | - ->removeComponentsByType('GridFieldPaginator') |
|
| 34 | - ->removeComponentsByType('GridFieldDetailForm') |
|
| 35 | - ->addComponents( |
|
| 36 | - new VersionedForm(), |
|
| 37 | - new GridFieldPaginatorWithShowAll(30), |
|
| 38 | - $multiClass = new MultiClassSelector(), |
|
| 39 | - $sortable = new OrderableBlocks('SortOrder') |
|
| 40 | - ); |
|
| 41 | - $subBlocks = BlocksAdmin::getAvaiableTypes(); |
|
| 42 | - $multiClass->setClasses($subBlocks); |
|
| 43 | - } |
|
| 44 | - $grid->setConfig($config); |
|
| 45 | - return $grid; |
|
| 46 | - } |
|
| 27 | + if ($label == '') { $label = $name; } |
|
| 28 | + $grid = new GridField($name, $label, $source); |
|
| 29 | + $config = $gridHeaderType::create(); |
|
| 30 | + $config->removeComponentsByType('GridFieldAddNewButton'); |
|
| 31 | + if ( $canAdd ) { |
|
| 32 | + $config |
|
| 33 | + ->removeComponentsByType('GridFieldPaginator') |
|
| 34 | + ->removeComponentsByType('GridFieldDetailForm') |
|
| 35 | + ->addComponents( |
|
| 36 | + new VersionedForm(), |
|
| 37 | + new GridFieldPaginatorWithShowAll(30), |
|
| 38 | + $multiClass = new MultiClassSelector(), |
|
| 39 | + $sortable = new OrderableBlocks('SortOrder') |
|
| 40 | + ); |
|
| 41 | + $subBlocks = BlocksAdmin::getAvaiableTypes(); |
|
| 42 | + $multiClass->setClasses($subBlocks); |
|
| 43 | + } |
|
| 44 | + $grid->setConfig($config); |
|
| 45 | + return $grid; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - private function dockedBlocks() { |
|
| 49 | - $blocks = Block::get(); |
|
| 50 | - $IDs = array(); |
|
| 51 | - $ClassName = $this->owner->ClassName; |
|
| 52 | - $Classes = $blocks->map('ID', 'shownInClass'); |
|
| 53 | - foreach ($Classes as $BlockID => $Class) { |
|
| 54 | - $listedClasses = explode(',', $Class); |
|
| 55 | - if (in_array($ClassName, $listedClasses)) { |
|
| 56 | - $IDs[] = $BlockID; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $blocks = Block::get()->filter('ID', $IDs)->sort('SortOrder','ASC'); |
|
| 60 | - return $blocks; |
|
| 61 | - } |
|
| 48 | + private function dockedBlocks() { |
|
| 49 | + $blocks = Block::get(); |
|
| 50 | + $IDs = array(); |
|
| 51 | + $ClassName = $this->owner->ClassName; |
|
| 52 | + $Classes = $blocks->map('ID', 'shownInClass'); |
|
| 53 | + foreach ($Classes as $BlockID => $Class) { |
|
| 54 | + $listedClasses = explode(',', $Class); |
|
| 55 | + if (in_array($ClassName, $listedClasses)) { |
|
| 56 | + $IDs[] = $BlockID; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $blocks = Block::get()->filter('ID', $IDs)->sort('SortOrder','ASC'); |
|
| 60 | + return $blocks; |
|
| 61 | + } |
|
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -1,15 +1,15 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class BlockinPage extends Extension { |
| 4 | - private static $belongs_many_many = array ( |
|
| 4 | + private static $belongs_many_many = array( |
|
| 5 | 5 | 'Blocks' => 'Block' |
| 6 | 6 | ); |
| 7 | 7 | |
| 8 | - public function updateCMSFields( FieldList $fields ) { |
|
| 8 | + public function updateCMSFields(FieldList $fields) { |
|
| 9 | 9 | $ancestry = ClassInfo::ancestry($this->owner->ClassName); |
| 10 | 10 | if (!in_array('RedirectorPage', $ancestry) && !in_array('VirtualPage', $ancestry)) { |
| 11 | 11 | $blocks = $this->owner->Blocks(); |
| 12 | - $blocks_grid = $this->gridBuilder('Blocks', $blocks, '', true,'GridFieldConfig_RelationEditor'); |
|
| 12 | + $blocks_grid = $this->gridBuilder('Blocks', $blocks, '', true, 'GridFieldConfig_RelationEditor'); |
|
| 13 | 13 | $docked_grid = $this->gridBuilder('DockedBlocks', $this->dockedBlocks(), ''); |
| 14 | 14 | |
| 15 | 15 | $fields->addFieldToTab('Root.MyBlocks', $blocks_grid); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $grid = new GridField($name, $label, $source); |
| 29 | 29 | $config = $gridHeaderType::create(); |
| 30 | 30 | $config->removeComponentsByType('GridFieldAddNewButton'); |
| 31 | - if ( $canAdd ) { |
|
| 31 | + if ($canAdd) { |
|
| 32 | 32 | $config |
| 33 | 33 | ->removeComponentsByType('GridFieldPaginator') |
| 34 | 34 | ->removeComponentsByType('GridFieldDetailForm') |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $IDs[] = $BlockID; |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | - $blocks = Block::get()->filter('ID', $IDs)->sort('SortOrder','ASC'); |
|
| 59 | + $blocks = Block::get()->filter('ID', $IDs)->sort('SortOrder', 'ASC'); |
|
| 60 | 60 | return $blocks; |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | \ No newline at end of file |
@@ -1,9 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class DualColumnBlock extends Block { |
| 4 | - private static $singular_name = 'Dual-column Block'; |
|
| 5 | - private static $db = array ( |
|
| 6 | - 'LeftColumn' => 'HTMLText', |
|
| 7 | - 'RightColumn' => 'HTMLText' |
|
| 8 | - ); |
|
| 4 | + private static $singular_name = 'Dual-column Block'; |
|
| 5 | + private static $db = array ( |
|
| 6 | + 'LeftColumn' => 'HTMLText', |
|
| 7 | + 'RightColumn' => 'HTMLText' |
|
| 8 | + ); |
|
| 9 | 9 | } |
| 10 | 10 | \ No newline at end of file |
@@ -2,7 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | class DualColumnBlock extends Block { |
| 4 | 4 | private static $singular_name = 'Dual-column Block'; |
| 5 | - private static $db = array ( |
|
| 5 | + private static $db = array( |
|
| 6 | 6 | 'LeftColumn' => 'HTMLText', |
| 7 | 7 | 'RightColumn' => 'HTMLText' |
| 8 | 8 | ); |