Skip to content

Commit

Permalink
ENH Add generic types (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Jan 18, 2024
1 parent 5071f0e commit b7b4ff8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
11 changes: 7 additions & 4 deletions src/VersionFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\View\Parsers\HtmlDiff;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Versioned\Versioned_Version;

/**
* @extends Extension<SiteTree&static>
*/
class VersionFeed extends SiteTreeExtension
{

private static $db = array(
'PublicHistory' => 'Boolean(true)'
);
Expand Down Expand Up @@ -68,7 +71,7 @@ public function updateFieldLabels(&$labels)
* @param int $highestVersion Top version number to consider.
* @param int $limit Limit to the amount of items returned.
*
* @returns ArrayList List of cleaned records.
* @return ArrayList<Versioned_Version> List of cleaned records.
*/
public function getDiffList($highestVersion = null, $limit = 100)
{
Expand Down Expand Up @@ -156,7 +159,7 @@ public function getDiffList($highestVersion = null, $limit = 100)
* Return a single diff representing this version.
* Returns the initial version if there is nothing to compare to.
*
* @return DataObject|null Object with relevant fields diffed.
* @return Versioned_Version|null Object with relevant fields diffed.
*/
public function getDiff()
{
Expand All @@ -173,7 +176,7 @@ public function updateSettingsFields(FieldList $fields)
if (!$this->owner->config()->get('changes_enabled')) {
return;
}

// Add public history field.
$fields->addFieldToTab(
'Root.Settings',
Expand Down
16 changes: 10 additions & 6 deletions src/VersionFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,29 @@
use SilverStripe\Security\Member;
use SilverStripe\ORM\ArrayList;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Convert;
use SilverStripe\View\Requirements;
use SilverStripe\Core\Extension;
use SilverStripe\VersionFeed\Filters\ContentFilter;

/**
* @extends Extension<Controller&static>
*/
class VersionFeedController extends Extension
{
private static $allowed_actions = array(
'changes',
'allchanges'
);

/**
* Content handler
*
* @var ContentFilter
*/
protected $contentFilter;

/**
* Sets the content filter
*
Expand All @@ -39,7 +43,7 @@ public function setContentFilter(ContentFilter $contentFilter)
{
$this->contentFilter = $contentFilter;
}

/**
* Evaluates the result of the given callback
*
Expand Down Expand Up @@ -163,7 +167,7 @@ public function allchanges()
$rss->setTemplate('Page_allchanges_rss');
return $rss->outputToBrowser();
}

/**
* Generates and embeds the RSS header link for the page-specific version rss feed
*/
Expand All @@ -172,7 +176,7 @@ public function linkToPageRSSFeed()
if (!Config::inst()->get(VersionFeed::class, 'changes_enabled') || !$this->owner->PublicHistory) {
return;
}

RSSFeed::linkToFeed(
$this->owner->Link('changes'),
_t(
Expand All @@ -193,7 +197,7 @@ public function linkToAllSiteRSSFeed()
) {
return;
}

// RSS feed to all-site changes.
$title = Convert::raw2xml($this->linkToAllSitesRSSFeedTitle());
$url = $this->owner->getSiteRSSLink();
Expand Down
6 changes: 4 additions & 2 deletions src/VersionFeedSiteConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\DataExtension;
use SilverStripe\SiteConfig\SiteConfig;

/**
* Allows global configuration of all changes
*
* @extends DataExtension<SiteConfig>
*/
class VersionFeedSiteConfig extends DataExtension
{

private static $db = array(
'AllChangesEnabled' => 'Boolean(true)'
);
Expand All @@ -26,7 +28,7 @@ public function updateFieldLabels(&$labels)
{
$labels['AllChangesEnabled'] = _t(__CLASS__ . '.ALLCHANGESLABEL', 'Make global changes feed public');
}

public function updateCMSFields(FieldList $fields)
{
if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')) {
Expand Down

0 comments on commit b7b4ff8

Please sign in to comment.