Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SS4 upgrade #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
<?php

if (($NEWS_MODULE_DIR = basename(dirname(__FILE__))) != 'news') {
die("News module should exist in the /news directory, not $NEWS_MODULE_DIR");
}
25 changes: 17 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
{
"name": "silverstripe-australia/silverstripe-news",
"description": "News module for silverstripe",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": ["silverstripe", "news"],
"authors": [
{
"name": "Marcus Nyeholt"
"name": "Marcus Nyeholt"
}
],
"require": {
"silverstripe/framework": "^3.1.0",
"silverstripe/cms": "^3.1.0"
"silverstripe/framework": "^4.1.0",
"silverstripe/cms": "^4.1.0"
},
"autoload": {
"psr-4": {
"Symbiote\\News\\": "src/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
},
"installer-name": "news"
"dev-master": "2.x-dev"
},
"installer-name": "silverstripe-news",
"expose": [
"images"
]
},
"minimum-stability": "dev"
"minimum-stability": "dev",
"prefer-stable": true
}
57 changes: 32 additions & 25 deletions code/pages/NewsArticle.php → src/NewsArticle.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
<?php

namespace Symbiote\News;

use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Image;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\DateField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;

/**
* A news article in the system
*
* @author Marcus Nyeholt <[email protected]>
* @license BSD License http://silverstripe.org/bsd-license/
*/
class NewsArticle extends Page {
class NewsArticle extends SiteTree {

private static $icon = 'news/images/newspaper';
private static $table_name = 'NewsArticle';
private static $icon = 'resources/vendor/silverstripe-australia/silverstripe-news/images/newspaper-file.gif';
private static $db = array(
'Summary' => 'HTMLText',
'Author' => 'Varchar(128)',
Expand All @@ -18,14 +30,14 @@ class NewsArticle extends Page {
);
/**
* The InternalFile is used when the news article is mostly contained in a file based item -
* if this is set, then the URL to the item is returned in the call to "Link" for this asset.
* if this is set, then the URL to the item is returned in the call to "Link" for this asset.
*
* @var array
*/
private static $has_one = array(
'InternalFile' => 'File',
'NewsSection' => 'NewsHolder',
'Thumbnail' => 'Image',
'InternalFile' => File::class,
'NewsSection' => NewsHolder::class,
'Thumbnail' => Image::class,
);

public function getCMSFields() {
Expand All @@ -34,13 +46,11 @@ public function getCMSFields() {
$fields->addFieldToTab('Root.Main', new TextField('Author', _t('NewsArticle.AUTHOR', 'Author')), 'Content');
$fields->addFieldToTab('Root.Main', $dp = new DateField('OriginalPublishedDate', _t('NewsArticle.PUBLISHED_DATE', 'When was this article first published?')), 'Content');

$dp->setConfig('showcalendar', true);

$fields->addFieldToTab('Root.Main', new TextField('ExternalURL', _t('NewsArticle.EXTERNAL_URL', 'External URL to article (will automatically redirect to this URL if no article content set)')), 'Content');
$fields->addFieldToTab('Root.Main', new TextField('Source', _t('NewsArticle.SOURCE', 'News Source')), 'Content');

$fields->addFieldToTab('Root.Main', $if = new UploadField('Thumbnail', _t('NewsArticle.THUMB', 'Thumbnail')), 'Content');
$if->setConfig('allowedMaxFileNumber', 1)->setFolderName('news-articles/thumbnails');
$if->setAllowedMaxFileNumber(1)->setFolderName('news-articles/thumbnails');
$if->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));

if (!$this->OriginalPublishedDate) {
Expand All @@ -49,11 +59,11 @@ public function getCMSFields() {
}

$fields->addFieldToTab('Root.Main', UploadField::create('InternalFile', _t('NewsArticle.INTERNAL_FILE', 'Select a file containing this news article, if any'))->setFolderName('news'), 'Content');
$fields->addFieldToTab('Root.Main', $summary = new HtmlEditorField('Summary', _t('NewsArticle.SUMMARY', 'Article Summary (displayed in listings)')), 'Content');
$fields->addFieldToTab('Root.Main', $summary = new HTMLEditorField('Summary', _t('NewsArticle.SUMMARY', 'Article Summary (displayed in listings)')), 'Content');
$summary->addExtraClass('stacked');

$this->extend('updateArticleCMSFields', $fields);

return $fields;
}

Expand All @@ -63,13 +73,13 @@ public function getCMSFields() {
*/
public function onBeforeWrite() {
parent::onBeforeWrite();

// dummy initial date
if (!$this->OriginalPublishedDate) {
// @TODO Fix this to be correctly localized!!
$this->OriginalPublishedDate = date('Y-m-d 12:00:00');
}

$parent = $this->Parent();

// just in case we've been moved, update our section
Expand Down Expand Up @@ -98,20 +108,20 @@ public function onBeforePublish() {
// go through all parents that are news holders and publish them if they haven't been
$this->publishSection();
}

public function onAfterPublish() {
// $this->publishSection();
}

/**
* Ensure's the section is published.
*
*
* We need to do it both before and after publish because of some quirks with
* folders not existing on one but existing on the other depending on the order of
* writing the objects
*/
protected function publishSection() {
$parent = DataObject::get_by_id('NewsHolder', $this->ParentID);
$parent = DataObject::get_by_id(NewsHolder::class, $this->ParentID);
while ($parent && $parent instanceof NewsHolder) {
if (!$parent->isPublished()) {
$parent->doPublish();
Expand Down Expand Up @@ -164,7 +174,7 @@ public function HasExternalLink() {
}

/**
* Link to the news article. If it has an external URL set, or a file, link to that instead.
* Link to the news article. If it has an external URL set, or a file, link to that instead.
*
* @param String $action
* @return String
Expand All @@ -180,8 +190,8 @@ public function Link($action='') {
}
return parent::Link($action);
}


/**
* Pages to update cache file for static publisher
*
Expand All @@ -190,19 +200,16 @@ public function Link($action='') {
public function pagesAffectedByChanges() {
$parent = $this->Parent();
$urls = array($this->Link());

// add all parent (holders)
while($parent && $parent->ParentID > -1 && $parent instanceof NewsHolder) {
$urls[] = $parent->Link();
$parent = $parent->Parent();
}

$this->extend('updatePagesAffectedByChanges', $urls);

return $urls;
}

}

class NewsArticle_Controller extends Page_Controller {
}
11 changes: 11 additions & 0 deletions src/NewsArticleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Symbiote\News;

use SilverStripe\CMS\Controllers\ContentController;

//template inheritance doesnt work when not using PageController
//Seems PageController in root namespace is mandatory

class NewsArticleController extends \PageController {
}
Loading