mirror of
https://github.com/silverstripe/silverstripe-widgets
synced 2024-10-22 17:05:54 +02:00
Merge branch '1.2' into 1.3
This commit is contained in:
commit
ef40ca30aa
@ -6,39 +6,42 @@
|
||||
*/
|
||||
class WidgetContentControllerExtension extends Extension
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $allowed_actions = array(
|
||||
'handleWidget'
|
||||
);
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
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
|
||||
* looks for connected widgets by their database identifier.
|
||||
*
|
||||
* Assumes URLs in the following format: <URLSegment>/widget/<Widget-ID>.
|
||||
*
|
||||
* @return RequestHandler
|
||||
*/
|
||||
public function handleWidget()
|
||||
{
|
||||
$SQL_id = $this->owner->getRequest()->param('ID');
|
||||
if (!$SQL_id) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Handles widgets attached to a page through one or more {@link WidgetArea}
|
||||
* elements.
|
||||
*
|
||||
* 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()
|
||||
{$SQL_id = $this->owner->getRequest()->param('ID');
|
||||
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();
|
||||
// find WidgetArea relations
|
||||
$widgetAreaRelations = array();
|
||||
$hasOnes = $widgetOwner->hasOne();
|
||||
|
||||
if (!$hasOnes) {
|
||||
return false;
|
||||
}
|
||||
if(!$hasOnes) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($hasOnes as $hasOneName => $hasOneClass) {
|
||||
if ($hasOneClass == 'WidgetArea' || is_subclass_of($hasOneClass, 'WidgetArea')) {
|
||||
@ -54,10 +57,10 @@ class WidgetContentControllerExtension extends Extension
|
||||
break;
|
||||
}
|
||||
|
||||
$widget = $this->owner->data()->$widgetAreaRelation()->Widgets()
|
||||
->filter('ID', $SQL_id)
|
||||
->First();
|
||||
}
|
||||
$widget = $widgetOwner->$widgetAreaRelation()->Widgets()
|
||||
->filter('ID', $SQL_id)
|
||||
->First();
|
||||
}
|
||||
|
||||
if (!$widget) {
|
||||
user_error('No widget found', E_USER_ERROR);
|
||||
|
@ -45,80 +45,95 @@ class WidgetController extends Controller
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @return string
|
||||
*/
|
||||
public function Link($action = null)
|
||||
/**
|
||||
* @param string $action
|
||||
* @return string
|
||||
*/
|
||||
public function Link($action = null)
|
||||
{
|
||||
$id = ($this->widget) ? $this->widget->ID : null;
|
||||
$segment = Controller::join_links('widget', $id, $action);
|
||||
$segment = Controller::join_links('widget', $id, $action);
|
||||
|
||||
if ($page = Director::get_current_page()) {
|
||||
return $page->Link($segment);
|
||||
}
|
||||
$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 Widget
|
||||
*/
|
||||
public function getWidget()
|
||||
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()
|
||||
{
|
||||
return $this->widget;
|
||||
}
|
||||
foreach(Controller::$controller_stack as $controller) {
|
||||
if (!($controller instanceof WidgetController)) {
|
||||
return $controller;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Widget
|
||||
*/
|
||||
public function getWidget()
|
||||
{return $this->widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded from {@link Widget->WidgetHolder()} to allow for controller/
|
||||
* form linking.
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function WidgetHolder()
|
||||
{
|
||||
return $this->renderWith("WidgetHolder");
|
||||
}
|
||||
/**
|
||||
* 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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* {@link WidgetAreaEditor} within the CMS interface.
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function editablesegment()
|
||||
{
|
||||
/**
|
||||
* 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()}
|
||||
* to render a administrator-view of the widget. It is assumed that this
|
||||
* view contains form elements which are submitted and saved through
|
||||
* {@link WidgetAreaEditor} within the CMS interface.
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
public function editablesegment() {
|
||||
// use left and main to set the html config
|
||||
$leftandmain = LeftAndMain::create();
|
||||
$leftandmain->init();
|
||||
|
||||
$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')) {
|
||||
$obj = new $className();
|
||||
return $obj->EditableSegment();
|
||||
} else {
|
||||
user_error("Bad widget class: $className", E_USER_WARNING);
|
||||
return "Bad widget class name given";
|
||||
}
|
||||
}
|
||||
$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')) {
|
||||
$obj = new $className();
|
||||
return $obj->EditableSegment();
|
||||
} else {
|
||||
user_error("Bad widget class: $className", E_USER_WARNING);
|
||||
return "Bad widget class name given";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,8 +10,8 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"silverstripe/framework": ">=3.2",
|
||||
"silverstripe/cms": ">=3.2"
|
||||
"silverstripe/framework": "^3.2",
|
||||
"silverstripe/cms": "^3.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/PHPUnit": "~3.7@stable"
|
||||
|
@ -1,7 +1,7 @@
|
||||
ar:
|
||||
Widget:
|
||||
PLURALNAME: تطبيقات مصغرة
|
||||
SINGULARNAME: تطبيق مصغر
|
||||
PLURALNAME: 'تطبيقات مصغرة'
|
||||
SINGULARNAME: 'تطبيق مصغر'
|
||||
WidgetArea:
|
||||
PLURALNAME: 'مساحات التطبيقات المصغرة'
|
||||
SINGULARNAME: 'مساحة التطبيقات المصغرة'
|
||||
@ -14,4 +14,4 @@ ar:
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'اضغط لإضافة هذا التطبيق المصغر'
|
||||
WidgetEditor_ss:
|
||||
DELETE: مسح
|
||||
DELETE: 'مسح'
|
||||
|
@ -3,8 +3,8 @@ de:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Widgetbereiche'
|
||||
SINGULARNAME: 'Widgetbereich'
|
||||
PLURALNAME: Widgetbereiche
|
||||
SINGULARNAME: Widgetbereich
|
||||
WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Vorhandene Widgets'
|
||||
AVAILWIDGETS: 'Klicke den Widget Titel, um es zu benutzen.'
|
||||
|
@ -1,6 +1,6 @@
|
||||
fa_IR:
|
||||
Widget:
|
||||
PLURALNAME: ویجت ها
|
||||
PLURALNAME: 'ویجت ها'
|
||||
SINGULARNAME: ویجت
|
||||
WidgetArea:
|
||||
PLURALNAME: 'محیط ویجت ها'
|
||||
|
17
lang/sk.yml
Normal file
17
lang/sk.yml
Normal file
@ -0,0 +1,17 @@
|
||||
sk:
|
||||
Widget:
|
||||
PLURALNAME: Widgety
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Oblasti widgetu'
|
||||
SINGULARNAME: 'Oblasť widgetu'
|
||||
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.'
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: 'Kliknite pre pridanie tohto widgetu'
|
||||
WidgetEditor_ss:
|
||||
DELETE: Vymazať
|
@ -3,8 +3,8 @@ sv:
|
||||
PLURALNAME: Widgets
|
||||
SINGULARNAME: Widget
|
||||
WidgetArea:
|
||||
PLURALNAME: 'Widgetområden'
|
||||
SINGULARNAME: 'Widgetområde'
|
||||
PLURALNAME: Widgetområden
|
||||
SINGULARNAME: Widgetområde
|
||||
WidgetAreaEditor_ss:
|
||||
AVAILABLE: 'Tillgängliga widgets'
|
||||
AVAILWIDGETS: 'Klicka på en widget nedan för att använda den på sidan.'
|
||||
|
@ -1,7 +1,7 @@
|
||||
zh:
|
||||
Widget:
|
||||
PLURALNAME: 小工具
|
||||
SINGULARNAME: 小工具
|
||||
PLURALNAME: '小工具'
|
||||
SINGULARNAME: '小工具'
|
||||
WidgetArea:
|
||||
PLURALNAME: '小工具区域'
|
||||
SINGULARNAME: '小工具区域'
|
||||
@ -14,4 +14,4 @@ zh:
|
||||
WidgetDescription_ss:
|
||||
CLICKTOADDWIDGET: '点击添加该小工具'
|
||||
WidgetEditor_ss:
|
||||
DELETE: 删除
|
||||
DELETE: '删除'
|
||||
|
Loading…
Reference in New Issue
Block a user