-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstracted Photo Gallery Features to an Extension
- Loading branch information
1 parent
13e192c
commit 63ecdda
Showing
4 changed files
with
63 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
LeftAndMain: | ||
extra_requirements_css: | ||
- basic-galleries/css/cms.css | ||
- basic-galleries/css/cms.css | ||
PhotoGalleryPage: | ||
extensions: | ||
- PhotoGalleryExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
class PhotoGalleryExtension extends DataExtension { | ||
|
||
// One gallery page has many gallery images | ||
private static $has_many = array( | ||
'PhotoGalleryImages' => 'PhotoGalleryImage' | ||
); | ||
|
||
public function updateCMSFields(FieldList $fields) { | ||
|
||
$gridFieldConfig = GridFieldConfig_RecordEditor::create(); | ||
$gridFieldConfig->addComponent(new GridFieldBulkUpload()); | ||
$gridFieldConfig->addComponent(new GridFieldGalleryTheme('Image')); | ||
$bulkUpload = $gridFieldConfig->getComponentByType('GridFieldBulkUpload'); | ||
$bulkUpload->setUfSetup('setFolderName', "Managed/PhotoGalleries/".$this->owner->ID."-".$this->owner->URLSegment); | ||
$bulkUpload->setUfConfig('canAttachExisting',false); | ||
$bulkUpload->setUfConfig('canPreviewFolder',false); | ||
|
||
$gridFieldConfig->removeComponentsByType('GridFieldPaginator'); | ||
$gridFieldConfig->addComponent(new GridFieldSortableRows('SortOrder')); | ||
$gridFieldConfig->addComponent(new GridFieldPaginator(100)); | ||
$gridFieldConfig->removeComponentsByType('GridFieldAddNewButton'); | ||
|
||
$gridfield = new GridField("PhotoGalleryImages", "Image Gallery", $this->owner->PhotoGalleryImages()->sort("SortOrder"), $gridFieldConfig); | ||
$fields->addFieldToTab('Root.ImageGallery', $gridfield); | ||
|
||
$fields->addFieldToTab('Root.ImageGallery', new LiteralField('help'," | ||
<h2>To upload new images:</h2> | ||
<ol> | ||
<li>1. Click the <strong>From your computer</strong> button above.</li> | ||
<li>2. <strong>Locate and select</strong> the image(s) you wish to upload.</li> | ||
<li>3. Click on <strong>Open/Choose</strong> and the image(s) will begin to upload.</li> | ||
<li>4. Click <strong>Finish</strong>.</li> | ||
</ol>")); | ||
|
||
$fields->renameField("Content", "Top Content"); | ||
|
||
return $fields; | ||
|
||
} | ||
|
||
public function GetGalleryImages() { | ||
return $this->owner->PhotoGalleryImages()->sort("SortOrder"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters