Source of file SitewideContentTaxonomy.php
Size: 1,859 Bytes - Last Modified: 2021-12-23T10:34:31+00:00
/var/www/docs.ssmods.com/process/src/src/Model/SitewideContentTaxonomy.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php namespace SilverStripe\SiteWideContentReport\Model; use SilverStripe\Core\Config\Config; use SilverStripe\Core\Extension; use SilverStripe\Taxonomy\TaxonomyTerm; /** * Provides taxonomy integration for sitewide content report. * * Requires https://github.com/silverstripe-labs/silverstripe-taxonomy * * Class SitewideContentTaxonomy * @package SilverStripe\SiteWideContentReport\Model */ 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 */ public function updateColumns($itemType, &$columns) { if ($itemType !== 'Pages') { return; } // Check if pages has the tags field if (!self::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) { $tags = $record->$field()->column('Name'); return implode(', ', $tags); }, ]; } /** * 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); } } |