Merge branch '1.3'

This commit is contained in:
Daniel Hensby 2017-01-25 13:33:02 +00:00
commit f3b14df4e4
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
8 changed files with 160 additions and 125 deletions

View File

@ -6,39 +6,42 @@
*/ */
class WidgetContentControllerExtension extends Extension class WidgetContentControllerExtension extends Extension
{ {
/** /**
* *
* @var array * @var array
*/ */
private static $allowed_actions = array( private static $allowed_actions = array(
'handleWidget' 'handleWidget'
); );
/** /**
* Handles widgets attached to a page through one or more {@link WidgetArea} * Handles widgets attached to a page through one or more {@link WidgetArea}
* elements. * 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. * looks for connected widgets by their database identifier.
* *
* Assumes URLs in the following format: <URLSegment>/widget/<Widget-ID>. * Assumes URLs in the following format: <URLSegment>/widget/<Widget-ID>.
* *
* @return RequestHandler * @return RequestHandler
*/ */
public function handleWidget() public function handleWidget()
{ {$SQL_id = $this->owner->getRequest()->param('ID');
$SQL_id = $this->owner->getRequest()->param('ID'); if(!$SQL_id) {return false;
if (!$SQL_id) { }
return false; /** @var SiteTree $widgetOwner */
} $widgetOwner = $this->owner->data();
while($widgetOwner->InheritSideBar && $widgetOwner->Parent()->exists()){
// find WidgetArea relations $widgetOwner = $widgetOwner->Parent();
$widgetAreaRelations = array(); }
$hasOnes = $this->owner->data()->hasOne();
// find WidgetArea relations
if (!$hasOnes) { $widgetAreaRelations = array();
return false; $hasOnes = $widgetOwner->hasOne();
}
if(!$hasOnes) {
return false;
}
foreach ($hasOnes as $hasOneName => $hasOneClass) { foreach ($hasOnes as $hasOneName => $hasOneClass) {
if ($hasOneClass == 'WidgetArea' || is_subclass_of($hasOneClass, 'WidgetArea')) { if ($hasOneClass == 'WidgetArea' || is_subclass_of($hasOneClass, 'WidgetArea')) {
@ -54,15 +57,15 @@ class WidgetContentControllerExtension extends Extension
break; break;
} }
$widget = $this->owner->data()->$widgetAreaRelation()->Widgets() $widget = $widgetOwner->$widgetAreaRelation()->Widgets()
->filter('ID', $SQL_id) ->filter('ID', $SQL_id)
->First(); ->First();
} }
if (!$widget) { if (!$widget) {
user_error('No widget found', E_USER_ERROR); user_error('No widget found', E_USER_ERROR);
} }
return $widget->getController(); return $widget->getController();
} }
} }

View File

