diff --git a/forms/gridfield/GridFieldLevelup.php b/forms/gridfield/GridFieldLevelup.php
index a7327842b..0e63e032b 100644
--- a/forms/gridfield/GridFieldLevelup.php
+++ b/forms/gridfield/GridFieldLevelup.php
@@ -1,49 +1,84 @@
levelID = $levelID;
- }
+ public function __construct($currentID) {
+ if($currentID && is_numeric($currentID)) $this->currentID = $currentID;
}
public function getHTMLFragments($gridField) {
$modelClass = $gridField->getModelClass();
- if(isset($_GET['ParentID']) && $_GET['ParentID']){
-
- $modelObj = DataObject::get_by_id($modelClass, $_GET['ParentID']);
-
- if(is_callable(array($modelObj, 'getParent'))){
- $levelup = $modelObj->getParent();
- if(!$levelup){
- $parentID = 0;
- }else{
- $parentID = $levelup->ID;
- }
+ $parentID = 0;
+
+ if($this->currentID) {
+ $modelObj = DataObject::get_by_id($modelClass, $this->currentID);
+
+ if($modelObj->hasMethod('getParent')) {
+ $parent = $modelObj->getParent();
+ } elseif($modelObj->ParentID) {
+ $parent = $modelObj->Parent();
}
- //$controller = $gridField->getForm()->Controller();
+
+ if($parent) $parentID = $parent->ID;
+
+ // Attributes
+ $attrs = array_merge($this->attributes, array(
+ 'href' => sprintf($this->linkSpec, $parentID),
+ 'class' => 'cms-panel-link list-parent-link'
+ ));
+ $attrsStr = '';
+ foreach($attrs as $k => $v) $attrsStr .= " $k=\"" . Convert::raw2att($v) . "\"";
+
$forTemplate = new ArrayData(array(
- 'UpLink' => sprintf(
- '%s',
- $parentID,
- _t('GridField.LEVELUP', 'Level up' )
- ),
+ 'UpLink' => sprintf('%s', $attrsStr, _t('GridField.LEVELUP', 'Level up'))
));
return array(
'before' => $forTemplate->renderWith('GridFieldLevelup'),
- //'header' => $forTemplate->renderWith('GridFieldLevelup_Row'),
);
}
}
+
+ public function setAttributes($attrs) {
+ $this->attributes = $attrs;
+ return $this;
+ }
+
+ public function getAttributes() {
+ return $this->attributes;
+ }
+
+ public function setLinkSpec($link) {
+ $this->linkSpec = $link;
+ return $this;
+ }
+
+ public function getLinkSpec() {
+ return $this->linkSpec;
+ }
}
-?>
\ No newline at end of file