Frank Mullenger
Contact Me
Blog
Ecommerce Module
- SilverStripe framework >3.1.2
- SilverStripe cms >3.1.2
1.1
Very simple gallery solution to upload images and display them in a basic gallery using Fancybox.
A gallery can be added to any page type, GalleryPage is shipped with this module as an example.
Uses customised UploadField to manage the images, allowing bulk upload of images then resorting using drag drop and editing of captions inline.
You are required to purchase a licence for Fancybox for commercial websites. Fancy box can be replaced easily for each page type you apply the gallery to.
composer require frankmullenger/gallery 1.0.*@dev
- Visit yoursite.com/dev/build?flush=1 to rebuild the database (you may need to do this twice).
- Place this directory in the root of your SilverStripe installation, rename the folder 'gallery'.
- Visit yoursite.com/dev/build?flush=1 to rebuild the database (you may need to do this twice).
- Create "Gallery page" in the CMS
- Edit the gallery page and go to "Gallery" tab
- Drag images into the "Drop" area
- Edit caption for images
- Drag and drop images to re-order them
You can make any page type a gallery by applying the extensions in this module to a page type. Using GalleryPage as an example:
Including Javascript in your controller to display the images in your gallery and a DataObject representing the join table. Because we are applying an extension with a many_many Images component you will need a DataObject {PageType}_Images to represent the join. This object requires Caption and SortOrder fields.
<?php
class GalleryPage extends Page {
}
class GalleryPage_Controller extends Page_Controller {
public function init() {
parent::init();
Requirements::javascript('gallery/javascript/jquery-1.7.1.min.js');
Requirements::javascript('gallery/javascript/jquery.fancybox.js');
Requirements::javascript('gallery/javascript/GalleryPage.js');
Requirements::css('gallery/css/jquery.fancybox.css');
}
}
class GalleryPage_Images extends DataObject {
static $db = array (
'PageID' => 'Int',
'ImageID' => 'Int',
'Caption' => 'Text',
'SortOrder' => 'Int'
);
}
You may need to run /dev/build twice during this process to ensure the join object is created correctly.
Using the GalleryPage.ss layout template as an example, loop through the ordered images and display them with necessary markup for your lightbox Javascript.
<% loop OrderedImages %>
<a class="fancybox" data-fancybox-group="gallery" href="$Filename" title="$Caption">
$SetSize(250,250)
</a>
<% end_loop %>
Apply the extension to the page type in a config yaml file:
GalleryPage:
extensions:
- 'Gallery_PageExtension'
This extension uses:
Copyright (c) 2013, [Frank Mullenger](http://nz.linkedin.com/in/frankmullenger)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of SilverStripe nor the names of its contributors may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.