mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 17:05:54 +02:00
SS4 compat: Update readme, docs, composer configuration and Travis build configuration
This commit is contained in:
parent
f3b14df4e4
commit
defb4bf134
@ -6,4 +6,4 @@ checks:
|
||||
duplication: true
|
||||
|
||||
filter:
|
||||
paths: [code/*, tests/*]
|
||||
paths: [src/*, tests/*]
|
||||
|
15
.travis.yml
15
.travis.yml
@ -1,31 +1,28 @@
|
||||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
|
||||
# See https://github.com/silverstripe/silverstripe-travis-support for setup details
|
||||
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
|
||||
env:
|
||||
- DB=MYSQL CORE_RELEASE=3.2
|
||||
- DB=MYSQL CORE_RELEASE=master
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=MYSQL CORE_RELEASE=3
|
||||
env: DB=MYSQL CORE_RELEASE=master
|
||||
- php: 5.6
|
||||
env: DB=PGSQL CORE_RELEASE=3.2
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
env: DB=PGSQL CORE_RELEASE=master
|
||||
|
||||
before_script:
|
||||
- composer self-update || true
|
||||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
|
||||
- git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
- composer install
|
||||
|
230
README.md
230
README.md
@ -1,6 +1,6 @@
|
||||
# Widgets Module
|
||||
|
||||
[![Build Status](https://secure.travis-ci.org/silverstripe/silverstripe-widgets.png?branch=1.1)](http://travis-ci.org/silverstripe/silverstripe-widgets)
|
||||
[![Build Status](https://secure.travis-ci.org/silverstripe/silverstripe-widgets.png?branch=master)](http://travis-ci.org/silverstripe/silverstripe-widgets)
|
||||
|
||||
## Overview
|
||||
|
||||
@ -9,7 +9,7 @@ the sidebar of your website.
|
||||
|
||||
## Requirements
|
||||
|
||||
* SilverStripe 3.2
|
||||
* SilverStripe 4.0
|
||||
|
||||
|
||||
### Installation
|
||||
@ -55,18 +55,28 @@ e.g.
|
||||
|
||||
**mysite/code/Page.php**
|
||||
|
||||
class Page extends SiteTree {
|
||||
...
|
||||
```php
|
||||
<?php
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Widgets\Form\WidgetAreaEditor;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
class Page extends SiteTree
|
||||
{
|
||||
// ...
|
||||
private static $has_one = array(
|
||||
"MyWidgetArea" => "WidgetArea",
|
||||
'MyWidgetArea' => WidgetArea::class
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("MyWidgetArea"));
|
||||
$fields->addFieldToTab('Root.Widgets', new WidgetAreaEditor('MyWidgetArea'));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case, you need to alter your templates to include the `$MyWidgetArea` placeholder.
|
||||
|
||||
@ -94,33 +104,47 @@ An example widget is below:
|
||||
|
||||
**FlickrWidget.php**
|
||||
|
||||
:::php
|
||||
```php
|
||||
<?php
|
||||
class FlickrWidget extends Widget {
|
||||
private static $db = array(
|
||||
"User" => "Varchar",
|
||||
"Photoset" => "Varchar",
|
||||
"Tags" => "Varchar",
|
||||
"NumberToShow" => "Int"
|
||||
);
|
||||
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
use FlickrService;
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
class FlickrWidget extends Widget
|
||||
{
|
||||
private static $db = array(
|
||||
'User' => 'Varchar',
|
||||
'Photoset' => 'Varchar',
|
||||
'Tags' => 'Varchar',
|
||||
'NumberToShow' => 'Int'
|
||||
);
|
||||
|
||||
private static $defaults = array(
|
||||
"NumberToShow" => 8
|
||||
'NumberToShow' => 8
|
||||
);
|
||||
|
||||
private static $title = "Photos";
|
||||
private static $cmsTitle = "Flickr Photos";
|
||||
private static $description = "Shows flickr photos.";
|
||||
private static $title = 'Photos';
|
||||
private static $cmsTitle = 'Flickr Photos';
|
||||
private static $description = 'Shows flickr photos.';
|
||||
|
||||
public function Photos() {
|
||||
Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js");
|
||||
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/effects.js");
|
||||
Requirements::javascript("mashups/javascript/lightbox.js");
|
||||
Requirements::css("mashups/css/lightbox.css");
|
||||
public function Photos()
|
||||
{
|
||||
// You'll need to install these yourself
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/prototype/prototype.js');
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
|
||||
Requirements::javascript('mashups/javascript/lightbox.js');
|
||||
Requirements::css('mashups/css/lightbox.css');
|
||||
|
||||
$flickr = new FlickrService();
|
||||
if($this->Photoset == "") {
|
||||
if ($this->Photoset == '') {
|
||||
$photos = $flickr->getPhotos($this->Tags, $this->User, $this->NumberToShow, 1);
|
||||
} else {
|
||||
$photos = $flickr->getPhotoSet($this->Photoset, $this->User, $this->NumberToShow, 1);
|
||||
@ -128,37 +152,43 @@ An example widget is below:
|
||||
|
||||
$output = new ArrayList();
|
||||
foreach ($photos->PhotoItems as $photo) {
|
||||
$output->push(new ArrayData(array(
|
||||
"Title" => $photo->title,
|
||||
"Link" => "http://farm1.static.flickr.com/" . $photo->image_path .".jpg",
|
||||
"Image" => "http://farm1.static.flickr.com/" .$photo->image_path. "_s.jpg"
|
||||
)));
|
||||
$output->push(
|
||||
new ArrayData(
|
||||
array(
|
||||
'Title' => $photo->title,
|
||||
'Link' => 'http://farm1.static.flickr.com/' . $photo->image_path .'.jpg',
|
||||
'Image' => 'http://farm1.static.flickr.com/' .$photo->image_path. '_s.jpg'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
return new FieldList(
|
||||
new TextField("User", "User"),
|
||||
new TextField("PhotoSet", "Photo Set"),
|
||||
new TextField("Tags", "Tags"),
|
||||
new NumericField("NumberToShow", "Number to Show")
|
||||
new TextField('User', 'User'),
|
||||
new TextField('PhotoSet', 'Photo Set'),
|
||||
new TextField('Tags', 'Tags'),
|
||||
new NumericField('NumberToShow', 'Number to Show')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**FlickrWidget.ss**
|
||||
|
||||
:::ss
|
||||
```
|
||||
<% control Photos %>
|
||||
<a href="$Link" rel="lightbox" title="$Title"><img src="$Image" alt="$Title" /></a>
|
||||
<% end_control %>
|
||||
```
|
||||
|
||||
|
||||
## Releasing a widget
|
||||
|
||||
Follow the [standard procedures defined for releasing a SilverStripe module](http://doc.silverstripe.org/framework/en/3.1/topics/module-development).
|
||||
Follow the [standard procedures defined for releasing a SilverStripe module](https://docs.silverstripe.org/en/4/developer_guides/extending/how_tos/publish_a_module).
|
||||
|
||||
Here is a composer template you can use.
|
||||
|
||||
@ -178,8 +208,8 @@ You need to finish off / change:
|
||||
"type": "silverstripe-module",
|
||||
"keywords" : ["widget"],
|
||||
"require": {
|
||||
"silverstripe/framework": "3.*",
|
||||
"silverstripe/cms": "3.*"
|
||||
"silverstripe/framework": "^4.0",
|
||||
"silverstripe/cms": "^4.0"
|
||||
},
|
||||
"license": "BSD-2-Clause",
|
||||
"authors": [
|
||||
@ -190,6 +220,11 @@ You need to finish off / change:
|
||||
],
|
||||
"extra" : {
|
||||
"installer-name": "widgets_"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yourname\\MyWidget\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -203,27 +238,30 @@ define a merge variable in the Page Controller and include it in the Page Templa
|
||||
|
||||
This example creates an RSSWidget with the SilverStripe blog feed.
|
||||
|
||||
:::php
|
||||
public function SilverStripeFeed() {
|
||||
```php
|
||||
public function SilverStripeFeed()
|
||||
{
|
||||
$widget = new RSSWidget();
|
||||
$widget->RssUrl = "http://feeds.feedburner.com/silverstripe-blog";
|
||||
return $widget->renderWith("WidgetHolder");
|
||||
$widget->RssUrl = 'http://feeds.feedburner.com/silverstripe-blog';
|
||||
return $widget->renderWith('WidgetHolder');
|
||||
}
|
||||
```
|
||||
|
||||
To render the widget, simply include $SilverStripeFeed in your template:
|
||||
To render the widget, simply include `$SilverStripeFeed` in your template:
|
||||
|
||||
```
|
||||
$SilverStripeFeed
|
||||
```
|
||||
|
||||
As directed in the definition of `SilverStripeFeed()`, the Widget will be rendered through the WidgetHolder template. This
|
||||
is pre-defined at `widgets/templates/WidgetHolder.ss` and simply consists of:
|
||||
|
||||
As directed in the definition of SilverStripeFeed(), the Widget will be rendered through the WidgetHolder template. This
|
||||
is pre-defined at `framework/templates/WidgetHolder.ss` and simply consists of:
|
||||
|
||||
:::ss
|
||||
```
|
||||
<div class="WidgetHolder">
|
||||
<h3>$Title</h3>
|
||||
$Content
|
||||
</div>
|
||||
|
||||
```
|
||||
|
||||
You can override the WidgetHolder.ss and Widget.ss templates in your theme too by adding WidgetHolder and Widget
|
||||
templates to `themes/myThemeName/templates/Includes/`
|
||||
@ -233,25 +271,27 @@ templates to `themes/myThemeName/templates/Includes/`
|
||||
To change the title of your widget, you need to override the Title() method. By default, this simply returns the $title
|
||||
variable. For example, to set your widgets title to 'Hello World!', you could use:
|
||||
|
||||
**widgets_yourWidget/YourWidgetWidget.php**
|
||||
**widgets_yourWidget/src/YourWidgetWidget.php**
|
||||
|
||||
:::php
|
||||
public function Title() {
|
||||
return "Hello World!";
|
||||
```php
|
||||
public function Title()
|
||||
{
|
||||
return 'Hello World!';
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
but, you can do exactly the same by setting your $title variable.
|
||||
but, you can do exactly the same by setting your `$title` variable.
|
||||
|
||||
A more common reason for overriding Title() is to allow the title to be set in the CMS. Say you had a text field in your
|
||||
widget called WidgetTitle, that you wish to use as your title. If nothing is set, then you'll use your default title.
|
||||
This is similar to the RSS Widget in the blog module.
|
||||
|
||||
:::php
|
||||
public function Title() {
|
||||
```php
|
||||
public function Title()
|
||||
{
|
||||
return $this->WidgetTitle ? $this->WidgetTitle : self::$title;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
This returns the value inputted in the CMS, if it's set or what is in the $title variable if it isn't.
|
||||
|
||||
@ -263,15 +303,36 @@ sure that your controller follows the usual naming conventions, and it will be a
|
||||
|
||||
**mysite/code/MyWidget.php**
|
||||
|
||||
:::php
|
||||
class MyWidget extends Widget {
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
class MyWidget extends Widget
|
||||
{
|
||||
private static $db = array(
|
||||
'TestValue' => 'Text'
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
class MyWidget_Controller extends WidgetController {
|
||||
public function MyFormName() {
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
use SilverStripe\Widgets\Controllers\WidgetController;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\TextField;
|
||||
|
||||
class MyWidgetController extends WidgetController
|
||||
{
|
||||
public function MyFormName()
|
||||
{
|
||||
return new Form(
|
||||
$this,
|
||||
'MyFormName',
|
||||
@ -284,48 +345,55 @@ sure that your controller follows the usual naming conventions, and it will be a
|
||||
);
|
||||
}
|
||||
|
||||
public function doAction($data, $form) {
|
||||
public function doAction($data, $form)
|
||||
{
|
||||
// $this->widget points to the widget
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
To output this form, modify your widget template.
|
||||
|
||||
**mysite/templates/MyWidget.ss**
|
||||
**mysite/templates/Yourname/MyWidget/MyWidget.ss**
|
||||
|
||||
:::ss
|
||||
```
|
||||
$Content
|
||||
$MyFormName
|
||||
```
|
||||
|
||||
**Note:** The necessary controller actions are only present in subclasses of `Page_Controller`. To use
|
||||
widget forms in other controller subclasses, have a look at *ContentController->handleWidget()* and
|
||||
*ContentController::$url_handlers*.
|
||||
**Note:** The necessary controller actions are only present in subclasses of `PageController`. To use
|
||||
widget forms in other controller subclasses, have a look at `ContentController->handleWidget()` and
|
||||
`ContentController::$url_handlers`.
|
||||
|
||||
## But what if I have widgets on my blog currently??
|
||||
|
||||
**Note:** This applies to old versions of the blog module. The latest version of this module does not contain `BlogHolder.php`.
|
||||
|
||||
If you currently have a blog installed, the widget fields are going to double up on those pages (as the blog extends the
|
||||
Page class). One way to fix this is to comment out line 30 in BlogHolder.php and remove the DB entry by running a
|
||||
Page class). One way to fix this is to comment out line 30 in `BlogHolder.php` and remove the DB entry by running a
|
||||
`http://www.mysite.com/db/build`.
|
||||
|
||||
**blog/code/BlogHolder.php**
|
||||
|
||||
:::php
|
||||
```php
|
||||
<?php
|
||||
class BlogHolder extends Page {
|
||||
|
||||
........
|
||||
class BlogHolder extends Page
|
||||
{
|
||||
// ........
|
||||
static $has_one = array(
|
||||
// "Sidebar" => "WidgetArea", COMMENT OUT
|
||||
'Newsletter' => 'NewsletterType'
|
||||
.......
|
||||
public function getCMSFields() {
|
||||
);
|
||||
// .......
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->removeFieldFromTab("Root.Content","Content");
|
||||
// $fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("Sidebar")); COMMENT OUT
|
||||
|
||||
........
|
||||
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Then you can use the Widget area you defined on Page.php
|
||||
|
||||
@ -339,4 +407,4 @@ and any new translations will be merged back to the project source code.
|
||||
Please use [https://www.transifex.com/projects/p/silverstripe-widgets/](https://www.transifex.com/projects/p/silverstripe-widgets/) to contribute translations,
|
||||
rather than sending pull requests with YAML files.
|
||||
|
||||
See the ["i18n" topic](https://docs.silverstripe.org/en/3.2/developer_guides/i18n/) on doc.silverstripe.org for more details.
|
||||
See the ["i18n" topic](https://docs.silverstripe.org/en/4/developer_guides/i18n/) on doc.silverstripe.org for more details.
|
||||
|
@ -0,0 +1 @@
|
||||
<?php
|
@ -10,12 +10,21 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": "^4",
|
||||
"silverstripe/cms": "^4"
|
||||
"silverstripe/framework": "^4.0@dev",
|
||||
"silverstripe/cms": "^4.0@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "~4.8"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
"dev-master": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SilverStripe\\Widgets\\": "src/",
|
||||
"SilverStripe\\Widgets\\Tests\\": "tests/",
|
||||
}
|
||||
},
|
||||
"license": "BSD-3-Clause"
|
||||
|
@ -4,7 +4,7 @@ Contributions are welcome! Create an issue, explaining a bug or proposal. Submit
|
||||
|
||||
## Releasing a widget
|
||||
|
||||
Follow the [standard procedures defined for releasing a SilverStripe module](http://doc.silverstripe.org/framework/en/3.1/topics/module-development).
|
||||
Follow the [standard procedures defined for releasing a SilverStripe module](https://docs.silverstripe.org/en/4/developer_guides/extending/how_tos/publish_a_module).
|
||||
|
||||
Here is a composer template you can use.
|
||||
|
||||
@ -36,6 +36,11 @@ You need to finish off / change:
|
||||
],
|
||||
"extra" : {
|
||||
"installer-name": "widgets_"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yourname\\MyWidget\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
@ -12,7 +12,9 @@ You'll also need to run `dev/build`.
|
||||
|
||||
Install the module through [composer](http://getcomposer.org):
|
||||
|
||||
composer require silverstripe/widgets
|
||||
```sh
|
||||
$ composer require silverstripe/widgets
|
||||
```
|
||||
|
||||
Widgets are essentially database relations to other models, mostly page types.
|
||||
By default, they're not added to any of your own models. The easiest and most common
|
||||
@ -20,10 +22,11 @@ way to get started would be to create a single collection of widgets under the
|
||||
name "SideBar" on your `Page` class. This is handled by an extension which you
|
||||
can enable through your `config.yml`:
|
||||
|
||||
:::yml
|
||||
```yaml
|
||||
Page:
|
||||
extensions:
|
||||
- WidgetPageExtension
|
||||
```
|
||||
|
||||
Run a `dev/build`, and adjust your templates to include the resulting sidebar view.
|
||||
The placeholder is called `$SideBarView`, and loops through all widgets assigned
|
||||
@ -31,7 +34,7 @@ to the current page.
|
||||
|
||||
Alternatively, you can add one or more widget collections to your own page types.
|
||||
Here's an example on how to just add widgets to a `MyPage` type, and call it
|
||||
`MyWidgetArea` instead.
|
||||
`MyWidgetArea` instead. Please ensure you add the correct namespaces for your module.
|
||||
|
||||
### Installing a widget
|
||||
|
||||
@ -56,18 +59,28 @@ e.g.
|
||||
|
||||
**mysite/code/Page.php**
|
||||
|
||||
class Page extends SiteTree {
|
||||
...
|
||||
```php
|
||||
<?php
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Widgets\Form\WidgetAreaEditor;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
class Page extends SiteTree
|
||||
{
|
||||
// ...
|
||||
private static $has_one = array(
|
||||
"MyWidgetArea" => "WidgetArea",
|
||||
'MyWidgetArea' => WidgetArea::class
|
||||
);
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("MyWidgetArea"));
|
||||
$fields->addFieldToTab('Root.Widgets', new WidgetAreaEditor('MyWidgetArea'));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case, you need to alter your templates to include the `$MyWidgetArea` placeholder.
|
||||
|
||||
@ -95,33 +108,47 @@ An example widget is below:
|
||||
|
||||
**FlickrWidget.php**
|
||||
|
||||
:::php
|
||||
```php
|
||||
<?php
|
||||
class FlickrWidget extends Widget {
|
||||
private static $db = array(
|
||||
"User" => "Varchar",
|
||||
"Photoset" => "Varchar",
|
||||
"Tags" => "Varchar",
|
||||
"NumberToShow" => "Int"
|
||||
);
|
||||
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
use FlickrService;
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\NumericField;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\View\Requirements;
|
||||
|
||||
class FlickrWidget extends Widget
|
||||
{
|
||||
private static $db = array(
|
||||
'User' => 'Varchar',
|
||||
'Photoset' => 'Varchar',
|
||||
'Tags' => 'Varchar',
|
||||
'NumberToShow' => 'Int'
|
||||
);
|
||||
|
||||
private static $defaults = array(
|
||||
"NumberToShow" => 8
|
||||
'NumberToShow' => 8
|
||||
);
|
||||
|
||||
private static $title = "Photos";
|
||||
private static $cmsTitle = "Flickr Photos";
|
||||
private static $description = "Shows flickr photos.";
|
||||
private static $title = 'Photos';
|
||||
private static $cmsTitle = 'Flickr Photos';
|
||||
private static $description = 'Shows flickr photos.';
|
||||
|
||||
public function Photos() {
|
||||
Requirements::javascript(THIRDPARTY_DIR . "/prototype/prototype.js");
|
||||
Requirements::javascript(THIRDPARTY_DIR . "/scriptaculous/effects.js");
|
||||
Requirements::javascript("mashups/javascript/lightbox.js");
|
||||
Requirements::css("mashups/css/lightbox.css");
|
||||
public function Photos()
|
||||
{
|
||||
// You'll need to install these yourself
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/prototype/prototype.js');
|
||||
Requirements::javascript(THIRDPARTY_DIR . '/scriptaculous/effects.js');
|
||||
Requirements::javascript('mashups/javascript/lightbox.js');
|
||||
Requirements::css('mashups/css/lightbox.css');
|
||||
|
||||
$flickr = new FlickrService();
|
||||
if($this->Photoset == "") {
|
||||
if ($this->Photoset == '') {
|
||||
$photos = $flickr->getPhotos($this->Tags, $this->User, $this->NumberToShow, 1);
|
||||
} else {
|
||||
$photos = $flickr->getPhotoSet($this->Photoset, $this->User, $this->NumberToShow, 1);
|
||||
@ -129,32 +156,38 @@ An example widget is below:
|
||||
|
||||
$output = new ArrayList();
|
||||
foreach ($photos->PhotoItems as $photo) {
|
||||
$output->push(new ArrayData(array(
|
||||
"Title" => $photo->title,
|
||||
"Link" => "http://farm1.static.flickr.com/" . $photo->image_path .".jpg",
|
||||
"Image" => "http://farm1.static.flickr.com/" .$photo->image_path. "_s.jpg"
|
||||
)));
|
||||
$output->push(
|
||||
new ArrayData(
|
||||
array(
|
||||
'Title' => $photo->title,
|
||||
'Link' => 'http://farm1.static.flickr.com/' . $photo->image_path .'.jpg',
|
||||
'Image' => 'http://farm1.static.flickr.com/' .$photo->image_path. '_s.jpg'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function getCMSFields() {
|
||||
public function getCMSFields()
|
||||
{
|
||||
return new FieldList(
|
||||
new TextField("User", "User"),
|
||||
new TextField("PhotoSet", "Photo Set"),
|
||||
new TextField("Tags", "Tags"),
|
||||
new NumericField("NumberToShow", "Number to Show")
|
||||
new TextField('User', 'User'),
|
||||
new TextField('PhotoSet', 'Photo Set'),
|
||||
new TextField('Tags', 'Tags'),
|
||||
new NumericField('NumberToShow', 'Number to Show')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
**FlickrWidget.ss**
|
||||
|
||||
:::ss
|
||||
```
|
||||
<% control Photos %>
|
||||
<a href="$Link" rel="lightbox" title="$Title"><img src="$Image" alt="$Title" /></a>
|
||||
<% end_control %>
|
||||
```
|
||||
|
||||
## Limiting Allowed Widgets for a Pagetype
|
||||
|
||||
@ -162,8 +195,15 @@ You can lock down a particular `WidgetAreaEditor` to only allow adding certain w
|
||||
|
||||
**GreatPage.php**
|
||||
|
||||
:::php
|
||||
```php
|
||||
$fields->addFieldToTab(
|
||||
'Root.Widgets',
|
||||
new WidgetAreaEditor('PhenomenalWidgetArea', ['ParticularlyEpicWidget', 'LessGreatWidget'])
|
||||
new WidgetAreaEditor(
|
||||
'PhenomenalWidgetArea',
|
||||
[
|
||||
'Fully\\Qualified\\ParticularlyEpicWidget',
|
||||
'Yourname\\MyModule\\LessGreatWidget'
|
||||
]
|
||||
)
|
||||
);
|
||||
```
|
||||
|
@ -5,8 +5,8 @@ the sidebar of your website. To check out a what a [Widget](http://silverstripe.
|
||||
[demo site](http://demo.silverstripe.org/)
|
||||
[![Build Status](http://img.shields.io/travis/silverstripe/silverstripe-widgets.svg?style=flat-square)](https://travis-ci.org/silverstripe/silverstripe-widgets)
|
||||
[![Code Quality](http://img.shields.io/scrutinizer/g/silverstripe/silverstripe-widgets.svg?style=flat-square)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-widgets)
|
||||
[![Version](http://img.shields.io/packagist/v/silverstripe/silverstripe-widgets.svg?style=flat-square)](https://packagist.org/packages/silverstripe/silverstripe-widgets)
|
||||
[![License](http://img.shields.io/packagist/l/silverstripe/silverstripe-widgets.svg?style=flat-square)](LICENSE.md)
|
||||
[![Version](http://img.shields.io/packagist/v/silverstripe/widgets.svg?style=flat-square)](https://packagist.org/packages/silverstripe/widgets)
|
||||
[![License](http://img.shields.io/packagist/l/silverstripe/widgets.svg?style=flat-square)](LICENSE.md)
|
||||
|
||||
## Share Links
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user