Source of file ElementStatCounters.php
Size: 2,569 Bytes - Last Modified: 2021-12-24T06:46:03+00:00
/var/www/docs.ssmods.com/process/src/src/Elements/ElementStatCounters.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 | <?php namespace Dynamic\Elements\StatCounters\Elements; use DNADesign\Elemental\Models\BaseElement; use Dynamic\Elements\StatCounters\Model\StatCounter; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldDeleteAction; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBHTMLText; /** * Class ElementStatCounters * @package Dynamic\Elements\StatCounters\Elements */ class ElementStatCounters extends BaseElement { /** * @var string */ //private static $icon = 'font-icon-block-banner'; /** * @return string */ private static $singular_name = 'Stat Counters Element'; /** * @return string */ private static $plural_name = 'Stat Counters Elements'; /** * @var array */ private static $has_many = [ 'Stats' => StatCounter::class, ]; /** * @var string */ private static $table_name = 'ElementStatCounters'; /** * @var bool */ private static $inline_editable = false; /** * @return FieldList */ public function getCMSFields() { $this->beforeUpdateCMSFields(function (FieldList $fields) { if ($stats = $fields->dataFieldByName('Stats')) { $fields->removeByName('Stats'); $config = $stats->getConfig(); $config-> removeComponentsByType([ GridFieldAddExistingAutocompleter::class, GridFieldDeleteAction::class, ]) ->addComponents([ new GridFieldDeleteAction(false), ]); $fields->addFieldToTab('Root.Main', $stats); } }); return parent::getCMSFields(); } /** * @return DBHTMLText */ public function getSummary() { if ($this->Stats()->count() == 1) { $label = ' stat'; } else { $label = ' stats'; } return DBField::create_field('HTMLText', $this->Stats()->count() . $label)->Summary(20); } /** * @return array */ protected function provideBlockSchema() { $blockSchema = parent::provideBlockSchema(); $blockSchema['content'] = $this->getSummary(); return $blockSchema; } /** * @return string */ public function getType() { return _t(__CLASS__.'.BlockType', 'Stat Counters'); } } |