1 <?php
2 3 4 5 6 7 8
9 class PhotoGalleryWidget extends SidebarWidget {
10
11 static $has_one = array(
12 'Holder' => 'PhotoGalleryPage'
13 );
14
15 public $needObjects = array(
16 'PhotoGalleryPage' => 'Page'
17 );
18
19 function getCMSFields() {
20 if (!$this->canCreate()) {
21 return $this->getFailCMSFields();
22 }
23
24 $fields = parent::getCMSFields();
25 $holders = DataObject::get('PhotoGalleryPage');
26 if ($holders) {
27 $holders = $holders->map();
28 } else {
29 $holders = array();
30 }
31 $fields->replaceField('HolderID', new DropdownField('HolderID', $this->fieldLabel('Holder'), $holders, "", null, _t('Widgets.All', 'All')));
32
33 return $fields;
34 }
35
36 function Photos() {
37 if ($this->HolderID && $this->Holder()) {
38 $holder = $this->Holder();
39 } else {
40 $holder = DataObject::get_one('PhotoGalleryPage');
41 }
42 if ($holder) {
43 return PhotoAlbumPage::get_photos(1, $holder->ID);
44 }
45 return false;
46 }
47
48 function hasContent() {
49 if ($this->Photos()) {
50 return true;
51 }
52 return false;
53 }
54
55 function getMoreLink() {
56 if ($this->HolderID && $this->Holder()) {
57 return $this->Holder()->Link();
58 }
59 if ($photos = $this->Photos()) {
60 return $photos->First()->Album()->Link();
61 }
62 return false;
63 }
64 }
65
66
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-