FIX Add legacy class remapping, escape FQ class names in URLs, docs and add bootstrap to buttons

This commit is contained in:
Robbie Averill 2017-01-18 14:49:15 +13:00
parent e7de0c61bf
commit ec9421ba65
12 changed files with 53 additions and 73 deletions

View File

@ -11,14 +11,12 @@ php:
- 7.1
env:
- DB=MYSQL CORE_RELEASE=master
- DB=MYSQL CORE_RELEASE=4
matrix:
include:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=master
- php: 5.6
env: DB=PGSQL CORE_RELEASE=master
env: DB=PGSQL CORE_RELEASE=4
before_script:
- composer self-update || true

View File

@ -62,7 +62,7 @@ e.g.
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Widgets\Form\WidgetAreaEditor;
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
use SilverStripe\Widgets\Model\WidgetArea;
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.
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:
@ -271,13 +271,13 @@ 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/src/YourWidgetWidget.php**
```php
public function Title()
public function getTitle()
{
return 'Hello World!';
}
@ -285,12 +285,12 @@ public function Title()
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()
public function getTitle()
{
return $this->WidgetTitle ? $this->WidgetTitle : self::$title;
}

7
_config/legacy.yml Normal file
View File

@ -0,0 +1,7 @@
---
Name: widgetslegacymapping
---
SilverStripe\ORM\DatabaseAdmin:
classname_value_remapping:
Widget: SilverStripe\Widgets\Model\Widget
WidgetArea: SilverStripe\Widgets\Model\WidgetArea

View File

@ -24,8 +24,10 @@
"autoload": {
"psr-4": {
"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
}

View File

@ -25,7 +25,7 @@ can enable through your `config.yml`:
```yaml
Page:
extensions:
- WidgetPageExtension
- SilverStripe\Widgets\Extensions\WidgetPageExtension
```
Run a `dev/build`, and adjust your templates to include the resulting sidebar view.
@ -63,7 +63,7 @@ e.g.
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Widgets\Form\WidgetAreaEditor;
use SilverStripe\Widgets\Forms\WidgetAreaEditor;
use SilverStripe\Widgets\Model\WidgetArea;
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.
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:

View File

@ -112,36 +112,6 @@ class WidgetController extends Controller
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
*/
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.
@ -167,7 +137,8 @@ class WidgetController extends Controller
$leftandmain = LeftAndMain::create();
$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()) {
// set current locale based on logged in user's locale
$locale = Member::currentUser()->Locale;

View File

@ -142,7 +142,7 @@ class WidgetAreaEditor extends FormField
throw new Exception("no form");
}
$widgetData = $this->getForm()->getRequest()->requestVar(Widget::class);
$widgetData = $this->getForm()->getRequest()->requestVar('Widget');
if ($widgetData && isset($widgetData[$this->getName()])) {
$widgetAreaData = $widgetData[$this->getName()];
@ -180,7 +180,6 @@ class WidgetAreaEditor extends FormField
if ($widget->ParentID == 0) {
$widget->ParentID = $record->$name()->ID;
}
$widget->populateFromPostData($newWidgetData);
}
}

View File

@ -147,7 +147,7 @@ class Widget extends DataObject
public function getTitle()
{
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()
{
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()
{
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
*/
public function ClassName()
{
return $this->class;
return str_replace('\\', '_', $this->class);
}
/**

View File

@ -4,8 +4,8 @@
<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 %>
<% if $AvailableWidgets %>
<% loop $AvailableWidgets %>
$DescriptionSegment
<% end_loop %>
<% 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>
<div class="usedWidgets" id="usedWidgets-$Name">
<% if UsedWidgets %>
<% loop UsedWidgets %>
<% if $UsedWidgets %>
<% loop $UsedWidgets %>
$EditableSegment
<% end_loop %>
<% else %>

View File

@ -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>
<p class="deleteWidget"><span class="widgetDelete btn btn-danger"><% _t('WidgetEditor_ss.DELETE', 'Delete') %></span></p>
</div>

View File

@ -41,7 +41,7 @@ class WidgetAreaEditorTest extends SapphireTest
public function testFillingOneArea()
{
$data = array(
Widget::class => array(
'Widget' => array(
'BottomBar' => array(
'new-1' => array(
'Title' => 'MyTestWidget',
@ -78,7 +78,7 @@ class WidgetAreaEditorTest extends SapphireTest
public function testFillingTwoAreas()
{
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
'new-1' => array(
'Title' => 'MyTestWidgetSide',
@ -128,7 +128,7 @@ class WidgetAreaEditorTest extends SapphireTest
{
// First get some widgets in there
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
'new-1' => array(
'Title' => 'MyTestWidgetSide',
@ -168,7 +168,7 @@ class WidgetAreaEditorTest extends SapphireTest
// Save again (after removing the SideBar's widget)
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
),
'BottomBar' => array(
@ -200,7 +200,7 @@ class WidgetAreaEditorTest extends SapphireTest
{
// First get some widgets in there
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
'new-1' => array(
'Title' => 'MyTestWidgetSide',
@ -240,7 +240,7 @@ class WidgetAreaEditorTest extends SapphireTest
// Save again (after removing the SideBar's widget)
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
),
'BottomBar' => array(
@ -266,7 +266,7 @@ class WidgetAreaEditorTest extends SapphireTest
{
// First get some widgets in there
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
'new-1' => array(
'Title' => 'MyTestWidgetSide',
@ -306,7 +306,7 @@ class WidgetAreaEditorTest extends SapphireTest
// Save again (after removing the SideBar's widget)
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
$sideWidgets[0]->ID => array(
'Title' => 'MyTestWidgetSide-edited',
@ -344,7 +344,7 @@ class WidgetAreaEditorTest extends SapphireTest
{
// First get some widgets in there
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
'new-1' => array(
'Title' => 'MyTestWidgetSide',
@ -384,7 +384,7 @@ class WidgetAreaEditorTest extends SapphireTest
// Save again (after removing the SideBar's widget)
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
$sideWidgets[0]->ID => array(
'Title' => 'MyTestWidgetSide-edited',
@ -422,7 +422,7 @@ class WidgetAreaEditorTest extends SapphireTest
{
// First get some widgets in there
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
'new-1' => array(
'Title' => 'MyTestWidgetSide',
@ -463,7 +463,7 @@ class WidgetAreaEditorTest extends SapphireTest
// Save again (after removing the SideBar's widget)
$data = array(
Widget::class => array(
'Widget' => array(
'SideBar' => array(
$sideWidgets[0]->ID => array(
'Title' => 'MyTestWidgetSide-edited',