mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 17:05:39 +02:00
Add utility request handler class
This commit is contained in:
parent
8b9ea0e1d6
commit
7d63584d42
12
README.md
12
README.md
@ -3,11 +3,17 @@ SilverStripe Grid Field Extensions Module
|
||||
|
||||
This module provides a number of useful grid field components:
|
||||
|
||||
* `GridFieldAddExistingSearchButton` - a more advanced search form for adding items.
|
||||
* `GridFieldAddNewInlineButton` - builds on `GridFieldEditableColumns` to allow inline creation of records.
|
||||
* `GridFieldAddNewMultiClass` - lets the user select from a list of classes to create a new record from.
|
||||
* `GridFieldAddExistingSearchButton` - a more advanced search form for adding
|
||||
items.
|
||||
* `GridFieldAddNewInlineButton` - builds on `GridFieldEditableColumns` to allow
|
||||
inline creation of records.
|
||||
* `GridFieldAddNewMultiClass` - lets the user select from a list of classes to
|
||||
create a new record from.
|
||||
* `GridFieldEditableColumns` - allows inline editing of records.
|
||||
* `GridFieldOrderableRows` - drag and drop re-ordering of rows.
|
||||
* `GridFieldRequestHandler` - a basic utility class which can be used to build
|
||||
custom grid field detail views including tabs, breadcrumbs and other CMS
|
||||
features.
|
||||
* `GridFieldTitleHeader` - a simple header which displays column titles.
|
||||
|
||||
See [docs/en/index.md](docs/en/index.md) for documentation and examples.
|
||||
|
147
code/GridFieldRequestHandler.php
Normal file
147
code/GridFieldRequestHandler.php
Normal file
@ -0,0 +1,147 @@
|
||||
<?php
|
||||
/**
|
||||
* A base utility class for request handlers which present a grid field detail
|
||||
* view.
|
||||
*
|
||||
* This class provides some useful defaults for grid field detail views, such
|
||||
* as tabs, breadcrumbs and a back link. Much of this code is extracted from the
|
||||
* detail form.
|
||||
*/
|
||||
abstract class GridFieldRequestHandler extends RequestHandler {
|
||||
|
||||
/**
|
||||
* @var GridField
|
||||
*/
|
||||
protected $grid;
|
||||
|
||||
/**
|
||||
* @var GridFieldComponent
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $template = __CLASS__;
|
||||
|
||||
public function __construct(GridField $grid, GridFieldComponent $component, $name) {
|
||||
$this->grid = $grid;
|
||||
$this->component = $component;
|
||||
$this->name = $name;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function index($request) {
|
||||
$result = $this->renderWith($this->template);
|
||||
|
||||
if($request->isAjax()) {
|
||||
return $result;
|
||||
} else {
|
||||
return $this->getTopLevelController()->customise(array(
|
||||
'Content' => $result
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function Link($action = null) {
|
||||
return Controller::join_links($this->grid->Link(), $this->name, $action);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be overloaded to build out the detail form.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function Form() {
|
||||
$form = new Form(
|
||||
$this,
|
||||
'Form',
|
||||
new FieldList($root = new TabSet('Root', new Tab('Main'))),
|
||||
new FieldList()
|
||||
);
|
||||
|
||||
if($this->getTopLevelController() instanceof LeftAndMain) {
|
||||
$form->setTemplate('LeftAndMain_EditForm');
|
||||
$form->addExtraClass('cms-content cms-edit-form cms-tabset center');
|
||||
$form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
|
||||
|
||||
$root->setTemplate('CMSTabSet');
|
||||
$form->Backlink = $this->getBackLink();
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Controller
|
||||
*/
|
||||
public function getController() {
|
||||
return $this->grid->getForm()->getController();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $template
|
||||
*/
|
||||
public function setTemplate($template) {
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTemplate() {
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayList
|
||||
*/
|
||||
public function getBreadcrumbs() {
|
||||
$controller = $this->getController();
|
||||
|
||||
if($controller->hasMethod('Breadcrumbs')) {
|
||||
return $controller->Breadcrumbs();
|
||||
} else {
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBackLink() {
|
||||
$controller = $this->getTopLevelController();
|
||||
|
||||
if($controller->hasMethod('Backlink')) {
|
||||
return $controller->Backlink();
|
||||
} else {
|
||||
return $controller->Link();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Controller
|
||||
*/
|
||||
protected function getTopLevelController() {
|
||||
$controller = $this->getController();
|
||||
|
||||
while($controller) {
|
||||
if($controller instanceof GridFieldRequestHandler) {
|
||||
$controller = $controller->getController();
|
||||
} elseif($controller instanceof GridFieldDetailForm_ItemRequest) {
|
||||
$controller = $controller->getController();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
}
|
5
templates/GridFieldRequestHandler.ss
Normal file
5
templates/GridFieldRequestHandler.ss
Normal file
@ -0,0 +1,5 @@
|
||||
<% if $BackLink %>
|
||||
<a href="$BackLink"><%t GridFieldExtensions.BACK "Back" %></a>
|
||||
<% end_if %>
|
||||
|
||||
$Form
|
Loading…
Reference in New Issue
Block a user