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
|
||||
|
||||
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
|
||||
|
12
README.md
12
README.md
@ -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
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": {
|
||||
"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
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -93,36 +93,6 @@ class WidgetController extends Controller
|
||||
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
|
||||
*/
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 %>
|
||||
@ -18,10 +18,10 @@
|
||||
<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 %>
|
||||
<% if $UsedWidgets %>
|
||||
<% loop $UsedWidgets %>
|
||||
$EditableSegment
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
@ -29,4 +29,4 @@
|
||||
<% end_if %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -3,4 +3,4 @@
|
||||
<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>
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user