Source of file BootstrapCard.php
Size: 3,176 Bytes - Last Modified: 2021-12-23T10:50:32+00:00
/var/www/docs.ssmods.com/process/src/src/Elements/BootstrapCard.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 | <?php namespace Syntro\SilverstripeElementalBootstrap\Elements; use SilverStripe\Forms\FieldList; use SilverStripe\AssetAdmin\Forms\UploadField; use SilverStripe\Assets\Image; use SilverStripe\ORM\FieldType\DBField; use Syntro\SilverstripeElementalBootstrap\Elements\BootstrapElement; use Syntro\SilverstripeElementalBootstrap\Controllers\BootstrapElementController; /** * A simple Card, containing images on top or bottom, a title and a body. * @author Matthias Leutenegger */ class BootstrapCard extends BootstrapElement { private static $icon = 'font-icon-block-banner'; private static $table_name = 'Syntro_Elemental_BootstrapCard'; private static $title = 'Card'; private static $singular_name = 'Card'; private static $plural_name = 'Cards'; private static $description = 'A simple Card with an image, title and body.'; /** * @var string */ private static $controller_class = BootstrapElementController::class; /** * Database fields * * @var array */ private static $db = [ 'Title' => 'Varchar', 'Body' => 'HTMLText' ]; /** * Has_one relationship * * @var array */ private static $has_one = [ 'CardImageTop' => Image::class, 'CardImageBottom' => Image::class, ]; /** * getCMSFields - return fields for fieldlist * * @return FieldList */ public function getCMSFields() { $this->beforeUpdateCMSFields( function (FieldList $fields) { $fields->addFieldToTab( 'Root.Main', UploadField::create( 'CardImageTop', 'Card Image Top' ) ->setIsMultiUpload(false), 'Title' ); $fields->addFieldToTab( 'Root.Main', UploadField::create( 'CardImageBottom', 'Card Image Bottom' ) ->setIsMultiUpload(false) ); } ); return parent::getCMSFields(); } /** * getType - get the translated name * * @return string */ public function getType() { return _t(__CLASS__ . '.BlockType', 'Card'); } /** * Return file title and thumbnail for summary section of ElementEditor * * @return array */ protected function provideBlockSchema() { $blockSchema = parent::provideBlockSchema(); /** @var Image|null */ $image = $this->CardImageTop(); if ($image && $image->exists() && $image->getIsImage()) { $blockSchema['fileURL'] = $image->CMSThumbnail()->getURL(); $blockSchema['fileTitle'] = $image->getTitle(); } $blockSchema['content'] = $this->getSummary(); return $blockSchema; } /** * Return a Summary string * * @return null|string */ public function getSummary() { return DBField::create_field('HTMLText', $this->Body)->Summary(20); } } |