Source of file ElementPersons.php
Size: 4,430 Bytes - Last Modified: 2021-12-24T05:19:58+00:00
/var/www/docs.ssmods.com/process/src/src/Model/ElementPersons.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 | <?php namespace Jellygnite\Elements\Model; use DNADesign\Elemental\Models\BaseElement; use Jellygnite\Elements\Controllers\CustomElementController; use Jellygnite\Elements\Model\PersonObject; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\ORM\FieldType\DBHTMLText; use SilverStripe\Versioned\GridFieldArchiveAction; use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; use Symbiote\GridFieldExtensions\GridFieldOrderableRows; /** * Class ElementPersons * * @property string $Content * * @method \SilverStripe\ORM\ManyManyList Persons() */ class ElementPersons extends BaseElement { private static $cascade_duplicates = false; /** * @var string */ private static $icon = 'font-icon-block-users'; /** * @return string */ private static $singular_name = 'Persons Element'; /** * @return string */ private static $plural_name = 'Persons Elements'; /** * @var string */ private static $table_name = 'ElementPersons'; /** * @var array */ private static $styles = []; // allows us to store templates in this module folder private static $controller_class = CustomElementController::class; /** * @var array */ private static $db = [ 'Content' => 'HTMLText' ]; /** * @var array */ private static $many_many = array( 'Persons' => PersonObject::class, ); /** * @var array */ private static $many_many_extraFields = array( 'Persons' => array( 'SortOrder' => 'Int', ), ); /** * @var array */ private static $owns = [ 'Persons', ]; /** * Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be * clickable and a GridFieldDetailForm will be used. * * @config * @var bool */ private static $inline_editable = false; private static $defaults = array ( 'ShowTitle' => '1' ); /** * @param bool $includerelations * @return array */ public function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); $labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Intro'); $labels['Persons'] = _t(__CLASS__ . '.PersonsLabel', 'Persons'); return $labels; } /** * @return FieldList */ public function getCMSFields() { $this->beforeUpdateCMSFields(function (FieldList $fields) { $fields->dataFieldByName('Content') ->setRows(5); if ($this->ID) { /** @var \SilverStripe\Forms\GridField\GridField $PersonField */ $personField = $fields->dataFieldByName('Persons'); $fields->removeByName('Persons'); $config = $personField->getConfig(); $config->removeComponentsByType([ GridFieldAddExistingAutocompleter::class, GridFieldDeleteAction::class, GridFieldArchiveAction::class, ])->addComponents( new GridFieldOrderableRows('SortOrder'), new GridFieldAddExistingSearchButton() ); $fields->addFieldsToTab('Root.Main', array( $personField, )); } }); return parent::getCMSFields(); } /** * @return mixed */ public function getPersonList() { return $this->Persons()->sort('SortOrder'); } /** * @return DBHTMLText */ public function getSummary() { if ($this->Persons()->count() == 1) { $label = ' person'; } else { $label = ' persons'; } return DBField::create_field('HTMLText', $this->Persons()->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', 'Persons'); } } |