@ -1,21 +1,21 @@
<?php <?php
/** /**
* 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 * It always handles a single widget, usually passed in as a database
* identifier through the controller URL. Needs to be constructed as a nested * identifier through the controller URL. Needs to be constructed as a nested
* controller within a {@link ContentController}. * controller within a {@link ContentController}.
* *
* ## Forms * ## Forms
* You can add forms like in any other SilverStripe controller. If you need * You can add forms like in any other SilverStripe controller. If you need
* access to the widget from within a form, you can use * access to the widget from within a form, you can use
* `$this->controller->getWidget()` inside the form logic. * `$this->controller->getWidget()` inside the form logic.
* *
* Note: Widget controllers currently only work on {@link Page} objects, * Note: Widget controllers currently only work on {@link Page} objects,
* because the logic is implemented in {@link ContentController->handleWidget()}. * because the logic is implemented in {@link ContentController->handleWidget()}.
* Copy this logic and the URL rules to enable it for other controllers. * Copy this logic and the URL rules to enable it for other controllers.
* *
* @package widgets * @package widgets
*/ */
class WidgetController extends Controller class WidgetController extends Controller
@ -41,84 +41,99 @@ class WidgetController extends Controller
$this->widget = $widget; $this->widget = $widget;
$this->failover = $widget; $this->failover = $widget;
} }
parent::__construct(); parent::__construct();
} }
/** /**
* @param string $action * @param string $action
* @return string * @return string
*/ */
public function Link($action = null) public function Link($action = null)
{ {
$id = ($this->widget) ? $this->widget->ID : 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()) { $page = Director::get_current_page();
return $page->Link($segment); if($page && !($page instanceof WidgetController)) {return $page->Link($segment);
} }
return Controller::curr()->Link($segment); if ($controller = $this->getParentController()) {return $controller->Link($segment);
} }
/** return $segment;
* @return Widget }
*/
public function getWidget() /**
{ * Cycles up the controller stack until it finds a non-widget controller
return $this->widget; * This is needed becauseController::currreturns the widget controller,
} * which means anyLinkfunction turns into endless loop.
*
/** * @return Controller
* Overloaded from {@link Widget->Content()} to allow for controller / form */
* linking. public function getParentController()
*
* @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");
}
/**
* 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()
{ {
foreach(Controller::$controller_stack as $controller) {
if (!($controller instanceof WidgetController)) {
return $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");
}
/**
* 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 // use left and main to set the html config
$leftandmain = LeftAndMain::create(); $leftandmain = LeftAndMain::create();
$leftandmain->init(); $leftandmain->init();
$className = $this->urlParams['ID'];
$className = $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; i18n::set_locale($locale);
i18n::set_locale($locale); }
} if(class_exists($className) && is_subclass_of($className, 'Widget')) {
if (class_exists($className) && is_subclass_of($className, 'Widget')) { $obj = new $className();
$obj = new $className(); return $obj->EditableSegment();
return $obj->EditableSegment(); } else {
} else { user_error("Bad widget class: $className", E_USER_WARNING);
user_error("Bad widget class: $className", E_USER_WARNING); return "Bad widget class name given";
return "Bad widget class name given"; }
} }
}
} }
/** /**

View File

@ -1,7 +1,7 @@
ar: ar:
Widget: Widget:
PLURALNAME: تطبيقات مصغرة PLURALNAME: 'تطبيقات مصغرة'
SINGULARNAME: تطبيق مصغر SINGULARNAME: 'تطبيق مصغر'
WidgetArea: WidgetArea:
PLURALNAME: 'مساحات التطبيقات المصغرة' PLURALNAME: 'مساحات التطبيقات المصغرة'
SINGULARNAME: 'مساحة التطبيقات المصغرة' SINGULARNAME: 'مساحة التطبيقات المصغرة'
@ -14,4 +14,4 @@ ar:
WidgetDescription_ss: WidgetDescription_ss:
CLICKTOADDWIDGET: 'اضغط لإضافة هذا التطبيق المصغر' CLICKTOADDWIDGET: 'اضغط لإضافة هذا التطبيق المصغر'
WidgetEditor_ss: WidgetEditor_ss:
DELETE: مسح DELETE: 'مسح'

View File

@ -3,8 +3,8 @@ de:
PLURALNAME: Widgets PLURALNAME: Widgets
SINGULARNAME: Widget SINGULARNAME: Widget
WidgetArea: WidgetArea:
PLURALNAME: 'Widgetbereiche' PLURALNAME: Widgetbereiche
SINGULARNAME: 'Widgetbereich' SINGULARNAME: Widgetbereich
WidgetAreaEditor_ss: WidgetAreaEditor_ss:
AVAILABLE: 'Vorhandene Widgets' AVAILABLE: 'Vorhandene Widgets'
AVAILWIDGETS: 'Klicke den Widget Titel, um es zu benutzen.' AVAILWIDGETS: 'Klicke den Widget Titel, um es zu benutzen.'

View File

@ -1,6 +1,6 @@
fa_IR: fa_IR:
Widget: Widget:
PLURALNAME: ویجت ها PLURALNAME: 'ویجت ها'
SINGULARNAME: ویجت SINGULARNAME: ویجت
WidgetArea: WidgetArea:
PLURALNAME: 'محیط ویجت ها' PLURALNAME: 'محیط ویجت ها'

17
lang/sk.yml Normal file
View 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ť

View File

@ -3,8 +3,8 @@ sv:
PLURALNAME: Widgets PLURALNAME: Widgets
SINGULARNAME: Widget SINGULARNAME: Widget
WidgetArea: WidgetArea:
PLURALNAME: 'Widgetområden' PLURALNAME: Widgetområden
SINGULARNAME: 'Widgetområde' SINGULARNAME: Widgetområde
WidgetAreaEditor_ss: WidgetAreaEditor_ss:
AVAILABLE: 'Tillgängliga widgets' AVAILABLE: 'Tillgängliga widgets'
AVAILWIDGETS: 'Klicka på en widget nedan för att använda den på sidan.' AVAILWIDGETS: 'Klicka på en widget nedan för att använda den på sidan.'

View File

@ -1,7 +1,7 @@
zh: zh:
Widget: Widget:
PLURALNAME: 小工具 PLURALNAME: '小工具'
SINGULARNAME: 小工具 SINGULARNAME: '小工具'
WidgetArea: WidgetArea:
PLURALNAME: '小工具区域' PLURALNAME: '小工具区域'
SINGULARNAME: '小工具区域' SINGULARNAME: '小工具区域'
@ -14,4 +14,4 @@ zh:
WidgetDescription_ss: WidgetDescription_ss:
CLICKTOADDWIDGET: '点击添加该小工具' CLICKTOADDWIDGET: '点击添加该小工具'
WidgetEditor_ss: WidgetEditor_ss:
DELETE: 删除 DELETE: '删除'