-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5d02047
Showing
12 changed files
with
307 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
.buildpath | ||
.project | ||
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Installation Instructions # | ||
## Composer ## | ||
Run the following to add this module as a requirement and install it via composer. | ||
|
||
``` | ||
#!bash | ||
composer require "webfox/silverstripe-global-content" | ||
``` | ||
then browse to /dev/build?flush=all | ||
|
||
|
||
#Requirements# | ||
* Silverstripe 3.2+ | ||
* php5.4+ | ||
|
||
#Module Overview# | ||
This module adds a convenient `SiteConfig` like interface for managing global content. | ||
Useful for when you want global content but don't want to give content-authors access to `SiteConfig` | ||
|
||
#Module Usage# | ||
Too add additional fields: | ||
* Create a `DataExtension` that gets applied to `GlobalContent` | ||
* The extension requires an `updateFields(FieldList $fields)` method and any standard `DataExtension` properties | ||
|
||
```php | ||
class GlobalContentExtension extends DataExtension | ||
{ | ||
|
||
protected static $db = [ | ||
'MyFieldName' => 'Varchar' | ||
]; | ||
|
||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
|
||
$fields->addFieldToTab( | ||
'Root.Main', | ||
TextField::create('MyFieldName', 'My field name') | ||
); | ||
|
||
} | ||
|
||
} | ||
``` | ||
|
||
The use with permissions: | ||
* Grant the user/role/group the `Access to 'Global Content' section` permission | ||
|
||
To use in templates: | ||
* `$GlobalContent.MyFieldName` | ||
* `<% with $GlobalContent %> {$MyFieldName} <% end_with %>` | ||
|
||
To use in PHP: | ||
* `GlobalContent::inst()->MyFieldName` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
Name: silverstripe-global-content | ||
--- | ||
|
||
ContentController: | ||
extensions: | ||
- GlobalContent_ContentControllerExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
class GlobalContent extends DataObject | ||
{ | ||
/** | ||
* Return the GlobalContent instance | ||
* | ||
* @return self | ||
*/ | ||
public static function inst() | ||
{ | ||
return static::get_one(__CLASS__); | ||
} | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
$fields->add(HiddenField::create('ID', 'ID', $this->ID)); | ||
|
||
/** @var TabSet $rootTabset */ | ||
$rootTabset = $fields->fieldByName('Root'); | ||
$rootTabset->setTemplate('TablessCMSTabSet'); | ||
|
||
return $fields; | ||
} | ||
|
||
|
||
public function requireDefaultRecords() | ||
{ | ||
if (!static::inst()) { | ||
/** @var self $config */ | ||
$config = new static(); | ||
$config->write(); | ||
|
||
DB::alteration_message('Created default Global Content instance', 'created'); | ||
} | ||
} | ||
|
||
public function canView($member = null) | ||
{ | ||
return true; | ||
} | ||
|
||
public function canEdit($member = null) | ||
{ | ||
return Permission::check('CMS_ACCESS_GlobalContent_ModelAdmin', 'any', $member); | ||
} | ||
|
||
public function canDelete($member = null) | ||
{ | ||
return false; | ||
} | ||
|
||
public function canCreate($member = null) | ||
{ | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
class GlobalContent_ContentControllerExtension extends Extension | ||
{ | ||
|
||
public function getGlobalContent() | ||
{ | ||
return GlobalContent::inst(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
class GlobalContent_ModelAdmin extends ModelAdmin | ||
{ | ||
private static $managed_models = ['GlobalContent']; | ||
|
||
private static $url_segment = 'global-content'; | ||
|
||
private static $menu_title = 'Global Content'; | ||
|
||
protected static $menu_icon = 'silverstripe-global-content/images/globe-icon.png'; | ||
|
||
protected static $tree_class = 'GlobalContent'; | ||
|
||
public function getEditForm($id = null, $fields = null) | ||
{ | ||
$fields = GlobalContent::inst()->getCMSFields(); | ||
$actions = FieldList::create( | ||
FormAction::create('save', _t('GridFieldDetailForm.Save', 'Save')) | ||
->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive') | ||
); | ||
|
||
GlobalContent::inst()->extend('updateCMSActions', $actions); | ||
|
||
if (GlobalContent::inst()->hasMethod('getCMSValidator')) { | ||
$validator = GlobalContent::inst()->getCMSValidator(); | ||
} else { | ||
$validator = RequiredFields::create(); | ||
} | ||
GlobalContent::inst()->extend('updateCMSValidator', $validator); | ||
|
||
/** @var CMSForm $form */ | ||
$form = CMSForm::create($this, 'EditForm', $fields, $actions, $validator); | ||
$form->loadDataFrom(GlobalContent::inst()); | ||
$form->addExtraClass('cms-edit-form center'); | ||
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); | ||
$form->setHTMLID('Form_EditForm'); | ||
$form->setResponseNegotiator($this->getResponseNegotiator()); | ||
$form->setAttribute('data-pjax-fragment', 'CurrentForm'); | ||
$form->setFormAction(Controller::join_links( | ||
$this->Link($this->sanitiseClassName($this->modelClass)), | ||
'EditForm' | ||
)); | ||
|
||
$this->extend('updateEditForm', $form); | ||
|
||
return $form; | ||
} | ||
|
||
public function saveSettings($data, Form $form) | ||
{ | ||
|
||
$globalContentInstance = GlobalContent::inst(); | ||
|
||
$form->saveInto($globalContentInstance); | ||
$form->sessionMessage('Global content updated', 'good'); | ||
|
||
return $this->getResponseNegotiator()->respond($this->request); | ||
} | ||
|
||
public function save($data, $form) | ||
{ | ||
return parent::save($data, $form); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "webfox/silverstripe-global-content", | ||
"description": "Silverstripe SiteConfig like interface for global content that content-authors can access", | ||
"keywords": [ | ||
"webfox", | ||
"silverstripe", | ||
"global" | ||
], | ||
"type": "silverstripe-module", | ||
"require": { | ||
"silverstripe/cms": "~3.2" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Matthew Hailwood", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"extra": { | ||
"installer-name": "silverstripe-global-content" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="cms-content cms-tabset center $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content" data-blerg="glerg"> | ||
$EditForm | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<% if $IncludeFormTag %> | ||
<form $FormAttributes data-layout-type="border"> | ||
<% end_if %> | ||
|
||
<div class="cms-content-header north"> | ||
<div class="cms-content-header-info"> | ||
<% with $Controller %> | ||
<% include CMSBreadcrumbs %> | ||
<% end_with %> | ||
</div> | ||
|
||
<% if $Fields.hasTabset && $Fields.fieldByName('Root').Tabs.Count > 1 %> | ||
<div class="cms-content-header-tabs cms-tabset-nav-primary ss-ui-tabs-nav"> | ||
<ul> | ||
<% loop $Fields.fieldByName('Root').Tabs %> | ||
<li class="tab-$ClassName <% if $extraClass %>$extraClass<% end_if %>"> | ||
<a href="#$id" class="cms-panel-link" title="Form_EditForm">$Title</a> | ||
</li> | ||
<% end_loop %> | ||
</ul> | ||
</div> | ||
<% end_if %> | ||
|
||
</div> | ||
|
||
<div class="cms-content-fields center ui-widget-content" data-layout-type="border"> | ||
|
||
<div class="cms-content-fields center cms-panel-padded"> | ||
<% if $Message %> | ||
<p id="{$FormName}_error" class="message $MessageType">$Message</p> | ||
<% else %> | ||
<p id="{$FormName}_error" class="message $MessageType" style="display: none"></p> | ||
<% end_if %> | ||
|
||
<fieldset> | ||
<% if $Legend %> | ||
<legend>$Legend</legend><% end_if %> | ||
|
||
<% loop $Fields %> | ||
$FieldHolder | ||
<% end_loop %> | ||
<div class="clear"><!-- --></div> | ||
</fieldset> | ||
</div> | ||
|
||
<div class="cms-content-actions south"> | ||
<% if $Actions %> | ||
<div class="Actions"> | ||
<% loop $Actions %> | ||
$Field | ||
<% end_loop %> | ||
<% if $Controller.LinkPreview %> | ||
<a href="$Controller.LinkPreview" class="cms-preview-toggle-link ss-ui-button" | ||
data-icon="preview"> | ||
<% _t('LeftAndMain.PreviewButton', 'Preview') %> » | ||
</a> | ||
<% end_if %> | ||
</div> | ||
<% end_if %> | ||
</div> | ||
</div> | ||
|
||
<% if $IncludeFormTag %> | ||
</form> | ||
<% end_if %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div $AttributesHTML> | ||
<% loop $Tabs %> | ||
<% if $Tabs %> | ||
$FieldHolder | ||
<% else %> | ||
<div $AttributesHTML> | ||
<% loop $Fields %> | ||
$FieldHolder | ||
<% end_loop %> | ||
</div> | ||
<% end_if %> | ||
<% end_loop %> | ||
</div> |