-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW Move code from silverstripe/sitewidecontent-report
- Loading branch information
1 parent
3a49f94
commit 136fa79
Showing
10 changed files
with
669 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
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,8 @@ | ||
--- | ||
Name: reports-sitewidecontenttaxonomy | ||
Only: | ||
moduleexists: silverstripe/taxonomy | ||
--- | ||
SilverStripe\Reports\SiteWideContentReport\SitewideContentReport: | ||
extensions: | ||
- SilverStripe\Reports\SiteWideContentReport\Model\SitewideContentTaxonomy |
24 changes: 24 additions & 0 deletions
24
code/SiteWideContentReport/Form/GridFieldBasicContentReport.php
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,24 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Reports\SiteWideContentReport\Form; | ||
|
||
use SilverStripe\Forms\GridField\GridField; | ||
use SilverStripe\ORM\DataObject; | ||
|
||
class GridFieldBasicContentReport extends GridField | ||
{ | ||
/** | ||
* @param int $total | ||
* @param int $index | ||
* @param DataObject $record | ||
* | ||
* @return array | ||
*/ | ||
protected function getRowAttributes($total, $index, $record) | ||
{ | ||
$attributes = parent::getRowAttributes($total, $index, $record); | ||
$this->extend('updateRowAttributes', $total, $index, $record, $attributes); | ||
|
||
return $attributes; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
code/SiteWideContentReport/Model/SitewideContentTaxonomy.php
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,76 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Reports\SiteWideContentReport\Model; | ||
|
||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Core\Extension; | ||
use SilverStripe\Reports\SiteWideContentReport\SitewideContentReport; | ||
use SilverStripe\Taxonomy\TaxonomyTerm; | ||
|
||
/** | ||
* Provides taxonomy integration for sitewide content report. | ||
* | ||
* @extends Extension<SitewideContentReport> | ||
*/ | ||
class SitewideContentTaxonomy extends Extension | ||
{ | ||
/** | ||
* Name of field to get tags from. | ||
* | ||
* @config | ||
* | ||
* @var string | ||
*/ | ||
private static $tag_field = 'Terms'; | ||
|
||
/** | ||
* Update columns to include taxonomy details. | ||
* | ||
* @param string $itemType (i.e 'Pages' or 'Files') | ||
* @param array $columns Columns | ||
*/ | ||
protected function updateColumns($itemType, &$columns) | ||
{ | ||
if ($itemType !== 'Pages') { | ||
return; | ||
} | ||
|
||
// Check if pages has the tags field | ||
if (!SitewideContentTaxonomy::enabled()) { | ||
return; | ||
} | ||
|
||
// Set column | ||
$field = Config::inst()->get(__CLASS__, 'tag_field'); | ||
$columns['Terms'] = [ | ||
'printonly' => true, // Hide on page report | ||
'title' => _t('SilverStripe\\SiteWideContentReport\\SitewideContentReport.Tags', 'Tags'), | ||
'datasource' => function ($record) use ($field) { | ||
if ($record->hasMethod($field)) { | ||
$tags = $record->$field()->column('Name'); | ||
|
||
return implode(', ', $tags); | ||
} | ||
|
||
return ''; | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* Check if this field is enabled. | ||
* | ||
* @return bool | ||
*/ | ||
public static function enabled() | ||
{ | ||
if (!class_exists(TaxonomyTerm::class)) { | ||
return false; | ||
} | ||
|
||
// Check if pages has the tags field | ||
$field = Config::inst()->get(__CLASS__, 'tag_field'); | ||
|
||
return singleton('Page')->hasMethod($field); | ||
} | ||
} |
Oops, something went wrong.