Skip to content

Commit

Permalink
Make use Lumberjack ability to specify children
Browse files Browse the repository at this point in the history
  • Loading branch information
purplespider committed Nov 10, 2016
1 parent 5d07904 commit aab733a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 26 deletions.
22 changes: 0 additions & 22 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@ Designed to provide a simple, fool-proof way for users to add news articles to t

This module has been designed to have just the minimum required features, to avoid bloat, but can be easily extended to add new fields if required.

## IMPORTANT ##

The master branch has been updated to require [micmania1's Lumberjack module](https://github.com/micmania1/silverstripe-lumberjack), which moves the list of news articles from the sitetree to a gridfield.

However, there are a couple of tweaks required to Lumberjack in order for the best "News" experience. I've opened pull requests, but until they are accepted you can use my Lumberjack fork:

Just add the following to your composer.json file:
````
"repositories": [
{
"type": "vcs",
"url": "https://github.com/purplespider/silverstripe-lumberjack"
}
]
````

And to `require` add:
`"micmania1/silverstripe-lumberjack": "1.0.1a"`

If you don't wish to use this version, you can use the basic-news version 1.0.0 which doesn't use Lumberjack:
`"purplespider/basic-news": "1.0.*"`

## Maintainer Contact ##
* James Cocker ([email protected])

Expand Down
4 changes: 1 addition & 3 deletions _config/config.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
NewsHolder:
extensions:
- 'Lumberjack'
child_classname: NewsArticle

- 'CustomLumberjack'
NewsArticle:
show_in_sitetree: false
27 changes: 27 additions & 0 deletions code/CustomLumberjack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
class CustomLumberjack extends Lumberjack {

/**
* This is responsible for adding the child pages tab and gridfield.
* CUSTOM: Customised to make the GridField tab first.
*
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields) {
$excluded = $this->owner->getExcludedSiteTreeClassNames();
if(!empty($excluded)) {
$pages = $this->getLumberjackPagesForGridfield($excluded);
$gridField = new GridField(
"ChildPages",
$this->getLumberjackTitle(),
$pages,
$this->getLumberjackGridFieldConfig()
);

$tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField);
// $fields->insertAfter($tab, 'Main');
$fields->insertBefore($tab, 'Main'); // Only modified line
}
}

}
8 changes: 8 additions & 0 deletions code/NewsHolder.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function getLumberjackTitle()
{
return "News Articles";
}

public function getLumberjackPagesForGridfield($excluded = array())
{
return NewsArticle::get()->filter(array(
'ParentID' => $this->ID,
'ClassName' => $excluded,
));
}

// Only allows certain children to be created
private static $allowed_children = array('NewsArticle');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"require": {
"silverstripe/framework": "~3.1",
"silverstripe/cms": "~3.1",
"micmania1/silverstripe-lumberjack": "1.0.*"
"silverstripe/lumberjack": "dev-master"
},
"replace": {"silverstripe/basic-news": "*"}
}

0 comments on commit aab733a

Please sign in to comment.