Compare commits
136 Commits
Author | SHA1 | Date |
---|---|---|
Guy Sartorelli | eacb02c297 | |
Guy Sartorelli | afe1cc5da0 | |
Guy Sartorelli | f2b92e8f83 | |
Guy Sartorelli | 2b53f5095c | |
Maxime Rainville | d27f656e97 | |
Steve Boyd | b615184c54 | |
Guy Sartorelli | a9a20ab1c0 | |
Guy Sartorelli | 8ad0537473 | |
Guy Sartorelli | 02d5a17e1f | |
Guy Sartorelli | 53e7646700 | |
Steve Boyd | 812f3dc282 | |
Steve Boyd | 9934adecdb | |
Steve Boyd | 08cdad1290 | |
Guy Sartorelli | 08554e7882 | |
Steve Boyd | 57b1d87577 | |
Steve Boyd | 3fd8120b74 | |
Steve Boyd | d907c77ed6 | |
Guy Sartorelli | 65ef1bbc50 | |
Steve Boyd | d16e4770da | |
Steve Boyd | 3685869917 | |
Steve Boyd | 3d89a29628 | |
Guy Sartorelli | d78326987c | |
Steve Boyd | 51d29b3d5a | |
Maxime Rainville | 5aca443a7c | |
Steve Boyd | 2b9536e5ae | |
Steve Boyd | a08aa08f4d | |
Maxime Rainville | 6c2b654f19 | |
Maxime Rainville | 6e163beb44 | |
Steve Boyd | d4ae7ff9ab | |
Steve Boyd | 92f90fbea5 | |
Maxime Rainville | f759a8b56b | |
Maxime Rainville | 81b59ab4b9 | |
Steve Boyd | 0f37c09531 | |
Steve Boyd | c3fc2cab68 | |
Serge Latyntsev | 0fda5eec16 | |
Steve Boyd | 1265ce99a6 | |
Garion Herman | 8db05ea5f0 | |
Serge Latyntsev | 007b6fcdfa | |
Garion Herman | 42af10671e | |
Garion Herman | f396ee7242 | |
Robbie Averill | ade8047461 | |
wernerkrauss | 5d2f0570d8 | |
Robbie Averill | 7d2dd46159 | |
Dylan Wagstaff | 41c9ecffe6 | |
Robbie Averill | 35df96f502 | |
Robbie Averill | 6ce962607f | |
Robbie Averill | eb81b3c8d9 | |
Raissa North | 129a650729 | |
Dylan Wagstaff | d17c577609 | |
Scott Hutchinson | 294f9b60b5 | |
Robbie Averill | 76b8b3f891 | |
Raissa North | ab8349209a | |
Dylan Wagstaff | 0a3c280c3d | |
Robbie Averill | 8583b894a1 | |
Robbie Averill | 5ca288c9a3 | |
Robbie Averill | e1a0469c46 | |
Robbie Averill | a0b1f9b1cf | |
Robbie Averill | a2f4594597 | |
Raissa North | de7473e9ea | |
Raissa North | 58e26969a3 | |
Raissa North | 285b46fafb | |
Raissa North | 0916970951 | |
Robbie Averill | 5287ebcbe5 | |
Robbie Averill | c5511726ef | |
Robbie Averill | 4dccc49a41 | |
Robbie Averill | 646cd1a210 | |
Robbie Averill | 7767292d50 | |
Robbie Averill | c28c3c1d8d | |
Dylan Wagstaff | f8f10e96ff | |
Robbie Averill | bf9fbe3aa7 | |
Robbie Averill | 406f925beb | |
Robbie Averill | 712fb56897 | |
Adrian Stein | e9e30b6489 | |
Damian Mooyman | 023eef23c6 | |
Robbie Averill | fb91acbe3a | |
Robbie Averill | 3f02a0b295 | |
Dylan Wagstaff | 18296d00e4 | |
Dylan Wagstaff | 36a5840d45 | |
Franco Springveldt | 26f1c2bd74 | |
Robbie Averill | 9b12b602f5 | |
Robbie Averill | 7c85b1b5d9 | |
Robbie Averill | ad6a965526 | |
Robbie Averill | 33f173d39b | |
maks feltrin | 33ef8b9d2c | |
Daniel Hensby | 5437f6b2a5 | |
Daniel Hensby | cc7d188927 | |
Daniel Hensby | 4c87ff3896 | |
Rastislav Brandobur | a434245cfa | |
Robbie Averill | 8f0427922b | |
Robbie Averill | 9aa40a0611 | |
Rastislav Brandobur | 80029afafb | |
Brett Tasker | df4844d45f | |
Damian Mooyman | 1fe4c3db70 | |
Robbie Averill | 8dae0a6f95 | |
Robbie Averill | ec9421ba65 | |
Robbie Averill | e7de0c61bf | |
Robbie Averill | 8eee397b9a | |
Robbie Averill | defb4bf134 | |
Daniel Hensby | f3b14df4e4 | |
Daniel Hensby | ef40ca30aa | |
Daniel Hensby | 1bbaba52e0 | |
Daniel Hensby | 616bcdb364 | |
Daniel Hensby | 8c705392e9 | |
Daniel Hensby | 661e7ee48a | |
Daniel Hensby | cc591f2c56 | |
Daniel Hensby | 40af14906d | |
Garion Herman | 04dbb41125 | |
Damian Mooyman | 6dd4ff8525 | |
Damian Mooyman | 58aa2a6a35 | |
Daniel Hensby | 0986537be7 | |
rasstislav | 86bf12a181 | |
Damian Mooyman | 8d5203c08a | |
Daniel Hensby | cbebc589b2 | |
torleif | 3bc304b844 | |
Daniel Hensby | 36ccdf2ebc | |
torleif | 987d29341e | |
Damian Mooyman | 9e2b4f1586 | |
torleif | e6ea99ac12 | |
Stevie Mayhew | 4aa66af42d | |
torleif | 92e3fd6d9a | |
torleif | 1719ee3248 | |
Damian Mooyman | 90d6402185 | |
Damian Mooyman | 799c2f1bf0 | |
John Milmine | 0f207180b4 | |
☃ Stephen Shkardoon ☃ | 17c94ff9ce | |
Matthew Hailwood | ff0178330a | |
Damian Mooyman | c332a6ab8b | |
Daniel Hensby | 4d9fc0056c | |
Damian Mooyman | b95f204374 | |
Christopher Pitt | bf5a08da76 | |
Christopher Pitt | 791d32a303 | |
Damian Mooyman | ed6114a7dc | |
Damian Mooyman | ccea929cb9 | |
Ingo Schommer | 25a1a35a0b | |
Will Rossiter | 557a7219f4 | |
UndefinedOffset | 54599b98d1 |
|
@ -4,3 +4,4 @@
|
|||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/codecov.yml export-ignore
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: CI
|
||||
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
|
|
@ -0,0 +1,16 @@
|
|||
name: Dispatch CI
|
||||
|
||||
on:
|
||||
# At 1:00 PM UTC, only on Saturday and Sunday
|
||||
schedule:
|
||||
- cron: '0 13 * * 6,0'
|
||||
|
||||
jobs:
|
||||
dispatch-ci:
|
||||
name: Dispatch CI
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dispatch CI
|
||||
uses: silverstripe/gha-dispatch-ci@v1
|
|
@ -0,0 +1,17 @@
|
|||
name: Keepalive
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# The 4th of every month at 10:50am UTC
|
||||
schedule:
|
||||
- cron: '50 10 4 * *'
|
||||
|
||||
jobs:
|
||||
keepalive:
|
||||
name: Keepalive
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Keepalive
|
||||
uses: silverstripe/gha-keepalive@v1
|
|
@ -1,9 +0,0 @@
|
|||
inherit: true
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
duplication: true
|
||||
|
||||
filter:
|
||||
paths: [code/*, tests/*]
|
34
.travis.yml
34
.travis.yml
|
@ -1,34 +0,0 @@
|
|||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
|
||||
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
|
||||
env:
|
||||
- DB=MYSQL CORE_RELEASE=3.2
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
env: DB=MYSQL CORE_RELEASE=3
|
||||
- php: 5.6
|
||||
env: DB=PGSQL CORE_RELEASE=3.2
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
|
||||
before_script:
|
||||
- composer self-update || true
|
||||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit widgets/tests
|
|
@ -1,8 +1,9 @@
|
|||
[main]
|
||||
host = https://www.transifex.com
|
||||
|
||||
[silverstripe-widgets.master]
|
||||
[o:silverstripe:p:silverstripe-widgets:r:master]
|
||||
file_filter = lang/<lang>.yml
|
||||
source_file = lang/en.yml
|
||||
source_lang = en
|
||||
type = YML
|
||||
type = YML
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
mappings:
|
||||
WidgetContentControllerExtension: SilverStripe\Widgets\Controllers\WidgetContentControllerExtension
|
||||
Widget_Controller: SilverStripe\Widgets\Models\WidgetController
|
||||
WidgetPageExtension: SilverStripe\Widgets\Extensions\WidgetPageExtension
|
||||
WidgetAreaEditor: SilverStripe\Widgets\Forms\WidgetAreaEditor
|
||||
Widget: SilverStripe\Widgets\Model\Widget
|
||||
WidgetArea: SilverStripe\Widgets\Model\WidgetArea
|
400
README.md
400
README.md
|
@ -1,6 +1,7 @@
|
|||
# Widgets Module
|
||||
|
||||
[![Build Status](https://secure.travis-ci.org/silverstripe/silverstripe-widgets.png?branch=1.1)](http://travis-ci.org/silverstripe/silverstripe-widgets)
|
||||
[![CI](https://github.com/silverstripe/silverstripe-widgets/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-widgets/actions/workflows/ci.yml)
|
||||
[![Silverstripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
|
||||
## Overview
|
||||
|
||||
|
@ -9,8 +10,9 @@ the sidebar of your website.
|
|||
|
||||
## Requirements
|
||||
|
||||
* SilverStripe 3.2
|
||||
|
||||
* Silverstripe 4.0
|
||||
|
||||
**Note:** this version is compatible with Silverstripe 4. For Silverstripe 3, please see [the 1.x release line](https://github.com/silverstripe/silverstripe-widgets/tree/1.3).
|
||||
|
||||
### Installation
|
||||
|
||||
|
@ -26,6 +28,31 @@ 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`:
|
||||
|
||||
```yaml
|
||||
Page:
|
||||
extensions:
|
||||
- SilverStripe\Widgets\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
|
||||
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. Please ensure you add the correct namespaces for your module.
|
||||
|
||||
### Installing a widget
|
||||
|
||||
By following the "Packaging" rules below, widgets are easily installed. This example uses the Blog module which by default has widgets already enabled.
|
||||
|
||||
* Install the [blog module](https://github.com/silverstripe/silverstripe-blog/).
|
||||
* Download the widget and unzip to the main folder of your Silverstripe website, e.g. to `/widget_<widget-name>/`. The folder
|
||||
will contain a few files, which generally won't need editing or reading.
|
||||
* Run `http://my-website.com/dev/build`
|
||||
* Login to the CMS and go to the 'Blog' page. Choose the "widgets" tab and click the new widget to activate it.
|
||||
* Your blog will now have the widget shown
|
||||
|
||||
## Documentation
|
||||
|
||||
See the [docs/en](docs/en/introduction.md) folder.
|
||||
|
@ -34,20 +61,10 @@ See the [docs/en](docs/en/introduction.md) folder.
|
|||
|
||||
This library follows [Semver](http://semver.org). According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.
|
||||
|
||||
By following the "Packaging" rules below, widgets are easily installed. This example uses the Blog module which by default has widgets already enabled.
|
||||
|
||||
* Install the [blog module](https://github.com/silverstripe/silverstripe-blog/).
|
||||
* Download the widget and unzip to the main folder of your SilverStripe website, e.g. to `/widget_<widget-name>/`. The folder
|
||||
will contain a few files, which generally won't need editing or reading.
|
||||
* Run `http://my-website.com/dev/build`
|
||||
* Login to the CMS and go to the 'Blog' page. Choose the "widgets" tab and click the new widget to activate it.
|
||||
* Your blog will now have the widget shown
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
Please [create an issue](http://github.com/silverstripe/silverstripe-widgets/issues) for any bugs you've found, or features you're missing.
|
||||
|
||||
|
||||
* Install the Widgets Module, see above.
|
||||
* Add a WidgetArea field to your Page.
|
||||
* Add a new tab to the CMS with a WidgetAreaEditor field for managing the widgets.
|
||||
|
@ -55,18 +72,28 @@ e.g.
|
|||
|
||||
**mysite/code/Page.php**
|
||||
|
||||
class Page extends SiteTree {
|
||||
...
|
||||
private static $has_one = array(
|
||||
"MyWidgetArea" => "WidgetArea",
|
||||
);
|
||||
```php
|
||||
<?php
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("MyWidgetArea"));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
class Page extends SiteTree
|
||||
{
|
||||
// ...
|
||||
private static $has_one = array(
|
||||
'MyWidgetArea' => WidgetArea::class
|
||||
);
|
||||
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->addFieldToTab('Root.Widgets', new WidgetAreaEditor('MyWidgetArea'));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case, you need to alter your templates to include the `$MyWidgetArea` placeholder.
|
||||
|
||||
|
@ -87,78 +114,97 @@ The class should extend the Widget class, and must specify three config variable
|
|||
Flickr). The class may also specify functions to be used in the template like a page type can.
|
||||
|
||||
If a Widget has configurable options, then it can specify a number of database fields to store these options in via the
|
||||
static $db array, and also specify a getCMSFields function that returns a !FieldList, much the same way as a page type
|
||||
static `$db` array, and also specify a `getCMSFields` function that returns a `FieldList`, much the same way as a page type
|
||||
does.
|
||||
|
||||
An example widget is below:
|
||||
|
||||
**FlickrWidget.php**
|
||||
|
||||
:::php
|
||||
<?php
|
||||
class FlickrWidget extends Widget {
|
||||
private static $db = array(
|
||||
"User" => "Varchar",
|
||||
"Photoset" => "Varchar",
|
||||
"Tags" => "Varchar",
|
||||
"NumberToShow" => "Int"
|
||||
);
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
private static $defaults = array(
|
||||
"NumberToShow" => 8
|
||||
);
|
||||
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;
|
||||
|
||||
private static $title = "Photos";
|
||||
private static $cmsTitle = "Flickr Photos";
|
||||
private static $description = "Shows flickr photos.";
|
||||
class FlickrWidget extends Widget
|
||||
{
|
||||
private static $db = array(
|
||||
'User' => 'Varchar',
|
||||
'Photoset' => 'Varchar',
|
||||
'Tags' => 'Varchar',
|
||||
'NumberToShow' => 'Int'
|
||||
);
|
||||
|
||||
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");
|
||||
private static $defaults = array(
|
||||
'NumberToShow' => 8
|
||||
);
|
||||
|
||||
$flickr = new FlickrService();
|
||||
if($this->Photoset == "") {
|
||||
$photos = $flickr->getPhotos($this->Tags, $this->User, $this->NumberToShow, 1);
|
||||
} else {
|
||||
$photos = $flickr->getPhotoSet($this->Photoset, $this->User, $this->NumberToShow, 1);
|
||||
}
|
||||
private static $title = 'Photos';
|
||||
private static $cmsTitle = 'Flickr Photos';
|
||||
private static $description = 'Shows flickr photos.';
|
||||
|
||||
$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"
|
||||
)));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
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');
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
}
|
||||
$flickr = new FlickrService();
|
||||
if ($this->Photoset == '') {
|
||||
$photos = $flickr->getPhotos($this->Tags, $this->User, $this->NumberToShow, 1);
|
||||
} else {
|
||||
$photos = $flickr->getPhotoSet($this->Photoset, $this->User, $this->NumberToShow, 1);
|
||||
}
|
||||
|
||||
$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'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
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')
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**FlickrWidget.ss**
|
||||
|
||||
:::ss
|
||||
<% control Photos %>
|
||||
<a href="$Link" rel="lightbox" title="$Title"><img src="$Image" alt="$Title" /></a>
|
||||
<% end_control %>
|
||||
|
||||
```
|
||||
<% 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 +224,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 +236,11 @@ You need to finish off / change:
|
|||
],
|
||||
"extra" : {
|
||||
"installer-name": "widgets_"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Yourname\\MyWidget\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -201,57 +252,62 @@ You need to finish off / change:
|
|||
To call a single Widget in a page - without adding a widget area in the CMS for you to add / delete the widgets, you can
|
||||
define a merge variable in the Page Controller and include it in the Page Template.
|
||||
|
||||
This example creates an RSSWidget with the SilverStripe blog feed.
|
||||
This example creates an RSSWidget with the Silverstripe blog feed.
|
||||
|
||||
:::php
|
||||
public function SilverStripeFeed() {
|
||||
$widget = new RSSWidget();
|
||||
$widget->RssUrl = "http://feeds.feedburner.com/silverstripe-blog";
|
||||
return $widget->renderWith("WidgetHolder");
|
||||
}
|
||||
```php
|
||||
public function SilverStripeFeed()
|
||||
{
|
||||
$widget = new RSSWidget();
|
||||
$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
|
||||
```
|
||||
$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>
|
||||
|
||||
```
|
||||
<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/`
|
||||
|
||||
### Changing the title of your widget
|
||||
|
||||
To change the title of your widget, you need to override the Title() method. By default, this simply returns the $title
|
||||
To change the title of your widget, you need to override the `getTitle()` 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 getTitle()
|
||||
{
|
||||
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
|
||||
A more common reason for overriding `getTitle()` 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() {
|
||||
return $this->WidgetTitle ? $this->WidgetTitle : self::$title;
|
||||
}
|
||||
|
||||
```php
|
||||
public function getTitle()
|
||||
{
|
||||
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,69 +319,97 @@ sure that your controller follows the usual naming conventions, and it will be a
|
|||
|
||||
**mysite/code/MyWidget.php**
|
||||
|
||||
:::php
|
||||
class MyWidget extends Widget {
|
||||
private static $db = array(
|
||||
'TestValue' => 'Text'
|
||||
);
|
||||
}
|
||||
```php
|
||||
<?php
|
||||
|
||||
class MyWidget_Controller extends WidgetController {
|
||||
public function MyFormName() {
|
||||
return new Form(
|
||||
$this,
|
||||
'MyFormName',
|
||||
new FieldList(
|
||||
new TextField('TestValue')
|
||||
),
|
||||
new FieldList(
|
||||
new FormAction('doAction')
|
||||
)
|
||||
);
|
||||
}
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
public function doAction($data, $form) {
|
||||
// $this->widget points to the widget
|
||||
}
|
||||
}
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
class MyWidget extends Widget
|
||||
{
|
||||
private static $db = array(
|
||||
'TestValue' => 'Text'
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
```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',
|
||||
new FieldList(
|
||||
new TextField('TestValue')
|
||||
),
|
||||
new FieldList(
|
||||
new FormAction('doAction')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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
|
||||
```
|
||||
$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
|
||||
class BlogHolder extends Page {
|
||||
|
||||
........
|
||||
static $has_one = array(
|
||||
// "Sidebar" => "WidgetArea", COMMENT OUT
|
||||
'Newsletter' => 'NewsletterType'
|
||||
.......
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->removeFieldFromTab("Root.Content","Content");
|
||||
// $fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("Sidebar")); COMMENT OUT
|
||||
|
||||
........
|
||||
|
||||
```php
|
||||
<?php
|
||||
class BlogHolder extends Page
|
||||
{
|
||||
// ........
|
||||
static $has_one = array(
|
||||
// "Sidebar" => "WidgetArea", COMMENT OUT
|
||||
'Newsletter' => 'NewsletterType'
|
||||
);
|
||||
// .......
|
||||
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 +423,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
|
|
@ -1,8 +1,8 @@
|
|||
---
|
||||
Name: contentcontrollerurlhandler
|
||||
Name: widgetscontentcontrollerurlhandler
|
||||
---
|
||||
ContentController:
|
||||
SilverStripe\CMS\Controllers\ContentController:
|
||||
extensions:
|
||||
- WidgetContentControllerExtension
|
||||
- SilverStripe\Widgets\Controllers\WidgetContentControllerExtension
|
||||
url_handlers:
|
||||
'widget/$ID!': 'handleWidget'
|
||||
'widget/$ID!': 'handleWidget'
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
Name: widgetslegacymapping
|
||||
---
|
||||
SilverStripe\ORM\DatabaseAdmin:
|
||||
classname_value_remapping:
|
||||
Widget: SilverStripe\Widgets\Model\Widget
|
||||
WidgetArea: SilverStripe\Widgets\Model\WidgetArea
|
|
@ -1,3 +1,6 @@
|
|||
Director:
|
||||
---
|
||||
Name: widgetsroutes
|
||||
---
|
||||
SilverStripe\Control\Director:
|
||||
rules:
|
||||
'WidgetController//$Action/$ID/$OtherID': 'WidgetController'
|
||||
'WidgetController//$Action/$ID/$OtherID': 'SilverStripe\Widgets\Model\WidgetController'
|
||||
|
|
23
changelog.md
23
changelog.md
|
@ -1,8 +1,27 @@
|
|||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
## [1.2.2](https://github.com/silverstripe/silverstripe-widgets/tree/1.2.2) (2016-02-04)
|
||||
[Full Changelog](https://github.com/silverstripe/silverstripe-widgets/compare/1.2.1...1.2.2)
|
||||
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
**Closed issues:**
|
||||
|
||||
- Broken Links in README [\#119](https://github.com/silverstripe/silverstripe-widgets/issues/119)
|
||||
- Loop Children / with has\_one \(page\) not working [\#81](https://github.com/silverstripe/silverstripe-widgets/issues/81)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Fix readme.md links [\#120](https://github.com/silverstripe/silverstripe-widgets/pull/120) ([tractorcow](https://github.com/tractorcow))
|
||||
- Updated license year [\#118](https://github.com/silverstripe/silverstripe-widgets/pull/118) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- ItemsToRender might return NULL // avoid warnings [\#117](https://github.com/silverstripe/silverstripe-widgets/pull/117) ([steiha](https://github.com/steiha))
|
||||
- Added standard code of conduct [\#116](https://github.com/silverstripe/silverstripe-widgets/pull/116) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- Remove invalid 3.1 test fixture [\#115](https://github.com/silverstripe/silverstripe-widgets/pull/115) ([tractorcow](https://github.com/tractorcow))
|
||||
- Added standard git attributes [\#114](https://github.com/silverstripe/silverstripe-widgets/pull/114) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- Added license to composer.json [\#113](https://github.com/silverstripe/silverstripe-widgets/pull/113) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- Added standard license [\#112](https://github.com/silverstripe/silverstripe-widgets/pull/112) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- Update changelog for 1.2.1 [\#111](https://github.com/silverstripe/silverstripe-widgets/pull/111) ([tractorcow](https://github.com/tractorcow))
|
||||
- Added standard Travis config [\#110](https://github.com/silverstripe/silverstripe-widgets/pull/110) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- Added standard editor config [\#109](https://github.com/silverstripe/silverstripe-widgets/pull/109) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
- Converted to PSR-2 [\#107](https://github.com/silverstripe/silverstripe-widgets/pull/107) ([helpfulrobot](https://github.com/helpfulrobot))
|
||||
|
||||
## [1.2.1](https://github.com/silverstripe/silverstripe-widgets/tree/1.2.1) (2015-11-18)
|
||||
[Full Changelog](https://github.com/silverstripe/silverstripe-widgets/compare/1.1.2...1.2.1)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
comment: false
|
|
@ -1,25 +1,41 @@
|
|||
{
|
||||
"name": "silverstripe/widgets",
|
||||
"description": "Widgets are small pieces of functionality such as showing the latest Comments or Flickr Photos. They normally display on the sidebar of your website.",
|
||||
"type": "silverstripe-module",
|
||||
"keywords": ["silverstripe", "widgets", "blog"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ingo Schommer",
|
||||
"email": "ingo@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": ">=3.2",
|
||||
"silverstripe/cms": ">=3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "~3.7@stable"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.2.x-dev"
|
||||
}
|
||||
},
|
||||
"license": "BSD-3-Clause"
|
||||
}
|
||||
"name": "silverstripe/widgets",
|
||||
"description": "Widgets are small pieces of functionality such as showing the latest Comments or Flickr Photos. They normally display on the sidebar of your website.",
|
||||
"type": "silverstripe-vendormodule",
|
||||
"keywords": [
|
||||
"silverstripe",
|
||||
"widgets",
|
||||
"blog"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ingo Schommer",
|
||||
"email": "ingo@silverstripe.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/vendor-plugin": "^1.0",
|
||||
"silverstripe/framework": "^4.10",
|
||||
"silverstripe/cms": "^4.0",
|
||||
"silverstripe/versioned": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
},
|
||||
"extra": {
|
||||
"expose": [
|
||||
"css",
|
||||
"javascript"
|
||||
]
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SilverStripe\\Widgets\\": "src/",
|
||||
"SilverStripe\\Widgets\\Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"license": "BSD-3-Clause",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true
|
||||
}
|
|
@ -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/"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
```
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
@charset "UTF-8";
|
||||
.WidgetAreaEditor p { margin-bottom: 15px; }
|
||||
|
||||
.Widget { padding: 0 7px 7px 7px; margin: 16px 0 16px 0; color: #1f1f1f; background-color: #b0bec7; background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2IwYmVjNyIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzkyYTViMiIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA=="); background-size: 100%; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #b0bec7), color-stop(100%, #92a5b2)); background-image: -webkit-linear-gradient(#b0bec7, #92a5b2); background-image: -moz-linear-gradient(#b0bec7, #92a5b2); background-image: -o-linear-gradient(#b0bec7, #92a5b2); background-image: linear-gradient(#b0bec7, #92a5b2); border-top: 1px solid #c2cdd4; border-bottom: 1px solid #748d9d; -webkit-border-radius: 3px; -moz-border-radius: 3px; -ms-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
|
||||
.Widget h3 { margin: 0; padding: 0; line-height: 40px; text-shadow: #bfcad2 1px 1px 0; -webkit-transition-property: background-image; -moz-transition-property: background-image; -o-transition-property: background-image; transition-property: background-image; -webkit-transition-duration: 0.2s; -moz-transition-duration: 0.2s; -o-transition-duration: 0.2s; transition-duration: 0.2s; -webkit-transition-timing-function: ease-out; -moz-transition-timing-function: ease-out; -o-transition-timing-function: ease-out; transition-timing-function: ease-out; }
|
||||
.Widget .widgetDescription { background: #eceff1; padding: 5px 5px 1px 5px; margin: 0; -webkit-border-radius: 3px; -moz-border-radius: 3px; -ms-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
|
||||
.Widget .widgetFields { background: #eceff1; padding: 5px; margin: 7px 0 0 0; -webkit-border-radius: 3px; -moz-border-radius: 3px; -ms-border-radius: 3px; -o-border-radius: 3px; border-radius: 3px; }
|
||||
.Widget { padding: 0 1.25rem .75rem; margin: 16px 0 16px 0; color: #4F5861; background-color: #F1F3F6; border: 1px solid #ced5e1; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
|
||||
.Widget h3 { color: #43536d; margin: 0; padding: 4px 0; line-height: 40px; -moz-transition-property: background-image; -o-transition-property: background-image; -webkit-transition-property: background-image; transition-property: background-image; -moz-transition-duration: 0.2s; -o-transition-duration: 0.2s; -webkit-transition-duration: 0.2s; transition-duration: 0.2s; -moz-transition-timing-function: ease-out; -o-transition-timing-function: ease-out; -webkit-transition-timing-function: ease-out; transition-timing-function: ease-out; }
|
||||
.Widget .widgetDescription { padding: 0 0 .5rem; margin: 0; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; }
|
||||
.Widget .widgetDescription p { margin: 0; }
|
||||
.Widget .widgetFields { background: #F7F8FA; border-top: 1px solid #dbe0e9; border-bottom: 1px solid #dbe0e9; padding: .75rem 1.25rem; margin: .75rem -1.25rem; }
|
||||
|
||||
.availableWidgetsHolder { width: 38%; float: left; }
|
||||
|
||||
|
|
|
@ -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
|
||||
Page:
|
||||
extensions:
|
||||
- WidgetPageExtension
|
||||
```yaml
|
||||
Page:
|
||||
extensions:
|
||||
- SilverStripe\Widgets\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 {
|
||||
...
|
||||
private static $has_one = array(
|
||||
"MyWidgetArea" => "WidgetArea",
|
||||
);
|
||||
```php
|
||||
<?php
|
||||
|
||||
public function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("MyWidgetArea"));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
class Page extends SiteTree
|
||||
{
|
||||
// ...
|
||||
private static $has_one = array(
|
||||
'MyWidgetArea' => WidgetArea::class
|
||||
);
|
||||
|
||||
public function getCMSFields()
|
||||
{
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->addFieldToTab('Root.Widgets', new WidgetAreaEditor('MyWidgetArea'));
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In this case, you need to alter your templates to include the `$MyWidgetArea` placeholder.
|
||||
|
||||
|
@ -88,71 +101,109 @@ The class should extend the Widget class, and must specify three config variable
|
|||
Flickr). The class may also specify functions to be used in the template like a page type can.
|
||||
|
||||
If a Widget has configurable options, then it can specify a number of database fields to store these options in via the
|
||||
static $db array, and also specify a getCMSFields function that returns a !FieldList, much the same way as a page type
|
||||
static `$db` array, and also specify a `getCMSFields` function that returns a `FieldList`, much the same way as a page type
|
||||
does.
|
||||
|
||||
An example widget is below:
|
||||
|
||||
**FlickrWidget.php**
|
||||
|
||||
:::php
|
||||
<?php
|
||||
class FlickrWidget extends Widget {
|
||||
private static $db = array(
|
||||
"User" => "Varchar",
|
||||
"Photoset" => "Varchar",
|
||||
"Tags" => "Varchar",
|
||||
"NumberToShow" => "Int"
|
||||
);
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace Yourname\MyWidget;
|
||||
|
||||
private static $defaults = array(
|
||||
"NumberToShow" => 8
|
||||
);
|
||||
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;
|
||||
|
||||
private static $title = "Photos";
|
||||
private static $cmsTitle = "Flickr Photos";
|
||||
private static $description = "Shows flickr photos.";
|
||||
class FlickrWidget extends Widget
|
||||
{
|
||||
private static $db = array(
|
||||
'User' => 'Varchar',
|
||||
'Photoset' => 'Varchar',
|
||||
'Tags' => 'Varchar',
|
||||
'NumberToShow' => 'Int'
|
||||
);
|
||||
|
||||
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");
|
||||
private static $defaults = array(
|
||||
'NumberToShow' => 8
|
||||
);
|
||||
|
||||
$flickr = new FlickrService();
|
||||
if($this->Photoset == "") {
|
||||
$photos = $flickr->getPhotos($this->Tags, $this->User, $this->NumberToShow, 1);
|
||||
} else {
|
||||
$photos = $flickr->getPhotoSet($this->Photoset, $this->User, $this->NumberToShow, 1);
|
||||
}
|
||||
private static $title = 'Photos';
|
||||
private static $cmsTitle = 'Flickr Photos';
|
||||
private static $description = 'Shows flickr photos.';
|
||||
|
||||
$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"
|
||||
)));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
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');
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
}
|
||||
$flickr = new FlickrService();
|
||||
if ($this->Photoset == '') {
|
||||
$photos = $flickr->getPhotos($this->Tags, $this->User, $this->NumberToShow, 1);
|
||||
} else {
|
||||
$photos = $flickr->getPhotoSet($this->Photoset, $this->User, $this->NumberToShow, 1);
|
||||
}
|
||||
|
||||
$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'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
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')
|
||||
);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**FlickrWidget.ss**
|
||||
|
||||
:::ss
|
||||
<% control Photos %>
|
||||
<a href="$Link" rel="lightbox" title="$Title"><img src="$Image" alt="$Title" /></a>
|
||||
<% end_control %>
|
||||
```
|
||||
<% control Photos %>
|
||||
<a href="$Link" rel="lightbox" title="$Title"><img src="$Image" alt="$Title" /></a>
|
||||
<% end_control %>
|
||||
```
|
||||
|
||||
## Limiting Allowed Widgets for a Pagetype
|
||||
|
||||
You can lock down a particular `WidgetAreaEditor` to only allow adding certain widgets by passing them as a second parameter.
|
||||
|
||||
**GreatPage.php**
|
||||
|
||||
```php
|
||||
$fields->addFieldToTab(
|
||||
'Root.Widgets',
|
||||
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
|
||||
|
||||
|
@ -21,4 +21,4 @@ The generated share links have a public key and hash. There can be any number of
|
|||
|
||||
This module was created by [SilverStripe](https://twitter.com/silverstripe). You can ask questions on Twitter.
|
||||
|
||||
You can report bugs or request features on [GitHub](https://github.com/silverstripe/silverstripe-widgets/issues).
|
||||
You can report bugs or request features on [GitHub](https://github.com/silverstripe/silverstripe-widgets/issues).
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
var parentName=$(this).attr('name');
|
||||
this.rewriteWidgetAreaAttributes();
|
||||
|
||||
var availableWidgets=$('#availableWidgets-'+$(this).attr('name')).children().each(function() {
|
||||
var availableWidgets=$('#availableWidgets-'+parentName).children().each(function() {
|
||||
// Don't run on comments, whitespace, etc
|
||||
if($(this)[0].nodeType==1) {
|
||||
// Gotta change their ID's because otherwise we get clashes between two tabs
|
||||
|
@ -20,26 +20,25 @@
|
|||
$(this).find('.usedWidgets').sortable({
|
||||
opacity: 0.6,
|
||||
handle: '.handle',
|
||||
update: function(e, ui) {parentRef.updateWidgets(e, ui)},
|
||||
update: function (e, ui) {
|
||||
parentRef.updateWidgets(e, ui)
|
||||
},
|
||||
placeholder: 'ui-state-highlight',
|
||||
forcePlaceholderSize: true
|
||||
});
|
||||
|
||||
// Figure out maxid, this is used when creating new widgets
|
||||
$(this).data('maxid', 0);
|
||||
|
||||
var usedWidgets = $(this).find('.usedWidgets .Widget');
|
||||
usedWidgets.each(function() {
|
||||
var widget = $(this)[0];
|
||||
if(widget.id) {
|
||||
widgetid = widget.id.match(/Widget\[(.+?)\]\[([0-9]+)\]/i);
|
||||
if(widgetid && parseInt(widgetid[2]) > parseInt(parentRef.data('maxid'))) {
|
||||
parentRef.data('maxid', parseInt(widgetid[2]));
|
||||
}
|
||||
forcePlaceholderSize: true,
|
||||
start: function (e, ui) {
|
||||
htmleditors = $(ui.item).closest('.Widget').find('textarea.htmleditor');
|
||||
$.each(htmleditors, function (k, i) {
|
||||
tinyMCE.execCommand('mceRemoveControl', false, $(i).attr('id'));
|
||||
})
|
||||
},
|
||||
stop: function (e, ui) {
|
||||
htmleditors = $(ui.item).closest('.Widget').find('textarea.htmleditor');
|
||||
$.each(htmleditors, function (k, i) {
|
||||
tinyMCE.execCommand('mceAddControl', true, $(i).attr('id'));
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Ensure correct sort values are written when page is saved
|
||||
// TODO Adjust to new event listeners
|
||||
$('.cms-container').bind('submitform', function(e) {parentRef.beforeSave(e)});
|
||||
|
@ -58,17 +57,13 @@
|
|||
if (!widget.rewritten && (widget.id || widget.name)) {
|
||||
if (widget.id && widget.id.indexOf('Widget[') === 0) {
|
||||
var newValue = widget.id.replace(/Widget\[/, 'Widget['+name+'][');
|
||||
//console.log('Renaming '+widget.tagName+' ID '+widget.id+' to '+newValue);
|
||||
widget.id = newValue;
|
||||
}
|
||||
if (widget.name && widget.name.indexOf('Widget[') === 0) {
|
||||
var newValue = widget.name.replace(/Widget\[/, 'Widget['+name+'][');
|
||||
//console.log('Renaming '+widget.tagName+' Name '+widget.name+' to '+newValue);
|
||||
widget.name=newValue;
|
||||
}
|
||||
widget.rewritten='yes';
|
||||
}else {
|
||||
//console.log('Skipping '+(widget.id ? widget.id : (widget.name ? widget.name : 'unknown '+widget.tagName)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -130,13 +125,8 @@
|
|||
},
|
||||
|
||||
insertWidgetEditor: function(response) {
|
||||
var usedWidgets = $('#usedWidgets-'+$(this).attr('name')).children();
|
||||
|
||||
// Give the widget a unique id
|
||||
var newID=parseInt($(this).data('maxid'))+1;
|
||||
$(this).data('maxid', newID);
|
||||
|
||||
var widgetContent = response.replace(/Widget\[0\]/gi, "Widget[new-" + (newID) + "]");
|
||||
var newID = $(response).find('.formid').val();
|
||||
var widgetContent = response.replace(/Widget\[0\]/gi, "Widget[" + (newID) + "]");
|
||||
$('#usedWidgets-'+$(this).attr('name')).append(widgetContent);
|
||||
|
||||
this.rewriteWidgetAreaAttributes();
|
||||
|
|
14
lang/ar.yml
14
lang/ar.yml
|
@ -1,16 +1,16 @@
|
|||
ar:
|
||||
Widget:
|
||||
PLURALNAME: تطبيقات مصغرة
|
||||
SINGULARNAME: تطبيق مصغر
|
||||
WidgetArea:
|
||||
PLURALNAME: 'مساحات التطبيقات المصغرة'
|
||||
SINGULARNAME: 'مساحة التطبيقات المصغرة'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'التطبيقات المصغرة المتاحة'
|
||||
AVAILWIDGETS: 'اضغط على عنوان تطبيق مصغر بالأسفل لاستخدامه بهذه الصفحة.'
|
||||
INUSE: 'التطبيقات المصغرة المستخدمة حاليا'
|
||||
NOAVAIL: 'لا توجد حاليا أية تطبيقات مصغرة متاحة.'
|
||||
TOSORT: 'لترتيب التطبيقات المصغرة المستخدمة حاليا فى هذه الصفحة, اسحبها لأعلى و لأسفل.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: 'تطبيقات مصغرة'
|
||||
SINGULARNAME: 'تطبيق مصغر'
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'مساحات التطبيقات المصغرة'
|
||||
SINGULARNAME: 'مساحة التطبيقات المصغرة'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'اضغط لإضافة هذا التطبيق المصغر'
|
||||
WidgetEditor_ss:
|
||||
|
|
14
lang/de.yml
14
lang/de.yml
|
@ -1,16 +1,16 @@
|
|||
de:
|
||||
Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Widgetbereiche'
|
||||
SINGULARNAME: 'Widgetbereich'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Vorhandene Widgets'
|
||||
AVAILWIDGETS: 'Klicke den Widget Titel, um es zu benutzen.'
|
||||
INUSE: 'Benutzte Widgets'
|
||||
NOAVAIL: 'Es sind derzeit keine Widgets verfügbar.'
|
||||
TOSORT: 'Um die Widgets auf dieser Seite zu sortieren, ziehe sie nach oben oder unten.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: Widgetbereiche
|
||||
SINGULARNAME: Widgetbereich
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Klicke um dieses Widget hinzuzufügen'
|
||||
WidgetEditor_ss:
|
||||
|
|
22
lang/en.yml
22
lang/en.yml
|
@ -1,16 +1,24 @@
|
|||
en:
|
||||
Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Widget Areas'
|
||||
SINGULARNAME: 'Widget Area'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Extensions\WidgetPageExtension:
|
||||
INHERITSIDEBAR: 'Inherit Sidebar From Parent'
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Available Widgets'
|
||||
AVAILWIDGETS: 'Click a widget title below to use it on this page.'
|
||||
INUSE: 'Widgets currently used'
|
||||
NOAVAIL: 'There are currently no widgets available.'
|
||||
TOSORT: 'To sort currently used widgets on this page, drag them up and down.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgets
|
||||
PLURALS:
|
||||
one: 'A Widget'
|
||||
other: '{count} Widgets'
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Widget Areas'
|
||||
PLURALS:
|
||||
one: 'A Widget Area'
|
||||
other: '{count} Widget Areas'
|
||||
SINGULARNAME: 'Widget Area'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Click to add this widget'
|
||||
WidgetEditor_ss:
|
||||
|
|
22
lang/eo.yml
22
lang/eo.yml
|
@ -1,16 +1,24 @@
|
|||
eo:
|
||||
Widget:
|
||||
PLURALNAME: Fenestraĵoj
|
||||
SINGULARNAME: Fenestraĵo
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Fenestraĵaj zonoj'
|
||||
SINGULARNAME: 'Fenestraĵa zono'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Extensions\WidgetPageExtension:
|
||||
INHERITSIDEBAR: 'Heredi flankpanelon el patro'
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Disponeblaj fenestraĵoj'
|
||||
AVAILWIDGETS: 'Alklaku sube titolon de fenestraĵo por uzi ĝin en ĉi tiu paĝo.'
|
||||
INUSE: 'Fenestraĵoj aktuale uzataj'
|
||||
NOAVAIL: 'Aktuale mankas disponeblaj fenestraĵoj.'
|
||||
TOSORT: 'Por ordigi aktuale uzatajn fenestraĵojn en ĉi tiu paĝo, ŝovu ilin supren kaj malsupren.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Fenestraĵoj
|
||||
PLURALS:
|
||||
one: 'Unu fenestraĵo'
|
||||
other: '{count} fenestraĵoj'
|
||||
SINGULARNAME: Fenestraĵo
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Fenestraĵaj zonoj'
|
||||
PLURALS:
|
||||
one: 'Unu fenestraĵa zono'
|
||||
other: '{count} fenestraĵaj zonoj'
|
||||
SINGULARNAME: 'Fenestraĵa zono'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Alklaku por aldoni la fenestraĵon'
|
||||
WidgetEditor_ss:
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
fa_IR:
|
||||
Widget:
|
||||
PLURALNAME: ویجت ها
|
||||
SINGULARNAME: ویجت
|
||||
WidgetArea:
|
||||
PLURALNAME: 'محیط ویجت ها'
|
||||
SINGULARNAME: 'محیط ویجت'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'ویجت های موجود'
|
||||
AVAILWIDGETS: 'بر روی عنوان یک ویجت در پایین کلیک کنید تا آن را در این صفحه بکار بگیرید.'
|
||||
INUSE: 'ویجت هایی که در حال حاضر استفاده می شوند'
|
||||
NOAVAIL: 'در حال حاضر هیچ ویجتی موجود نیست.'
|
||||
TOSORT: 'برای مرتب سازی ویجت های این صفحه، آنها را بالا و پایین بکشید.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: 'ویجت ها'
|
||||
SINGULARNAME: ویجت
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'محیط ویجت ها'
|
||||
SINGULARNAME: 'محیط ویجت'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'برای افزودن این ویجت کلیک کنید'
|
||||
WidgetEditor_ss:
|
||||
|
|
14
lang/fi.yml
14
lang/fi.yml
|
@ -1,16 +1,16 @@
|
|||
fi:
|
||||
Widget:
|
||||
PLURALNAME: Vimpaimet
|
||||
SINGULARNAME: Vimpain
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Vimpain alueet'
|
||||
SINGULARNAME: 'Vimpain alue'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Käytettävissä olevat vimpaimet'
|
||||
AVAILWIDGETS: 'Napsauta vimpaimen otsikkoa alla ottaaksesi se käyttöön tällä sivulla.'
|
||||
INUSE: 'Käytössä olevat vimpaimet'
|
||||
NOAVAIL: 'Tällä hetkellä ei vimpaimia tarjolla.'
|
||||
TOSORT: 'Järjestääksesi käytössä olevat vimpaimet, raahaa ja pudota ne paikoilleen.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Vimpaimet
|
||||
SINGULARNAME: Vimpain
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Vimpain alueet'
|
||||
SINGULARNAME: 'Vimpain alue'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Napsauta lisätäksesi tämä vimpain'
|
||||
WidgetEditor_ss:
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
fi_FI:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Käytettävissä olevat vimpaimet'
|
||||
AVAILWIDGETS: 'Napsauta vimpaimen otsikkoa alla ottaaksesi se käyttöön tällä sivulla.'
|
||||
INUSE: 'Käytössä olevat vimpaimet'
|
||||
NOAVAIL: 'Tällä hetkellä ei vimpaimia tarjolla.'
|
||||
TOSORT: 'Järjestääksesi käytössä olevat vimpaimet, raahaa ja pudota ne paikoilleen.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Vimpaimet
|
||||
SINGULARNAME: Vimpain
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Vimpain alueet'
|
||||
SINGULARNAME: 'Vimpain alue'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Napsauta lisätäksesi tämä vimpain'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Poista
|
|
@ -0,0 +1,17 @@
|
|||
hr:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Dostupni widgeti'
|
||||
AVAILWIDGETS: 'Kliknite na naziv widgeta ispod za korištenje na ovoj stranici'
|
||||
INUSE: 'Trenutno korišteni widgeti'
|
||||
NOAVAIL: 'Trenutno nema dostupnih widgeta.'
|
||||
TOSORT: 'Za sortiranje trenutno korištenih widgeta na ovoj stranici, rasporedite ih povlačeći gore i dolje.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgeti
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Zone widgeta'
|
||||
SINGULARNAME: 'Zona widgeta'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Klikni za dodavanje ovog widgeta'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Obriši
|
|
@ -0,0 +1,5 @@
|
|||
id_ID:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Widget Tersedia'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Hapus
|
|
@ -0,0 +1,17 @@
|
|||
it:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Widget Disponibili'
|
||||
AVAILWIDGETS: 'Clickare sul titolo di un widget per usarlo in questa pagina'
|
||||
INUSE: 'Widget attualmente in uso'
|
||||
NOAVAIL: 'Attualmente non ci sono widget disponibili'
|
||||
TOSORT: 'Per riordinare i widget usati in questa pagina, trascinarli in alto o in basso.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widget
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Aree Widget'
|
||||
SINGULARNAME: 'Area Widget'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Clickare per aggiungere questo widget'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Elimina
|
|
@ -1,16 +1,16 @@
|
|||
it_IT:
|
||||
Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Aree Widget'
|
||||
SINGULARNAME: 'Area Widget'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Widgets disponibili'
|
||||
AVAILWIDGETS: 'Clicca sul titolo di un widget qui sotto per usarlo in questa pagina'
|
||||
INUSE: 'Widgets attualmente utilizzati'
|
||||
NOAVAIL: 'Non ci sono widgets attualmente disponibili.'
|
||||
TOSORT: 'Per ordinare i widgets utilizzati in questa pagina, trascinali in alto o in basso.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Aree Widget'
|
||||
SINGULARNAME: 'Area Widget'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Clicca per aggiungere questo widget'
|
||||
WidgetEditor_ss:
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
nl:
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Beschikbare Widgets'
|
||||
AVAILWIDGETS: 'Klik op een widget titel hieronder, om de widget te gebruiken op deze pagina.'
|
||||
INUSE: 'Huidige gebruikte Widgets'
|
||||
NOAVAIL: 'Er zijn geen widgets beschikbaar.'
|
||||
TOSORT: 'Om uw widgets te sorteren op deze pagina, rangschik met drag & drop.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Widget plaatsen'
|
||||
SINGULARNAME: 'Widget plaats'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Klik om deze widget toe te voegen'
|
||||
WidgetEditor_ss:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pl_PL:
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Dostępne widżety'
|
||||
AVAILWIDGETS: 'Kliknij w tytuł widżetu, aby używać go na tej stronie.'
|
||||
INUSE: 'Obecnie stosowane widżety'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
ro_RO:
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Widget-uri disponibile'
|
||||
AVAILWIDGETS: 'Faceți clic pe un titlu widget de mai jos pentru a-l folosi pe aceasta pagina.'
|
||||
INUSE: 'Widget-uri utilizate în prezent'
|
||||
|
|
14
lang/ru.yml
14
lang/ru.yml
|
@ -1,16 +1,16 @@
|
|||
ru:
|
||||
Widget:
|
||||
PLURALNAME: Виджеты
|
||||
SINGULARNAME: Виджет
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Области виджетов'
|
||||
SINGULARNAME: 'Область виджета'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Доступные виджеты'
|
||||
AVAILWIDGETS: 'Щелкните заголовок виджета ниже, чтобы использовать его на этой странице.'
|
||||
INUSE: 'Используемые виджеты'
|
||||
NOAVAIL: 'В данный момент доступных виджетов нет.'
|
||||
TOSORT: 'Чтобы расположить используемые на странице виджеты в нужном порядке, перетащите их вверх или вниз.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Виджеты
|
||||
SINGULARNAME: Виджет
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Области виджетов'
|
||||
SINGULARNAME: 'Область виджета'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Щелкните, чтобы добавить этот виджет'
|
||||
WidgetEditor_ss:
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
sk:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Dostupné widgety'
|
||||
AVAILWIDGETS: 'Kliknite na názov widgetu pre jeho použitie na tejto stránke.'
|
||||
INUSE: 'Momentálne používané widgety.'
|
||||
NOAVAIL: 'Momentálne nie sú dostupné žiadne widgety.'
|
||||
TOSORT: 'Pre zotriedenie momentálne používaných widgetov na tejto stránke, potiahnite ich hore alebo dole.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgety
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Oblasti widgetu'
|
||||
SINGULARNAME: 'Oblasť widgetu'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Kliknite pre pridanie tohto widgetu'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Vymazať
|
|
@ -0,0 +1,17 @@
|
|||
sl:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Vtičniki, ki so na voljo'
|
||||
AVAILWIDGETS: 'Spodaj izberite vtičnik, ki ga želite uporabiti na strani.'
|
||||
INUSE: 'Vtičniki v uporabi'
|
||||
NOAVAIL: 'Na voljo ni nobenega vtičnika.'
|
||||
TOSORT: 'Za razvrstitev vtičnikov na strani jih povlecite na ustrezno mesto. '
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Vtičniki
|
||||
SINGULARNAME: Vtičnik
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 'Prostori za vtičnike'
|
||||
SINGULARNAME: 'Prostor za vtičnike'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Kliknite na ta vtičnik, če ga želite dodati'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Odstrani
|
14
lang/sv.yml
14
lang/sv.yml
|
@ -1,16 +1,16 @@
|
|||
sv:
|
||||
Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Widgetområden'
|
||||
SINGULARNAME: 'Widgetområde'
|
||||
WidgetAreaEditor_ss:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Tillgängliga widgets'
|
||||
AVAILWIDGETS: 'Klicka på en widget nedan för att använda den på sidan.'
|
||||
INUSE: 'Använda widgets'
|
||||
NOAVAIL: 'Inga widgets tillängliga.'
|
||||
TOSORT: 'För att sortera widgetar på denna sida, dra dem uppåt eller nedåt.'
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: Widgetområden
|
||||
SINGULARNAME: Widgetområde
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Klicka för att lägga till denna widget'
|
||||
WidgetEditor_ss:
|
||||
|
|
22
lang/zh.yml
22
lang/zh.yml
|
@ -1,17 +1,17 @@
|
|||
zh:
|
||||
Widget:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 可用的小工具
|
||||
AVAILWIDGETS: 点击下方的小工具名称即可在此页上使用。
|
||||
INUSE: 当前使用的小工具
|
||||
NOAVAIL: 目前没有可用小工具。
|
||||
TOSORT: 要对本页当前使用的小工具进行排序,请像上下拖拽。
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: 小工具
|
||||
SINGULARNAME: 小工具
|
||||
WidgetArea:
|
||||
PLURALNAME: '小工具区域'
|
||||
SINGULARNAME: '小工具区域'
|
||||
WidgetAreaEditor_ss:
|
||||
AVAILABLE: '可用的小工具'
|
||||
AVAILWIDGETS: '点击下方的小工具名称即可在此页上使用。'
|
||||
INUSE: '当前使用的小工具'
|
||||
NOAVAIL: '目前没有可用小工具。'
|
||||
TOSORT: '要对本页当前使用的小工具进行排序,请像上下拖拽。'
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 小工具区域
|
||||
SINGULARNAME: 小工具区域
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: '点击添加该小工具'
|
||||
CLICKTOADDWIDGET: 点击添加该小工具
|
||||
WidgetEditor_ss:
|
||||
DELETE: 删除
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
zh_CN:
|
||||
SilverStripe\Widgets\Forms\WidgetAreaEditor_ss:
|
||||
AVAILABLE: 有效插件
|
||||
AVAILWIDGETS: 点击一个插件标题应用在当前页面
|
||||
INUSE: 当前已使用插件
|
||||
NOAVAIL: 当前无有效插件
|
||||
TOSORT: 请上下拖动当前页面的对应插件进行排序
|
||||
SilverStripe\Widgets\Model\Widget:
|
||||
PLURALNAME: 插件
|
||||
SINGULARNAME: 插件
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
PLURALNAME: 插件区域
|
||||
SINGULARNAME: 插件区域
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 点击增加该插件
|
||||
WidgetEditor_ss:
|
||||
DELETE: 删除
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2016, SilverStripe Limited
|
||||
Copyright (c) 2017, SilverStripe Limited
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ruleset name="SilverStripe">
|
||||
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
|
||||
|
||||
<file>src</file>
|
||||
<file>tests</file>
|
||||
|
||||
<rule ref="PSR2">
|
||||
<!-- Current exclusions -->
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName"/>
|
||||
</rule>
|
||||
</ruleset>
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Default">
|
||||
<directory>tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist addUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src/</directory>
|
||||
<exclude>
|
||||
<directory suffix=".php">tests/</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
|
@ -3,7 +3,7 @@
|
|||
// root widget area editor container
|
||||
.WidgetAreaEditor {
|
||||
h2 {
|
||||
|
||||
|
||||
}
|
||||
p {
|
||||
margin-bottom: 15px;
|
||||
|
@ -12,40 +12,36 @@
|
|||
|
||||
// base styles for a widget
|
||||
.Widget {
|
||||
padding: 0 7px 7px 7px;
|
||||
padding: 0 1.25rem .75rem;
|
||||
margin: 16px 0 16px 0;
|
||||
color: #1f1f1f;
|
||||
background-color: #b0bec7;
|
||||
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2IwYmVjNyIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzkyYTViMiIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
|
||||
background-size: 100%;
|
||||
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #b0bec7), color-stop(100%, #92a5b2));
|
||||
background-image: -webkit-linear-gradient(#b0bec7, #92a5b2);
|
||||
background-image: -moz-linear-gradient(#b0bec7, #92a5b2);
|
||||
background-image: -o-linear-gradient(#b0bec7, #92a5b2);
|
||||
background-image: linear-gradient(#b0bec7, #92a5b2);
|
||||
border-top: 1px solid #c2cdd4;
|
||||
border-bottom: 1px solid #748d9d;
|
||||
color: #4F5861;
|
||||
background-color: #F1F3F6;
|
||||
border: 1px solid #ced5e1;
|
||||
@include border-radius(3px);
|
||||
h3 {
|
||||
color: #43536d;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
padding: 4px 0;
|
||||
line-height: 40px;
|
||||
text-shadow: #bfcad2 1px 1px 0;
|
||||
@include transition-property(background-image);
|
||||
@include transition-duration(0.2s);
|
||||
@include transition-timing-function(ease-out);
|
||||
}
|
||||
.widgetDescription {
|
||||
background: #eceff1;
|
||||
padding: 5px 5px 1px 5px;
|
||||
padding: 0 0 .5rem;
|
||||
margin: 0;
|
||||
@include border-radius(3px);
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
.widgetFields {
|
||||
background: #eceff1;
|
||||
padding: 5px;
|
||||
margin: 7px 0 0 0;
|
||||
@include border-radius(3px);
|
||||
background: #F7F8FA;
|
||||
border-top: 1px solid #dbe0e9;
|
||||
border-bottom: 1px solid #dbe0e9;
|
||||
padding: .75rem 1.25rem;
|
||||
margin: .75rem -1.25rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +85,7 @@
|
|||
}
|
||||
|
||||
.noWidgets {
|
||||
|
||||
|
||||
}
|
||||
|
||||
// one column layout when space is limited
|
||||
|
@ -103,4 +99,4 @@
|
|||
width: 100%;
|
||||
float: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Controllers;
|
||||
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
/**
|
||||
* Add this to ContentController to enable widgets
|
||||
*
|
||||
|
@ -13,16 +19,16 @@ class WidgetContentControllerExtension extends Extension
|
|||
private static $allowed_actions = array(
|
||||
'handleWidget'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Handles widgets attached to a page through one or more {@link WidgetArea}
|
||||
* elements.
|
||||
*
|
||||
* Iterated through each $has_one relation with a {@link WidgetArea} and
|
||||
* Iterated through each $has_one relation with a {@link WidgetArea} and
|
||||
* looks for connected widgets by their database identifier.
|
||||
*
|
||||
*
|
||||
* Assumes URLs in the following format: <URLSegment>/widget/<Widget-ID>.
|
||||
*
|
||||
*
|
||||
* @return RequestHandler
|
||||
*/
|
||||
public function handleWidget()
|
||||
|
@ -31,17 +37,22 @@ class WidgetContentControllerExtension extends Extension
|
|||
if (!$SQL_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var SiteTree $widgetOwner */
|
||||
$widgetOwner = $this->owner->data();
|
||||
while ($widgetOwner->InheritSideBar && $widgetOwner->Parent()->exists()) {
|
||||
$widgetOwner = $widgetOwner->Parent();
|
||||
}
|
||||
|
||||
// find WidgetArea relations
|
||||
$widgetAreaRelations = array();
|
||||
$hasOnes = $this->owner->data()->hasOne();
|
||||
|
||||
$hasOnes = $widgetOwner->hasOne();
|
||||
|
||||
if (!$hasOnes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($hasOnes as $hasOneName => $hasOneClass) {
|
||||
if ($hasOneClass == 'WidgetArea' || is_subclass_of($hasOneClass, 'WidgetArea')) {
|
||||
if ($hasOneClass == WidgetArea::class || is_subclass_of($hasOneClass, WidgetArea::class)) {
|
||||
$widgetAreaRelations[] = $hasOneName;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +65,7 @@ class WidgetContentControllerExtension extends Extension
|
|||
break;
|
||||
}
|
||||
|
||||
$widget = $this->owner->data()->$widgetAreaRelation()->Widgets()
|
||||
$widget = $widgetOwner->$widgetAreaRelation()->Widgets()
|
||||
->filter('ID', $SQL_id)
|
||||
->First();
|
||||
}
|
||||
|
@ -62,7 +73,7 @@ class WidgetContentControllerExtension extends Extension
|
|||
if (!$widget) {
|
||||
user_error('No widget found', E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
return $widget->getController();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Extensions;
|
||||
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
/**
|
||||
* Adds a single {@link WidgetArea} called "SideBar" to {@link Page} classes.
|
||||
* Adjust your templates to render the resulting
|
||||
|
@ -10,23 +19,31 @@
|
|||
*/
|
||||
class WidgetPageExtension extends DataExtension
|
||||
{
|
||||
private static $db = array(
|
||||
private static $db = [
|
||||
'InheritSideBar' => 'Boolean',
|
||||
);
|
||||
];
|
||||
|
||||
private static $defaults = array(
|
||||
private static $defaults = [
|
||||
'InheritSideBar' => true
|
||||
);
|
||||
];
|
||||
|
||||
private static $has_one = array(
|
||||
'SideBar' => 'WidgetArea'
|
||||
);
|
||||
private static $has_one = [
|
||||
'SideBar' => WidgetArea::class,
|
||||
];
|
||||
|
||||
private static $owns = [
|
||||
'SideBar',
|
||||
];
|
||||
|
||||
private static $cascade_deletes = [
|
||||
'SideBar',
|
||||
];
|
||||
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
$fields->addFieldToTab(
|
||||
"Root.Widgets",
|
||||
new CheckboxField("InheritSideBar", 'Inherit Sidebar From Parent')
|
||||
new CheckboxField("InheritSideBar", _t(__CLASS__ . '.INHERITSIDEBAR', 'Inherit Sidebar From Parent'))
|
||||
);
|
||||
$fields->addFieldToTab(
|
||||
"Root.Widgets",
|
||||
|
@ -39,8 +56,7 @@ class WidgetPageExtension extends DataExtension
|
|||
*/
|
||||
public function SideBarView()
|
||||
{
|
||||
if (
|
||||
$this->owner->InheritSideBar
|
||||
if ($this->owner->InheritSideBar
|
||||
&& ($parent = $this->owner->getParent())
|
||||
&& $parent->hasMethod('SideBarView')
|
||||
) {
|
||||
|
@ -49,7 +65,7 @@ class WidgetPageExtension extends DataExtension
|
|||
return $this->owner->SideBar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function onBeforeDuplicate($duplicatePage)
|
||||
{
|
||||
if ($this->owner->hasField('SideBarID')) {
|
||||
|
@ -67,13 +83,4 @@ class WidgetPageExtension extends DataExtension
|
|||
|
||||
return $duplicatePage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support Translatable so that we don't link WidgetAreas across translations
|
||||
*/
|
||||
public function onTranslatableCreate()
|
||||
{
|
||||
//reset the sidebar ID
|
||||
$this->owner->SideBarID = 0;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Forms;
|
||||
|
||||
use Exception;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Forms\FormField;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataObjectInterface;
|
||||
use SilverStripe\View\Requirements;
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
/**
|
||||
* Special field type for selecting and configuring widgets on a page.
|
||||
*
|
||||
|
@ -12,11 +24,11 @@ class WidgetAreaEditor extends FormField
|
|||
* @param array $widgetClasses
|
||||
* @param int $maxWidgets
|
||||
*/
|
||||
public function __construct($name, $widgetClasses = array('Widget'), $maxWidgets = 0)
|
||||
public function __construct($name, $widgetClasses = array(Widget::class), $maxWidgets = 0)
|
||||
{
|
||||
$this->MaxWidgets = $maxWidgets;
|
||||
$this->widgetClasses = $widgetClasses;
|
||||
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
|
||||
|
@ -27,10 +39,10 @@ class WidgetAreaEditor extends FormField
|
|||
*/
|
||||
public function FieldHolder($properties = array())
|
||||
{
|
||||
Requirements::css('widgets/css/WidgetAreaEditor.css');
|
||||
Requirements::javascript('widgets/javascript/WidgetAreaEditor.js');
|
||||
Requirements::css('silverstripe/widgets:css/WidgetAreaEditor.css');
|
||||
Requirements::javascript('silverstripe/widgets:javascript/WidgetAreaEditor.js');
|
||||
|
||||
return $this->renderWith("WidgetAreaEditor");
|
||||
return $this->renderWith(WidgetAreaEditor::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,17 +56,17 @@ class WidgetAreaEditor extends FormField
|
|||
foreach ($this->widgetClasses as $widgetClass) {
|
||||
$classes = ClassInfo::subclassesFor($widgetClass);
|
||||
|
||||
if (isset($classes['Widget'])) {
|
||||
unset($classes['Widget']);
|
||||
} elseif (isset($classes[0]) && $classes[0] == 'Widget') {
|
||||
if (isset($classes[strtolower(Widget::class)])) {
|
||||
unset($classes[strtolower(Widget::class)]);
|
||||
} elseif (isset($classes[0]) && $classes[0] == Widget::class) {
|
||||
unset($classes[0]);
|
||||
}
|
||||
|
||||
|
||||
foreach ($classes as $class) {
|
||||
$available = Config::inst()->get($class, 'only_available_in');
|
||||
|
||||
|
||||
if (!empty($available) && is_array($available)) {
|
||||
if (in_array($this->Name, $available)) {
|
||||
if (in_array($this->Name, $available ?? [])) {
|
||||
$widgets->push(singleton($class));
|
||||
}
|
||||
} else {
|
||||
|
@ -62,7 +74,7 @@ class WidgetAreaEditor extends FormField
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $widgets;
|
||||
}
|
||||
|
||||
|
@ -72,8 +84,8 @@ class WidgetAreaEditor extends FormField
|
|||
public function UsedWidgets()
|
||||
{
|
||||
// Call class_exists() to load Widget.php earlier and avoid a segfault
|
||||
class_exists('Widget');
|
||||
|
||||
class_exists(Widget::class);
|
||||
|
||||
$relationName = $this->name;
|
||||
$widgets = $this->form->getRecord()->getComponent($relationName)->Items();
|
||||
|
||||
|
@ -101,6 +113,7 @@ class WidgetAreaEditor extends FormField
|
|||
|
||||
/**
|
||||
* @param DataObjectInterface $record
|
||||
* @throws Exception if no form could be retrieved
|
||||
*/
|
||||
public function saveInto(DataObjectInterface $record)
|
||||
{
|
||||
|
@ -109,15 +122,15 @@ class WidgetAreaEditor extends FormField
|
|||
|
||||
$widgetarea = $record->getComponent($name);
|
||||
$widgetarea->write();
|
||||
|
||||
|
||||
$record->$idName = $widgetarea->ID;
|
||||
|
||||
|
||||
$widgets = $widgetarea->Items();
|
||||
|
||||
|
||||
// store the field IDs and delete the missing fields
|
||||
// alternatively, we could delete all the fields and re add them
|
||||
$missingWidgets = array();
|
||||
|
||||
|
||||
if ($widgets) {
|
||||
foreach ($widgets as $existingWidget) {
|
||||
$missingWidgets[$existingWidget->ID] = $existingWidget;
|
||||
|
@ -128,12 +141,11 @@ class WidgetAreaEditor extends FormField
|
|||
throw new Exception("no form");
|
||||
}
|
||||
|
||||
$widgetData = $this->getForm()->getRequest()->requestVar('Widget');
|
||||
$widgetData = $this->getForm()->getController()->getRequest()->requestVar('Widget');
|
||||
if ($widgetData && isset($widgetData[$this->getName()])) {
|
||||
$widgetAreaData = $widgetData[$this->getName()];
|
||||
|
||||
foreach ($widgetAreaData as $newWidgetID => $newWidgetData) {
|
||||
|
||||
// Sometimes the id is "new-1" or similar, ensure this doesn't get into the query
|
||||
if (!is_numeric($newWidgetID)) {
|
||||
$newWidgetID = 0;
|
||||
|
@ -152,11 +164,17 @@ class WidgetAreaEditor extends FormField
|
|||
}
|
||||
}
|
||||
|
||||
// unsantise the class name
|
||||
if (empty($newWidgetData['Type'])) {
|
||||
$newWidgetData['Type'] = '';
|
||||
}
|
||||
$newWidgetData['Type'] = str_replace('_', '\\', $newWidgetData['Type'] ?? '');
|
||||
|
||||
// create a new object
|
||||
if (!$widget
|
||||
&& !empty($newWidgetData['Type'])
|
||||
&& class_exists($newWidgetData['Type'])
|
||||
&& is_subclass_of($newWidgetData['Type'], 'Widget')
|
||||
&& class_exists($newWidgetData['Type'] ?? '')
|
||||
&& is_subclass_of($newWidgetData['Type'], Widget::class)
|
||||
) {
|
||||
$widget = Injector::inst()->create($newWidgetData['Type']);
|
||||
$widget->ID = 0;
|
||||
|
@ -167,12 +185,11 @@ class WidgetAreaEditor extends FormField
|
|||
if ($widget->ParentID == 0) {
|
||||
$widget->ParentID = $record->$name()->ID;
|
||||
}
|
||||
|
||||
$widget->populateFromPostData($newWidgetData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove the fields not saved
|
||||
if ($missingWidgets) {
|
||||
foreach ($missingWidgets as $removedWidget) {
|
|
@ -1,60 +1,55 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Model;
|
||||
|
||||
use Exception;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\SSViewer;
|
||||
|
||||
/**
|
||||
* Widgets let CMS authors drag and drop small pieces of functionality into
|
||||
* Widgets let CMS authors drag and drop small pieces of functionality into
|
||||
* defined areas of their websites.
|
||||
*
|
||||
*
|
||||
* You can use forms in widgets by implementing a {@link WidgetController}.
|
||||
*
|
||||
* See {@link Widget_Controller} for more information.
|
||||
*
|
||||
*
|
||||
* See {@link WidgetController} for more information.
|
||||
*
|
||||
* @package widgets
|
||||
*/
|
||||
class Widget extends DataObject
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
private static $db = [
|
||||
"Title" => "Varchar(255)",
|
||||
"Sort" => "Int",
|
||||
"Enabled" => "Boolean",
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $defaults = array(
|
||||
private static $defaults = [
|
||||
'Enabled' => true,
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $casting = array(
|
||||
private static $casting = [
|
||||
'CMSTitle' => 'Text',
|
||||
'Description' => 'Text',
|
||||
);
|
||||
|
||||
private static $only_available_in = array();
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = array(
|
||||
"Parent" => "WidgetArea",
|
||||
);
|
||||
private static $only_available_in = [];
|
||||
|
||||
private static $has_one = [
|
||||
"Parent" => WidgetArea::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $default_sort = "\"Sort\"";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $title = "Widget Title";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -65,12 +60,15 @@ class Widget extends DataObject
|
|||
*/
|
||||
private static $description = "Description of what this widget does.";
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $summary_fields = array(
|
||||
private static $summary_fields = [
|
||||
'CMSTitle' => 'Title'
|
||||
);
|
||||
];
|
||||
|
||||
private static $table_name = 'Widget';
|
||||
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var WidgetController
|
||||
|
@ -82,10 +80,10 @@ class Widget extends DataObject
|
|||
parent::populateDefaults();
|
||||
$this->setField('Title', $this->getTitle());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Note: Overloaded in {@link WidgetController}.
|
||||
*
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function WidgetHolder()
|
||||
|
@ -102,52 +100,24 @@ class Widget extends DataObject
|
|||
if ($holder) {
|
||||
return $this->WidgetHolder();
|
||||
}
|
||||
|
||||
return $this->Content();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the widget content in a custom template with the same name as the
|
||||
* Renders the widget content in a custom template with the same name as the
|
||||
* current class. This should be the main point of output customization.
|
||||
*
|
||||
* Invoked from within WidgetHolder.ss, which contains the "framing" around
|
||||
*
|
||||
* Invoked from within WidgetHolder.ss, which contains the "framing" around
|
||||
* the custom content, like a title.
|
||||
*
|
||||
*
|
||||
* Note: Overloaded in {@link WidgetController}.
|
||||
*
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function Content()
|
||||
{
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry($this->class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public function Title()
|
||||
{
|
||||
return $this->getTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the frontend title for this widget
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->getField('Title')
|
||||
?: _t($this->class.'.TITLE', $this->config()->title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public function CMSTitle()
|
||||
{
|
||||
return $this->getCMSTitle();
|
||||
return $this->renderWith(SSViewer::get_templates_by_class(static::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,16 +125,7 @@ class Widget extends DataObject
|
|||
*/
|
||||
public function getCMSTitle()
|
||||
{
|
||||
return _t($this->class.'.CMSTITLE', $this->config()->cmsTitle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
public function Description()
|
||||
{
|
||||
return $this->getDescription();
|
||||
return _t(__CLASS__ . '.CMSTITLE', $this->config()->get('cmsTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,7 +133,7 @@ class Widget extends DataObject
|
|||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return _t($this->class.'.DESCRIPTION', $this->config()->description);
|
||||
return _t(__CLASS__ . '.DESCRIPTION', $this->config()->get('description'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,7 +143,7 @@ class Widget extends DataObject
|
|||
{
|
||||
return $this->renderWith('WidgetDescription');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see WidgetController::editablesegment()
|
||||
*
|
||||
|
@ -203,9 +164,10 @@ class Widget extends DataObject
|
|||
new CheckboxField('Enabled', $this->fieldLabel('Enabled'))
|
||||
);
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
|
@ -214,14 +176,24 @@ class Widget extends DataObject
|
|||
$fields = $this->getCMSFields();
|
||||
$outputFields = new FieldList();
|
||||
|
||||
$this->FormID = $this->ID ?: uniqid();
|
||||
$outputFields->push(
|
||||
HiddenField::create(
|
||||
'Widget[' . $this->FormID . '][FormID]',
|
||||
'FormID',
|
||||
$this->FormID
|
||||
)->addExtraClass('formid')
|
||||
);
|
||||
|
||||
foreach ($fields as $field) {
|
||||
$name = $field->getName();
|
||||
$value = $this->getField($name);
|
||||
if ($value) {
|
||||
$field->setValue($value);
|
||||
}
|
||||
$name = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->ID . "][\\1]", $name);
|
||||
$field->setName($name);
|
||||
$namefiltered = preg_replace("/([A-Za-z0-9\-_]+)/", "Widget[" . $this->FormID . "][\\1]", $name ?? '');
|
||||
|
||||
$field->setName($namefiltered);
|
||||
$outputFields->push($field);
|
||||
}
|
||||
|
||||
|
@ -229,11 +201,14 @@ class Widget extends DataObject
|
|||
}
|
||||
|
||||
/**
|
||||
* A fully qualified class name is returned with underscores instead of backslashes so it is HTML safe. Dashes
|
||||
* can't be used as they're handled in the Javascript for other purposes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function ClassName()
|
||||
{
|
||||
return $this->class;
|
||||
return str_replace('\\', '_', get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,11 +216,11 @@ class Widget extends DataObject
|
|||
*/
|
||||
public function Name()
|
||||
{
|
||||
return "Widget[".$this->ID."]";
|
||||
return "Widget[" . $this->ID . "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws Exception If the widget controller's class name couldn't be found
|
||||
*
|
||||
* @return WidgetController
|
||||
*/
|
||||
|
@ -255,29 +230,25 @@ class Widget extends DataObject
|
|||
return $this->controller;
|
||||
}
|
||||
|
||||
foreach (array_reverse(ClassInfo::ancestry($this->class)) as $widgetClass) {
|
||||
$controllerClass = "{$widgetClass}_Controller";
|
||||
|
||||
if (class_exists($controllerClass)) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (array_reverse(ClassInfo::ancestry(get_class($this)) ?? []) as $widgetClass) {
|
||||
$controllerClass = "{$widgetClass}Controller";
|
||||
|
||||
if (class_exists($controllerClass)) {
|
||||
if (class_exists($controllerClass ?? '')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!class_exists($controllerClass)) {
|
||||
throw new Exception("Could not find controller class for $this->classname");
|
||||
if (!class_exists($controllerClass ?? '')) {
|
||||
throw new Exception('Could not find controller class for ' . static::class);
|
||||
}
|
||||
|
||||
$this->controller = Injector::inst()->create($controllerClass, $this);
|
||||
if (Injector::inst()->has(HTTPRequest::class)) {
|
||||
$this->controller->setRequest(Injector::inst()->get(HTTPRequest::class));
|
||||
}
|
||||
|
||||
return $this->controller;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*/
|
||||
|
@ -294,19 +265,19 @@ class Widget extends DataObject
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Look for checkbox fields not present in the data
|
||||
foreach ($fields as $field) {
|
||||
if ($field instanceof CheckboxField && !array_key_exists($field->getName(), $data)) {
|
||||
if ($field instanceof CheckboxField && !array_key_exists($field->getName(), $data ?? [])) {
|
||||
$field->setValue(false);
|
||||
$field->saveInto($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->write();
|
||||
|
||||
|
||||
// The field must be written to ensure a unique ID.
|
||||
$this->Name = $this->class.$this->ID;
|
||||
$this->Name = get_class($this) . $this->ID;
|
||||
$this->write();
|
||||
}
|
||||
}
|
|
@ -1,41 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Model;
|
||||
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\HasManyList;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
||||
/**
|
||||
* Represents a set of widgets shown on a page.
|
||||
*
|
||||
* @package widgets
|
||||
*/
|
||||
class WidgetArea extends DataObject
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $has_many = array(
|
||||
"Widgets" => "Widget"
|
||||
);
|
||||
private static $has_many = [
|
||||
"Widgets" => Widget::class
|
||||
];
|
||||
|
||||
private static $owns = [
|
||||
'Widgets',
|
||||
];
|
||||
|
||||
private static $cascade_deletes = [
|
||||
'Widgets',
|
||||
];
|
||||
|
||||
private static $extensions = [
|
||||
Versioned::class,
|
||||
];
|
||||
|
||||
private static $table_name = 'WidgetArea';
|
||||
|
||||
public $template = __CLASS__;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $template = __CLASS__;
|
||||
|
||||
/**
|
||||
* Used in template instead of {@link Widgets()} to wrap each widget in its
|
||||
* controller, making it easier to access and process form logic and
|
||||
* Used in template instead of {@link Widgets()} to wrap each widget in its
|
||||
* controller, making it easier to access and process form logic and
|
||||
* actions stored in {@link WidgetController}.
|
||||
*
|
||||
*
|
||||
* @return SS_List - Collection of {@link WidgetController} instances.
|
||||
*/
|
||||
public function WidgetControllers()
|
||||
{
|
||||
$controllers = new ArrayList();
|
||||
$items = $this->ItemsToRender();
|
||||
if (!is_null($items)){
|
||||
if (!is_null($items)) {
|
||||
foreach ($items as $widget) {
|
||||
/** @var Widget $widget */
|
||||
|
||||
/** @var Controller $controller */
|
||||
$controller = $widget->getController();
|
||||
|
||||
$controller->init();
|
||||
$controller->doInit();
|
||||
$controllers->push($controller);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +64,7 @@ class WidgetArea extends DataObject
|
|||
*/
|
||||
public function Items()
|
||||
{
|
||||
return $this->getComponents('Widgets');
|
||||
return $this->Widgets();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,8 +72,7 @@ class WidgetArea extends DataObject
|
|||
*/
|
||||
public function ItemsToRender()
|
||||
{
|
||||
return $this->getComponents('Widgets')
|
||||
->filter("Enabled", 1);
|
||||
return $this->Items()->filter('Enabled', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,15 +91,4 @@ class WidgetArea extends DataObject
|
|||
{
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all connected Widgets when this WidgetArea gets deleted
|
||||
*/
|
||||
public function onBeforeDelete()
|
||||
{
|
||||
parent::onBeforeDelete();
|
||||
foreach ($this->Widgets() as $widget) {
|
||||
$widget->delete();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Model;
|
||||
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
|
||||
/**
|
||||
* Optional controller for every widget which has its own logic, e.g. in forms.
|
||||
* Optional controller for every widget which has its own logic, e.g. in forms.
|
||||
*
|
||||
* It always handles a single widget, usually passed in as a database
|
||||
* identifier through the controller URL. Needs to be constructed as a nested
|
||||
* It always handles a single widget, usually passed in as a database
|
||||
* identifier through the controller URL. Needs to be constructed as a nested
|
||||
* controller within a {@link ContentController}.
|
||||
*
|
||||
*
|
||||
* ## Forms
|
||||
* You can add forms like in any other SilverStripe controller. If you need
|
||||
* access to the widget from within a form, you can use
|
||||
* You can add forms like in any other SilverStripe controller. If you need
|
||||
* access to the widget from within a form, you can use
|
||||
* `$this->controller->getWidget()` inside the form logic.
|
||||
*
|
||||
* Note: Widget controllers currently only work on {@link Page} objects,
|
||||
* because the logic is implemented in {@link ContentController->handleWidget()}.
|
||||
* Copy this logic and the URL rules to enable it for other controllers.
|
||||
*
|
||||
*
|
||||
* @package widgets
|
||||
*/
|
||||
class WidgetController extends Controller
|
||||
|
@ -41,7 +48,7 @@ class WidgetController extends Controller
|
|||
$this->widget = $widget;
|
||||
$this->failover = $widget;
|
||||
}
|
||||
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -53,14 +60,36 @@ class WidgetController extends Controller
|
|||
{
|
||||
$id = ($this->widget) ? $this->widget->ID : null;
|
||||
$segment = Controller::join_links('widget', $id, $action);
|
||||
|
||||
if ($page = Director::get_current_page()) {
|
||||
|
||||
$page = Director::get_current_page();
|
||||
if ($page && !($page instanceof WidgetController)) {
|
||||
return $page->Link($segment);
|
||||
}
|
||||
|
||||
return Controller::curr()->Link($segment);
|
||||
|
||||
if ($controller = $this->getParentController()) {
|
||||
return $controller->Link($segment);
|
||||
}
|
||||
|
||||
return $segment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cycles up the controller stack until it finds a non-widget controller
|
||||
* This is needed becauseController::currreturns the widget controller,
|
||||
* which means anyLinkfunction turns into endless loop.
|
||||
*
|
||||
* @return Controller
|
||||
*/
|
||||
public function getParentController()
|
||||
{
|
||||
foreach (Controller::$controller_stack as $controller) {
|
||||
if (!($controller instanceof WidgetController)) {
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Widget
|
||||
*/
|
||||
|
@ -68,46 +97,47 @@ class WidgetController extends Controller
|
|||
{
|
||||
return $this->widget;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overloaded from {@link Widget->Content()} to allow for controller / form
|
||||
* Overloaded from {@link Widget->Content()} to allow for controller / form
|
||||
* linking.
|
||||
*
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function Content()
|
||||
{
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry($this->widget->class)));
|
||||
return $this->renderWith(array_reverse(ClassInfo::ancestry(get_class($this->widget)) ?? []));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Overloaded from {@link Widget->WidgetHolder()} to allow for controller/
|
||||
* Overloaded from {@link Widget->WidgetHolder()} to allow for controller/
|
||||
* form linking.
|
||||
*
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function WidgetHolder()
|
||||
{
|
||||
return $this->renderWith("WidgetHolder");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uses the `WidgetEditor.ss` template and {@link Widget->editablesegment()}
|
||||
* Uses the `WidgetEditor.ss` template and {@link Widget->editablesegment()}
|
||||
* to render a administrator-view of the widget. It is assumed that this
|
||||
* view contains form elements which are submitted and saved through
|
||||
* view contains form elements which are submitted and saved through
|
||||
* {@link WidgetAreaEditor} within the CMS interface.
|
||||
*
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function editablesegment()
|
||||
{
|
||||
$className = $this->urlParams['ID'];
|
||||
if (class_exists('Translatable') && Member::currentUserID()) {
|
||||
// set current locale based on logged in user's locale
|
||||
$locale = Member::currentUser()->Locale;
|
||||
i18n::set_locale($locale);
|
||||
}
|
||||
if (class_exists($className) && is_subclass_of($className, 'Widget')) {
|
||||
// use left and main to set the html config
|
||||
$leftandmain = LeftAndMain::create();
|
||||
$leftandmain->setRequest($this->getRequest());
|
||||
$leftandmain->doInit();
|
||||
|
||||
// Decode if fully qualified - @see Widget::ClassName
|
||||
$className = str_replace('_', '\\', $this->urlParams['ID'] ?? '');
|
||||
if (class_exists($className ?? '') && is_subclass_of($className, Widget::class)) {
|
||||
$obj = new $className();
|
||||
return $obj->EditableSegment();
|
||||
} else {
|
||||
|
@ -116,11 +146,3 @@ class WidgetController extends Controller
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use WidgetController
|
||||
* @package widgets
|
||||
*/
|
||||
class Widget_Controller extends WidgetController
|
||||
{
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<div class="WidgetAreaEditor field" id="WidgetAreaEditor-$Name" name="$Name"<% if $MaxWidgets %> maxwidgets="$MaxWidgets"<% end_if %>>
|
||||
<input type="hidden" id="$Name" name="$IdxField" value="$Value" />
|
||||
<div class="availableWidgetsHolder">
|
||||
<h2><%t SilverStripe\\Widgets\\Forms\\WidgetAreaEditor_ss.AVAILABLE 'Available Widgets' %></h2>
|
||||
<p class="message"><%t SilverStripe\\Widgets\\Forms\\WidgetAreaEditor_ss.AVAILWIDGETS 'Click a widget title below to use it on this page.' %></p>
|
||||
<div class="availableWidgets" id="availableWidgets-$Name">
|
||||
<% if $AvailableWidgets %>
|
||||
<% loop $AvailableWidgets %>
|
||||
$DescriptionSegment
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<div class="NoWidgets" id="NoWidgets-$Name">
|
||||
<p><%t SilverStripe\\Widgets\\Forms\\WidgetAreaEditor_ss.NOAVAIL 'There are currently no widgets available.' %></p>
|
||||
</div>
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="usedWidgetsHolder">
|
||||
<h2><%t SilverStripe\\Widgets\\Forms\\WidgetAreaEditor_ss.INUSE 'Widgets currently used' %></h2>
|
||||
<p class="message"><%t SilverStripe\\Widgets\\Forms\\WidgetAreaEditor_ss.TOSORT 'To sort currently used widgets on this page, drag them up and down.' %></p>
|
||||
|
||||
<div class="usedWidgets" id="usedWidgets-$Name">
|
||||
<% if $UsedWidgets %>
|
||||
<% loop $UsedWidgets %>
|
||||
$EditableSegment
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<div class="NoWidgets" id="NoWidgets-$Name"></div>
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,3 @@
|
|||
<% loop $WidgetControllers %>
|
||||
$WidgetHolder
|
||||
<% end_loop %>
|
|
@ -1,3 +0,0 @@
|
|||
<% loop WidgetControllers %>
|
||||
$WidgetHolder
|
||||
<% end_loop %>
|
|
@ -1,32 +0,0 @@
|
|||
<div class="WidgetAreaEditor field" id="WidgetAreaEditor-$Name" name="$Name"<% if MaxWidgets %> maxwidgets="$MaxWidgets"<% end_if %>>
|
||||
<input type="hidden" id="$Name" name="$IdxField" value="$Value" />
|
||||
<div class="availableWidgetsHolder">
|
||||
<h2><% _t('WidgetAreaEditor_ss.AVAILABLE', 'Available Widgets') %></h2>
|
||||
<p class="message"><% _t('WidgetAreaEditor_ss.AVAILWIDGETS', 'Click a widget title below to use it on this page.') %></p>
|
||||
<div class="availableWidgets" id="availableWidgets-$Name">
|
||||
<% if AvailableWidgets %>
|
||||
<% loop AvailableWidgets %>
|
||||
$DescriptionSegment
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<div class="NoWidgets" id="NoWidgets-$Name">
|
||||
<p><% _t('WidgetAreaEditor_ss.NOAVAIL', 'There are currently no widgets available.') %></p>
|
||||
</div>
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="usedWidgetsHolder">
|
||||
<h2><% _t('WidgetAreaEditor_ss.INUSE', 'Widgets currently used') %></h2>
|
||||
<p class="message"><% _t('WidgetAreaEditor_ss.TOSORT', 'To sort currently used widgets on this page, drag them up and down.') %></p>
|
||||
|
||||
<div class="usedWidgets" id="usedWidgets-$Name">
|
||||
<% if UsedWidgets %>
|
||||
<% loop UsedWidgets %>
|
||||
$EditableSegment
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<div class="NoWidgets" id="NoWidgets-$Name"></div>
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -1,6 +1,6 @@
|
|||
<div class="Widget" id="$ClassName">
|
||||
<h3 title="<% _t('WidgetDescription_ss.CLICKTOADDWIDGET', 'Click to add this widget') %>">$CMSTitle</h3>
|
||||
<h3 title="<%t WidgetDescription_ss.CLICKTOADDWIDGET 'Click to add this widget' %>">$CMSTitle</h3>
|
||||
<div class="widgetDescription">
|
||||
<p>$Description</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -10,5 +10,5 @@
|
|||
<% end_if %>
|
||||
<input type="hidden" name="$Name[Type]" value="$ClassName" />
|
||||
<input type="hidden" name="$Name[Sort]" value="$Sort" />
|
||||
<p class="deleteWidget"><span class="widgetDelete ss-ui-button"><% _t('WidgetEditor_ss.DELETE', 'Delete') %></span></p>
|
||||
</div>
|
||||
<p class="deleteWidget"><span class="widgetDelete btn btn-danger"><%t WidgetEditor_ss.DELETE 'Delete' %></span></p>
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div class="WidgetHolder $ClassName<% if FirstLast %> $FirstLast<% end_if %>">
|
||||
<% if Title %><h3>$Title</h3><% end_if %>
|
||||
<div class="WidgetHolder $ClassName<% if $FirstLast %> $FirstLast<% end_if %>">
|
||||
<% if $Title %><h3>$Title</h3><% end_if %>
|
||||
$Content
|
||||
</div>
|
||||
|
|
|
@ -1,4 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests;
|
||||
|
||||
use SilverStripe\CMS\Controllers\ContentController;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\HTTPRequest;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Widgets\Extensions\WidgetPageExtension;
|
||||
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
||||
use SilverStripe\Widgets\Tests\WidgetAreaEditorTest\FakePage;
|
||||
use SilverStripe\Widgets\Tests\WidgetAreaEditorTest\TestWidget;
|
||||
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage tests
|
||||
|
@ -8,21 +22,19 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
/**
|
||||
* This is the widget you want to use for your unit tests.
|
||||
*/
|
||||
protected $widgetToTest = 'WidgetAreaEditorTest_TestWidget';
|
||||
protected $widgetToTest = TestWidget::class;
|
||||
|
||||
protected static $extra_dataobjects = [
|
||||
FakePage::class,
|
||||
TestWidget::class,
|
||||
];
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'WidgetAreaEditorTest_FakePage',
|
||||
'WidgetAreaEditorTest_TestWidget',
|
||||
);
|
||||
|
||||
protected $usesDatabase = true;
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
"SiteTree" => array(
|
||||
"WidgetPageExtension"
|
||||
)
|
||||
);
|
||||
|
||||
protected static $required_extensions = [
|
||||
SiteTree::class => [WidgetPageExtension::class]
|
||||
];
|
||||
|
||||
public function testFillingOneArea()
|
||||
{
|
||||
$data = array(
|
||||
|
@ -36,14 +48,21 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
|
@ -75,30 +94,36 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
$page->SideBar()->flushCache();
|
||||
|
||||
|
||||
// Make sure they both got saved
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
|
||||
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide');
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide');
|
||||
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
|
||||
}
|
||||
|
||||
|
||||
public function testDeletingOneWidgetFromOneArea()
|
||||
{
|
||||
// First get some widgets in there
|
||||
|
@ -120,13 +145,19 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
|
@ -135,7 +166,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
|
@ -150,8 +181,9 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
|
@ -160,9 +192,9 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
||||
}
|
||||
|
||||
|
@ -187,13 +219,19 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
|
@ -202,7 +240,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
|
@ -212,21 +250,22 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
|
||||
$page->write();
|
||||
$page->flushCache();
|
||||
$page->BottomBar()->flushCache();
|
||||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 0);
|
||||
}
|
||||
|
||||
|
||||
public function testEditingOneWidget()
|
||||
{
|
||||
// First get some widgets in there
|
||||
|
@ -248,13 +287,19 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
|
@ -263,7 +308,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
|
@ -283,8 +328,9 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
|
@ -293,11 +339,11 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
|
||||
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom');
|
||||
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
|
||||
}
|
||||
|
||||
public function testEditingAWidgetFromEachArea()
|
||||
|
@ -321,13 +367,19 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$form->saveInto($page);
|
||||
$page->write();
|
||||
|
@ -336,7 +388,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
|
@ -356,8 +408,9 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
|
@ -366,13 +419,13 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($bottWidgets[0]->Title(), 'MyTestWidgetBottom-edited');
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
|
||||
$this->assertEquals($bottWidgets[0]->getTitle(), 'MyTestWidgetBottom-edited');
|
||||
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
|
||||
}
|
||||
|
||||
|
||||
public function testEditAWidgetFromOneAreaAndDeleteAWidgetFromAnotherArea()
|
||||
{
|
||||
// First get some widgets in there
|
||||
|
@ -394,13 +447,19 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
|
||||
$editorSide = new WidgetAreaEditor('SideBar');
|
||||
$editorBott = new WidgetAreaEditor('BottomBar');
|
||||
$form = new Form(new ContentController(), 'Form', new FieldList($editorSide, $editorBott), new FieldList());
|
||||
$form->setRequest($request);
|
||||
$page = new WidgetAreaEditorTest_FakePage();
|
||||
$form = new Form(
|
||||
$controller = new ContentController(),
|
||||
Form::class,
|
||||
new FieldList($editorSide, $editorBott),
|
||||
new FieldList()
|
||||
);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$page = new FakePage();
|
||||
|
||||
$editorSide->saveInto($page);
|
||||
$editorBott->saveInto($page);
|
||||
|
@ -410,7 +469,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
// Save again (after removing the SideBar's widget)
|
||||
$data = array(
|
||||
'Widget' => array(
|
||||
|
@ -425,8 +484,9 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
)
|
||||
)
|
||||
);
|
||||
$request = new SS_HTTPRequest('get', 'post', array(), $data);
|
||||
$form->setRequest($request);
|
||||
$request = new HTTPRequest('get', 'post', array(), $data);
|
||||
$controller->setRequest($request);
|
||||
$form->setController($controller);
|
||||
$form->saveInto($page);
|
||||
|
||||
$page->write();
|
||||
|
@ -435,23 +495,9 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||
$page->SideBar()->flushCache();
|
||||
$sideWidgets = $page->SideBar()->Widgets()->toArray();
|
||||
$bottWidgets = $page->BottomBar()->Widgets()->toArray();
|
||||
|
||||
|
||||
$this->assertEquals($page->BottomBar()->Widgets()->Count(), 0);
|
||||
$this->assertEquals($page->SideBar()->Widgets()->Count(), 1);
|
||||
$this->assertEquals($sideWidgets[0]->Title(), 'MyTestWidgetSide-edited');
|
||||
$this->assertEquals($sideWidgets[0]->getTitle(), 'MyTestWidgetSide-edited');
|
||||
}
|
||||
}
|
||||
|
||||
class WidgetAreaEditorTest_FakePage extends Page implements TestOnly
|
||||
{
|
||||
private static $has_one = array(
|
||||
"BottomBar" => "WidgetArea",
|
||||
);
|
||||
}
|
||||
|
||||
class WidgetAreaEditorTest_TestWidget extends Widget implements TestOnly
|
||||
{
|
||||
private static $cmsTitle = "Test widget";
|
||||
private static $title = "Test widget";
|
||||
private static $description = "Test widget";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests\WidgetAreaEditorTest;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
class FakePage extends Page implements TestOnly
|
||||
{
|
||||
private static $table_name = 'FakePage';
|
||||
|
||||
private static $has_one = array(
|
||||
"BottomBar" => WidgetArea::class
|
||||
);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests\WidgetAreaEditorTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
class TestWidget extends Widget implements TestOnly
|
||||
{
|
||||
private static $table_name = 'WidgetAreaEditorTest_TestWidget';
|
||||
private static $cmsTitle = "Test widget";
|
||||
private static $description = "Test widget";
|
||||
}
|
|
@ -1,99 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* @package widgets
|
||||
* @subpackage tests
|
||||
*/
|
||||
|
||||
namespace SilverStripe\Widgets\Tests;
|
||||
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage;
|
||||
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget;
|
||||
|
||||
class WidgetControllerTest extends FunctionalTest
|
||||
{
|
||||
protected static $fixture_file = 'WidgetControllerTest.yml';
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'WidgetControllerTestPage',
|
||||
'WidgetControllerTest_Widget',
|
||||
);
|
||||
|
||||
protected static $extra_dataobjects = [
|
||||
TestPage::class,
|
||||
TestWidget::class,
|
||||
];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->actWithPermission('ADMIN', function () {
|
||||
$this->objFromFixture(TestPage::class, 'page1')->publishRecursive();
|
||||
});
|
||||
}
|
||||
|
||||
public function testWidgetFormRendering()
|
||||
{
|
||||
$page = $this->objFromFixture('WidgetControllerTestPage', 'page1');
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$widget = $this->objFromFixture('WidgetControllerTest_Widget', 'widget1');
|
||||
|
||||
$page = $this->objFromFixture(TestPage::class, 'page1');
|
||||
$widget = $this->objFromFixture(TestWidget::class, 'widget1');
|
||||
|
||||
$response = $this->get($page->URLSegment);
|
||||
|
||||
$formAction = sprintf('%s/widget/%d/Form', $page->URLSegment, $widget->ID);
|
||||
$this->assertContains(
|
||||
|
||||
$formAction = sprintf('%s/widget/%d/%s', $page->URLSegment, $widget->ID, 'Form');
|
||||
$this->assertStringContainsString(
|
||||
$formAction,
|
||||
$response->getBody(),
|
||||
"Widget forms are rendered through WidgetArea templates"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testWidgetFormSubmission()
|
||||
{
|
||||
$page = $this->objFromFixture('WidgetControllerTestPage', 'page1');
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$widget = $this->objFromFixture('WidgetControllerTest_Widget', 'widget1');
|
||||
|
||||
$response = $this->get($page->URLSegment);
|
||||
$response = $this->submitForm('Form_Form', null, array('TestValue'=>'Updated'));
|
||||
$page = $this->objFromFixture(TestPage::class, 'page1');
|
||||
$widget = $this->objFromFixture(TestWidget::class, 'widget1');
|
||||
|
||||
$this->assertContains(
|
||||
$this->get($page->URLSegment);
|
||||
$response = $this->submitForm('Form_Form', null, array('TestValue' => 'Updated'));
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'TestValue: Updated',
|
||||
$response->getBody(),
|
||||
"Form values are submitted to correct widget form"
|
||||
);
|
||||
$this->assertContains(
|
||||
$this->assertStringContainsString(
|
||||
sprintf('Widget ID: %d', $widget->ID),
|
||||
$response->getBody(),
|
||||
"Widget form acts on correct widget, as identified in the URL"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @package widgets
|
||||
* @subpackage tests
|
||||
*/
|
||||
class WidgetControllerTest_Widget extends Widget implements TestOnly
|
||||
{
|
||||
private static $db = array(
|
||||
'TestValue' => 'Text'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @package widgets
|
||||
* @subpackage tests
|
||||
*/
|
||||
class WidgetControllerTest_WidgetController extends WidgetController implements TestOnly
|
||||
{
|
||||
private static $allowed_actions = array(
|
||||
'Form'
|
||||
);
|
||||
|
||||
public function Form()
|
||||
{
|
||||
$widgetform = new Form(
|
||||
$this,
|
||||
'Form',
|
||||
new FieldList(
|
||||
new TextField('TestValue')
|
||||
),
|
||||
new FieldList(
|
||||
new FormAction('doAction')
|
||||
)
|
||||
);
|
||||
|
||||
return $widgetform;
|
||||
}
|
||||
|
||||
public function doAction($data, $form)
|
||||
{
|
||||
return sprintf('TestValue: %s\nWidget ID: %d',
|
||||
$data['TestValue'],
|
||||
$this->widget->ID
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
WidgetControllerTest_Widget:
|
||||
widget1:
|
||||
Title: Widget 1
|
||||
WidgetArea:
|
||||
area1:
|
||||
Widgets: =>WidgetControllerTest_Widget.widget1
|
||||
WidgetControllerTestPage:
|
||||
page1:
|
||||
Title: Page1
|
||||
WidgetControllerTestSidebar: =>WidgetArea.area1
|
||||
SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget:
|
||||
widget1:
|
||||
Title: Widget 1
|
||||
SilverStripe\Widgets\Model\WidgetArea:
|
||||
area1:
|
||||
Widgets: =>SilverStripe\Widgets\Tests\WidgetControllerTest\TestWidget.widget1
|
||||
SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage:
|
||||
page1:
|
||||
Title: Page1
|
||||
WidgetControllerTestSidebar: =>SilverStripe\Widgets\Model\WidgetArea.area1
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests\WidgetControllerTest;
|
||||
|
||||
use Page;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Widgets\Model\WidgetArea;
|
||||
|
||||
class TestPage extends Page implements TestOnly
|
||||
{
|
||||
private static $table_name = 'TestPage';
|
||||
|
||||
private static $has_one = [
|
||||
'WidgetControllerTestSidebar' => WidgetArea::class,
|
||||
];
|
||||
|
||||
private static $owns = [
|
||||
'WidgetControllerTestSidebar',
|
||||
];
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests\WidgetControllerTest;
|
||||
|
||||
use PageController;
|
||||
use ReflectionClass;
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\View\SSViewer;
|
||||
use SilverStripe\Widgets\Tests\WidgetControllerTest\TestPage;
|
||||
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage tests
|
||||
*/
|
||||
class TestPageController extends PageController implements TestOnly
|
||||
{
|
||||
/**
|
||||
* Template selection doesnt work in test folders, so we add a test theme a template name.
|
||||
*/
|
||||
public function getViewer($action)
|
||||
{
|
||||
SSViewer::add_themes(['silverstripe/widgets:/tests/WidgetControllerTest']);
|
||||
return new SSViewer(TestPage::class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests\WidgetControllerTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Widgets\Model\Widget;
|
||||
|
||||
class TestWidget extends Widget implements TestOnly
|
||||
{
|
||||
private static $table_name = 'WidgetControllerTest_TestWidget';
|
||||
|
||||
private static $db = [
|
||||
'TestValue' => 'Text',
|
||||
];
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace SilverStripe\Widgets\Tests\WidgetControllerTest;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\FormAction;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Widgets\Model\WidgetController;
|
||||
|
||||
/**
|
||||
* @package widgets
|
||||
* @subpackage tests
|
||||
*/
|
||||
class TestWidgetController extends WidgetController implements TestOnly
|
||||
{
|
||||
private static $allowed_actions = array(
|
||||
'Form'
|
||||
);
|
||||
|
||||
public function Form()
|
||||
{
|
||||
$widgetform = new Form(
|
||||
$this,
|
||||
__FUNCTION__,
|
||||
new FieldList(
|
||||
new TextField('TestValue')
|
||||
),
|
||||
new FieldList(
|
||||
new FormAction('doAction')
|
||||
)
|
||||
);
|
||||
|
||||
return $widgetform;
|
||||
}
|
||||
|
||||
public function doAction($data, $form)
|
||||
{
|
||||
return sprintf(
|
||||
'TestValue: %s\nWidget ID: %d',
|
||||
$data['TestValue'],
|
||||
$this->widget->ID
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
$WidgetControllerTestSidebar
|
|
@ -0,0 +1 @@
|
|||
$Form
|
|
@ -1,29 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage tests
|
||||
*/
|
||||
class WidgetControllerTestPage extends Page implements TestOnly
|
||||
{
|
||||
private static $has_one = array(
|
||||
'WidgetControllerTestSidebar' => 'WidgetArea'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @package cms
|
||||
* @subpackage tests
|
||||
*/
|
||||
class WidgetControllerTestPage_Controller extends Page_Controller implements TestOnly
|
||||
{
|
||||
/**
|
||||
* Template selection doesnt work in test folders,
|
||||
* so we enforce a template name.
|
||||
*/
|
||||
public function getViewer($action)
|
||||
{
|
||||
$templates = array('WidgetControllerTestPage');
|
||||
|
||||
return new SSViewer($templates);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
$WidgetControllerTestSidebar
|
|
@ -1 +0,0 @@
|
|||
$Form
|
Loading…
Reference in New Issue