mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 17:05:54 +02:00
FIX Add legacy class remapping, escape FQ class names in URLs, docs and add bootstrap to buttons
This commit is contained in:
parent
e7de0c61bf
commit
ec9421ba65
@ -11,14 +11,12 @@ php:
|
|||||||
- 7.1
|
- 7.1
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- DB=MYSQL CORE_RELEASE=master
|
- DB=MYSQL CORE_RELEASE=4
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=MYSQL CORE_RELEASE=master
|
env: DB=PGSQL CORE_RELEASE=4
|
||||||
- php: 5.6
|
|
||||||
env: DB=PGSQL CORE_RELEASE=master
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer self-update || true
|
- composer self-update || true
|
||||||
|
12
README.md
12
README.md
@ -62,7 +62,7 @@ e.g.
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Widgets\Form\WidgetAreaEditor;
|
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
||||||
use SilverStripe\Widgets\Model\WidgetArea;
|
use SilverStripe\Widgets\Model\WidgetArea;
|
||||||
|
|
||||||
class Page extends SiteTree
|
class Page extends SiteTree
|
||||||
@ -100,7 +100,7 @@ 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.
|
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
|
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.
|
does.
|
||||||
|
|
||||||
An example widget is below:
|
An example widget is below:
|
||||||
@ -271,13 +271,13 @@ templates to `themes/myThemeName/templates/Includes/`
|
|||||||
|
|
||||||
### Changing the title of your widget
|
### 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:
|
variable. For example, to set your widgets title to 'Hello World!', you could use:
|
||||||
|
|
||||||
**widgets_yourWidget/src/YourWidgetWidget.php**
|
**widgets_yourWidget/src/YourWidgetWidget.php**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function Title()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return 'Hello World!';
|
return 'Hello World!';
|
||||||
}
|
}
|
||||||
@ -285,12 +285,12 @@ public function Title()
|
|||||||
|
|
||||||
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.
|
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.
|
This is similar to the RSS Widget in the blog module.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public function Title()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return $this->WidgetTitle ? $this->WidgetTitle : self::$title;
|
return $this->WidgetTitle ? $this->WidgetTitle : self::$title;
|
||||||
}
|
}
|
||||||
|
7
_config/legacy.yml
Normal file
7
_config/legacy.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
Name: widgetslegacymapping
|
||||||
|
---
|
||||||
|
SilverStripe\ORM\DatabaseAdmin:
|
||||||
|
classname_value_remapping:
|
||||||
|
Widget: SilverStripe\Widgets\Model\Widget
|
||||||
|
WidgetArea: SilverStripe\Widgets\Model\WidgetArea
|
@ -24,8 +24,10 @@
|
|||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"SilverStripe\\Widgets\\": "src/",
|
"SilverStripe\\Widgets\\": "src/",
|
||||||
"SilverStripe\\Widgets\\Tests\\": "tests/",
|
"SilverStripe\\Widgets\\Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "BSD-3-Clause"
|
"license": "BSD-3-Clause",
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ can enable through your `config.yml`:
|
|||||||
```yaml
|
```yaml
|
||||||
Page:
|
Page:
|
||||||
extensions:
|
extensions:
|
||||||
- WidgetPageExtension
|
- SilverStripe\Widgets\Extensions\WidgetPageExtension
|
||||||
```
|
```
|
||||||
|
|
||||||
Run a `dev/build`, and adjust your templates to include the resulting sidebar view.
|
Run a `dev/build`, and adjust your templates to include the resulting sidebar view.
|
||||||
@ -63,7 +63,7 @@ e.g.
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\CMS\Model\SiteTree;
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
use SilverStripe\Widgets\Form\WidgetAreaEditor;
|
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
|
||||||
use SilverStripe\Widgets\Model\WidgetArea;
|
use SilverStripe\Widgets\Model\WidgetArea;
|
||||||
|
|
||||||
class Page extends SiteTree
|
class Page extends SiteTree
|
||||||
@ -101,7 +101,7 @@ 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.
|
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
|
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.
|
does.
|
||||||
|
|
||||||
An example widget is below:
|
An example widget is below:
|
||||||
|
@ -93,36 +93,6 @@ class WidgetController extends Controller
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Widget
|
|
||||||
*/
|
|
||||||
public function getWidget()
|
|
||||||
{
|
|
||||||
return $this->widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overloaded from {@link Widget->WidgetHolder()} to allow for controller/
|
|
||||||
* form linking.
|
|
||||||
*
|
|
||||||
* @return string HTML
|
|
||||||
*/
|
|
||||||
public function WidgetHolder()
|
|
||||||
{
|
|
||||||
return $this->renderWith("WidgetHolder");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Widget
|
* @return Widget
|
||||||
*/
|
*/
|
||||||
@ -167,7 +137,8 @@ class WidgetController extends Controller
|
|||||||
$leftandmain = LeftAndMain::create();
|
$leftandmain = LeftAndMain::create();
|
||||||
$leftandmain->doInit();
|
$leftandmain->doInit();
|
||||||
|
|
||||||
$className = $this->urlParams['ID'];
|
// Decode if fully qualified - @see Widget::ClassName
|
||||||
|
$className = str_replace('_', '\\', $this->urlParams['ID']);
|
||||||
if (class_exists('Translatable') && Member::currentUserID()) {
|
if (class_exists('Translatable') && Member::currentUserID()) {
|
||||||
// set current locale based on logged in user's locale
|
// set current locale based on logged in user's locale
|
||||||
$locale = Member::currentUser()->Locale;
|
$locale = Member::currentUser()->Locale;
|
||||||
|
@ -142,7 +142,7 @@ class WidgetAreaEditor extends FormField
|
|||||||
throw new Exception("no form");
|
throw new Exception("no form");
|
||||||
}
|
}
|
||||||
|
|
||||||
$widgetData = $this->getForm()->getRequest()->requestVar(Widget::class);
|
$widgetData = $this->getForm()->getRequest()->requestVar('Widget');
|
||||||
if ($widgetData && isset($widgetData[$this->getName()])) {
|
if ($widgetData && isset($widgetData[$this->getName()])) {
|
||||||
$widgetAreaData = $widgetData[$this->getName()];
|
$widgetAreaData = $widgetData[$this->getName()];
|
||||||
|
|
||||||
@ -180,7 +180,6 @@ class WidgetAreaEditor extends FormField
|
|||||||
if ($widget->ParentID == 0) {
|
if ($widget->ParentID == 0) {
|
||||||
$widget->ParentID = $record->$name()->ID;
|
$widget->ParentID = $record->$name()->ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
$widget->populateFromPostData($newWidgetData);
|
$widget->populateFromPostData($newWidgetData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ class Widget extends DataObject
|
|||||||
public function getTitle()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return $this->getField('Title')
|
return $this->getField('Title')
|
||||||
?: _t($this->ClassName() . '.TITLE', $this->config()->title);
|
?: _t($this->class . '.TITLE', $this->config()->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,7 +155,7 @@ class Widget extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function getCMSTitle()
|
public function getCMSTitle()
|
||||||
{
|
{
|
||||||
return _t($this->ClassName() . '.CMSTITLE', $this->config()->cmsTitle);
|
return _t($this->class . '.CMSTITLE', $this->config()->cmsTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,7 +163,7 @@ class Widget extends DataObject
|
|||||||
*/
|
*/
|
||||||
public function getDescription()
|
public function getDescription()
|
||||||
{
|
{
|
||||||
return _t($this->ClassName() . '.DESCRIPTION', $this->config()->description);
|
return _t($this->class . '.DESCRIPTION', $this->config()->description);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,11 +231,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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ClassName()
|
public function ClassName()
|
||||||
{
|
{
|
||||||
return $this->class;
|
return str_replace('\\', '_', $this->class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
<h2><% _t('WidgetAreaEditor_ss.AVAILABLE', 'Available Widgets') %></h2>
|
<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>
|
<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">
|
<div class="availableWidgets" id="availableWidgets-$Name">
|
||||||
<% if AvailableWidgets %>
|
<% if $AvailableWidgets %>
|
||||||
<% loop AvailableWidgets %>
|
<% loop $AvailableWidgets %>
|
||||||
$DescriptionSegment
|
$DescriptionSegment
|
||||||
<% end_loop %>
|
<% end_loop %>
|
||||||
<% else %>
|
<% else %>
|
||||||
@ -20,8 +20,8 @@
|
|||||||
<p class="message"><% _t('WidgetAreaEditor_ss.TOSORT', 'To sort currently used widgets on this page, drag them up and down.') %></p>
|
<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">
|
<div class="usedWidgets" id="usedWidgets-$Name">
|
||||||
<% if UsedWidgets %>
|
<% if $UsedWidgets %>
|
||||||
<% loop UsedWidgets %>
|
<% loop $UsedWidgets %>
|
||||||
$EditableSegment
|
$EditableSegment
|
||||||
<% end_loop %>
|
<% end_loop %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
@ -10,5 +10,5 @@
|
|||||||
<% end_if %>
|
<% end_if %>
|
||||||
<input type="hidden" name="$Name[Type]" value="$ClassName" />
|
<input type="hidden" name="$Name[Type]" value="$ClassName" />
|
||||||
<input type="hidden" name="$Name[Sort]" value="$Sort" />
|
<input type="hidden" name="$Name[Sort]" value="$Sort" />
|
||||||
<p class="deleteWidget"><span class="widgetDelete ss-ui-button"><% _t('WidgetEditor_ss.DELETE', 'Delete') %></span></p>
|
<p class="deleteWidget"><span class="widgetDelete btn btn-danger"><% _t('WidgetEditor_ss.DELETE', 'Delete') %></span></p>
|
||||||
</div>
|
</div>
|
@ -41,7 +41,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
public function testFillingOneArea()
|
public function testFillingOneArea()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'BottomBar' => array(
|
'BottomBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidget',
|
'Title' => 'MyTestWidget',
|
||||||
@ -78,7 +78,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
public function testFillingTwoAreas()
|
public function testFillingTwoAreas()
|
||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidgetSide',
|
'Title' => 'MyTestWidgetSide',
|
||||||
@ -128,7 +128,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
// First get some widgets in there
|
// First get some widgets in there
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidgetSide',
|
'Title' => 'MyTestWidgetSide',
|
||||||
@ -168,7 +168,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
|
|
||||||
// Save again (after removing the SideBar's widget)
|
// Save again (after removing the SideBar's widget)
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
),
|
),
|
||||||
'BottomBar' => array(
|
'BottomBar' => array(
|
||||||
@ -200,7 +200,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
// First get some widgets in there
|
// First get some widgets in there
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidgetSide',
|
'Title' => 'MyTestWidgetSide',
|
||||||
@ -240,7 +240,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
|
|
||||||
// Save again (after removing the SideBar's widget)
|
// Save again (after removing the SideBar's widget)
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
),
|
),
|
||||||
'BottomBar' => array(
|
'BottomBar' => array(
|
||||||
@ -266,7 +266,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
// First get some widgets in there
|
// First get some widgets in there
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidgetSide',
|
'Title' => 'MyTestWidgetSide',
|
||||||
@ -306,7 +306,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
|
|
||||||
// Save again (after removing the SideBar's widget)
|
// Save again (after removing the SideBar's widget)
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
$sideWidgets[0]->ID => array(
|
$sideWidgets[0]->ID => array(
|
||||||
'Title' => 'MyTestWidgetSide-edited',
|
'Title' => 'MyTestWidgetSide-edited',
|
||||||
@ -344,7 +344,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
// First get some widgets in there
|
// First get some widgets in there
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidgetSide',
|
'Title' => 'MyTestWidgetSide',
|
||||||
@ -384,7 +384,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
|
|
||||||
// Save again (after removing the SideBar's widget)
|
// Save again (after removing the SideBar's widget)
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
$sideWidgets[0]->ID => array(
|
$sideWidgets[0]->ID => array(
|
||||||
'Title' => 'MyTestWidgetSide-edited',
|
'Title' => 'MyTestWidgetSide-edited',
|
||||||
@ -422,7 +422,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
// First get some widgets in there
|
// First get some widgets in there
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
'new-1' => array(
|
'new-1' => array(
|
||||||
'Title' => 'MyTestWidgetSide',
|
'Title' => 'MyTestWidgetSide',
|
||||||
@ -463,7 +463,7 @@ class WidgetAreaEditorTest extends SapphireTest
|
|||||||
|
|
||||||
// Save again (after removing the SideBar's widget)
|
// Save again (after removing the SideBar's widget)
|
||||||
$data = array(
|
$data = array(
|
||||||
Widget::class => array(
|
'Widget' => array(
|
||||||
'SideBar' => array(
|
'SideBar' => array(
|
||||||
$sideWidgets[0]->ID => array(
|
$sideWidgets[0]->ID => array(
|
||||||
'Title' => 'MyTestWidgetSide-edited',
|
'Title' => 'MyTestWidgetSide-edited',
|
||||||
|
Loading…
Reference in New Issue
Block a user