|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\SiteWideContentReport\Model; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Config\Config; |
|
6
|
|
|
use SilverStripe\Core\Extension; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Provides taxonomy integration for sitewide content report. |
|
10
|
|
|
* |
|
11
|
|
|
* Requires https://github.com/silverstripe-labs/silverstripe-taxonomy |
|
12
|
|
|
* |
|
13
|
|
|
* Class SitewideContentTaxonomy |
|
14
|
|
|
* @package SilverStripe\SiteWideContentReport\Model |
|
15
|
|
|
*/ |
|
16
|
|
|
class SitewideContentTaxonomy extends Extension |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Name of field to get tags from. |
|
20
|
|
|
* |
|
21
|
|
|
* @config |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private static $tag_field = 'Terms'; |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Update columns to include taxonomy details. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $itemType (i.e 'Pages' or 'Files') |
|
31
|
|
|
* @param array $columns Columns |
|
32
|
|
|
*/ |
|
33
|
|
|
public function updateColumns($itemType, &$columns) |
|
34
|
|
|
{ |
|
35
|
|
|
if ($itemType !== 'Pages') { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
// Check if pages has the tags field |
|
40
|
|
|
if (!self::enabled()) { |
|
41
|
|
|
return; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// Set column |
|
45
|
|
|
$field = Config::inst()->get(__CLASS__, 'tag_field'); |
|
46
|
|
|
$columns['Terms'] = [ |
|
47
|
|
|
'printonly' => true, // Hide on page report |
|
48
|
|
|
'title' => _t('SitewideContentReport.Tags', 'Tags'), |
|
49
|
|
|
'datasource' => function ($record) use ($field) { |
|
50
|
|
|
$tags = $record->$field()->column('Name'); |
|
51
|
|
|
|
|
52
|
|
|
return implode(', ', $tags); |
|
53
|
|
|
}, |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Check if this field is enabled. |
|
59
|
|
|
* |
|
60
|
|
|
* @return bool |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function enabled() |
|
63
|
|
|
{ |
|
64
|
|
|
if (!class_exists('TaxonomyTerm')) { |
|
65
|
|
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// Check if pages has the tags field |
|
69
|
|
|
$field = Config::inst()->get(__CLASS__, 'tag_field'); |
|
70
|
|
|
|
|
71
|
|
|
return singleton('Page')->hasMethod($field); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|