Source of file TestimonialWidget.php
Size: 1,215 Bytes - Last Modified: 2021-12-24T05:17:01+00:00
/var/www/docs.ssmods.com/process/src/src/model/TestimonialWidget.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344 | <?php namespace ilateral\SilverStripe\Testimonials\Model; use SilverStripe\Forms\DropdownField; use SilverStripe\Widgets\Model\Widget; use ilateral\SilverStripe\Testimonials\Model\Testimonial; use ilateral\SilverStripe\Testimonials\Model\TestimonialsHolderPage; if (!class_exists(Widget::class)) { return; } class TestimonialWidget extends Widget { private static $title = "Testimonial"; private static $cmsTitle = "Testimonial"; private static $description = "Displays a random testimonial from the database"; private static $table_name = "TestimonialWidget"; private static $has_one = array( 'Page' => TestimonialsHolderPage::class ); protected $testimonial; function getTestimonial(){ if(!$this->testimonial){ $this->testimonial = Testimonial::get()->sort("RAND()")->first(); } return $this->testimonial; } function getCMSFields(){ $fields = parent::getCMSFields(); $fields->push( DropdownField::create("PageID","Testimonials Holder Page", TestimonialsHolderPage::get()->map()->toArray() )->setHasEmptyDefault(true) ); return $fields; } } |