From d1d945275715e2ca3b0dc6c7e4ef4d9184c906ee Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 16 Apr 2013 15:28:45 +0200 Subject: [PATCH] API Moved "SideBar" widget relation to "widgets" module Removed BlogTreeExtension in favour of the new WidgetPageExtension in the "widgets module". Use the following code to update: Object::add_extension('BlogTree', 'WidgetPageExtension'); Object::add_extension('BlogEntry', 'WidgetPageExtension'); The template placeholder has been renamed from $SideBar to $SideBarView. In case you're overriding blog templates, please adjust accordingly. This change means that widgets can theoretically be applied to individual blog entries as well, since they need the "SideBar" relationship as well. In practice, this defaults to "InheritSideBar" though, which pulls them from the BlogHolder as usual. --- README.md | 16 ++++++++++ _config.php | 3 -- code/BlogEntry.php | 10 ------- code/BlogHolder.php | 48 +++++++++++++++++------------- code/BlogTree.php | 33 -------------------- code/widgets/BlogTreeExtension.php | 7 ----- css/flickrwidget.css | 3 -- templates/Includes/BlogSideBar.ss | 8 +++-- 8 files changed, 48 insertions(+), 80 deletions(-) delete mode 100644 code/widgets/BlogTreeExtension.php delete mode 100644 css/flickrwidget.css diff --git a/README.md b/README.md index 54510a7..38ad614 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,22 @@ or: mysite/blog/2007 would show blog entries for 2007 See [:pagecomment](/pagecomment) for creating Askimet-protected comments for every page. +## Widgets + +The module comes with a couple of default widgets, which rely on the "silverstripe/widgets" +module being installed. Since widgets are based on database records and relations +to pages, they need to be enabled through an `Extension` class in your `config.yml`: + + :::yml + BlogTree: + extensions: + - WidgetPageExtension + BlogEntry: + extensions: + - WidgetPageExtension + +Alternatively, you can simply enable the extension on your `Page` records +to have it available globally. ## Working with the theme diff --git a/_config.php b/_config.php index 82eba82..e69de29 100644 --- a/_config.php +++ b/_config.php @@ -1,3 +0,0 @@ -Parent(), 'SideBar')) { - return $this->getParent()->SideBar(); - } - - } - function Content() { if(self::$allow_wysiwyg_editing) { return $this->getField('Content'); diff --git a/code/BlogHolder.php b/code/BlogHolder.php index f079e69..a48013c 100644 --- a/code/BlogHolder.php +++ b/code/BlogHolder.php @@ -129,39 +129,45 @@ class BlogHolder extends BlogTree implements PermissionProvider { $blogholder->Title = "Blog"; $blogholder->URLSegment = "blog"; $blogholder->Status = "Published"; + $blogholder->write(); + $blogholder->publish("Stage", "Live"); + // Add default widgets to first found WidgetArea relationship if(class_exists('WidgetArea')) { - $widgetarea = new WidgetArea(); - $widgetarea->write(); + foreach($this->has_one() as $name => $class) { + if(is_a($class, 'WidgetArea', true)) { + $relationName = "{$name}ID"; + $widgetarea = new WidgetArea(); + $widgetarea->write(); - $blogholder->SideBarID = $widgetarea->ID; - $blogholder->write(); - $blogholder->publish("Stage", "Live"); + $blogholder->$relationName = $widgetarea->ID; + $blogholder->write(); + $blogholder->publish("Stage", "Live"); - $managementwidget = new BlogManagementWidget(); - $managementwidget->ParentID = $widgetarea->ID; - $managementwidget->write(); + $managementwidget = new BlogManagementWidget(); + $managementwidget->ParentID = $widgetarea->ID; + $managementwidget->write(); - $tagcloudwidget = new TagCloudWidget(); - $tagcloudwidget->ParentID = $widgetarea->ID; - $tagcloudwidget->write(); + $tagcloudwidget = new TagCloudWidget(); + $tagcloudwidget->ParentID = $widgetarea->ID; + $tagcloudwidget->write(); - $archivewidget = new ArchiveWidget(); - $archivewidget->ParentID = $widgetarea->ID; - $archivewidget->write(); + $archivewidget = new ArchiveWidget(); + $archivewidget->ParentID = $widgetarea->ID; + $archivewidget->write(); - $widgetarea->write(); - } else { - $blogholder->write(); - $blogholder->publish("Stage", "Live"); - } - + $widgetarea->write(); + + break; // only apply to one + } + } + } $blog = new BlogEntry(); $blog->Title = _t('BlogHolder.SUCTITLE', "SilverStripe blog module successfully installed"); $blog->URLSegment = 'sample-blog-entry'; $blog->Tags = _t('BlogHolder.SUCTAGS',"silverstripe, blog"); - $blog->Content = _t('BlogHolder.SUCCONTENT',"

Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog (such as the widgets displayed in the sidebar) in the CMS.

"); + $blog->Content = _t('BlogHolder.SUCCONTENT',"

Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog in the CMS.

"); $blog->Status = "Published"; $blog->ParentID = $blogholder->ID; $blog->write(); diff --git a/code/BlogTree.php b/code/BlogTree.php index 19f77c5..9ab754a 100644 --- a/code/BlogTree.php +++ b/code/BlogTree.php @@ -23,24 +23,13 @@ class BlogTree extends Page { static $default_entries_limit = 10; static $db = array( - 'InheritSideBar' => 'Boolean', 'LandingPageFreshness' => 'Varchar', ); - static $defaults = array( - 'InheritSideBar' => True - ); - - static $has_one = array(); - - static $has_many = array(); - static $allowed_children = array( 'BlogTree', 'BlogHolder' ); - - /* * Finds the BlogTree object most related to the current page. * - If this page is a BlogTree, use that @@ -90,30 +79,8 @@ class BlogTree extends Page { return $freshness; } - function SideBar() { - if($this->InheritSideBar && $this->getParent()) { - if (method_exists($this->getParent(), 'SideBar')) return $this->getParent()->SideBar(); - } - - if($this->SideBarID){ - return DataObject::get_by_id('WidgetArea', $this->SideBarID); - // @todo: This segfaults - investigate why then fix: return $this->getComponent('SideBar'); - } - } - /* ----------- CMS CONTROL -------------- */ - function getCMSFields() { - $fields = parent::getCMSFields(); - - if(class_exists('WidgetArea')) { - $fields->addFieldToTab("Root.Widgets", new CheckboxField("InheritSideBar", 'Inherit Sidebar From Parent')); - $fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("SideBar")); - } - - return $fields; - } - function getSettingsFields() { $fields = parent::getSettingsFields(); diff --git a/code/widgets/BlogTreeExtension.php b/code/widgets/BlogTreeExtension.php deleted file mode 100644 index 60b5820..0000000 --- a/code/widgets/BlogTreeExtension.php +++ /dev/null @@ -1,7 +0,0 @@ - "WidgetArea"); - -} \ No newline at end of file diff --git a/css/flickrwidget.css b/css/flickrwidget.css deleted file mode 100644 index ef16f0a..0000000 --- a/css/flickrwidget.css +++ /dev/null @@ -1,3 +0,0 @@ -div.flickrwidget { - text-align: center; -} \ No newline at end of file diff --git a/templates/Includes/BlogSideBar.ss b/templates/Includes/BlogSideBar.ss index ebd57aa..0833703 100644 --- a/templates/Includes/BlogSideBar.ss +++ b/templates/Includes/BlogSideBar.ss @@ -1,3 +1,5 @@ - \ No newline at end of file +<% if SideBarView %> + +<% end_if %> \ No newline at end of file