MINOR Moved some CMS-specific template config into GridFieldPopupForms, to make the external API easier to use, and make specific configs less dependent on the instanciation context, and more tuned to the actual execution controller context

This commit is contained in:
Ingo Schommer 2012-02-27 17:43:32 +01:00
parent ba0d1c60cb
commit 3b53ed1937
3 changed files with 16 additions and 6 deletions

View File

@ -478,7 +478,7 @@ class LeftAndMain extends Controller {
/**
* Return a list of appropriate templates for this class, with the given suffix
*/
protected function getTemplatesWithSuffix($suffix) {
public function getTemplatesWithSuffix($suffix) {
$classes = array_reverse(ClassInfo::ancestry($this->class));
foreach($classes as $class) {
$templates[] = $class . $suffix;

View File

@ -405,8 +405,7 @@ class Folder extends File {
$config->addComponent(new GridFieldPaginator(10));
$config->addComponent(new GridFieldAction_Delete());
$config->addComponent(new GridFieldAction_Edit());
$config->addComponent($gridFieldForm = new GridFieldPopupForms();
$gridFieldForm->setTemplate('CMSGridFieldPopupForms');
$config->addComponent($gridFieldForm = new GridFieldPopupForms());
$files = DataList::create('File')->filter('ParentID', $this->ID)->exclude('ClassName', 'Folder');
$gridField = new GridField('File','Files', $files, $config);
$gridField->setDisplayFields(array(

View File

@ -14,7 +14,7 @@ class GridFieldPopupForms implements GridField_URLHandler {
/**
* @var String
*/
protected $template = 'GridFieldItemEditView';
protected $template = 'GridFieldPopupForms';
/**
*
@ -51,6 +51,7 @@ class GridFieldPopupForms implements GridField_URLHandler {
*/
public function handleItem($gridField, $request) {
$controller = $gridField->getForm()->Controller();
if(is_numeric($request->param('ID'))) {
$record = $gridField->getList()->byId($request->param("ID"));
} else {
@ -161,7 +162,16 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
function edit($request) {
$controller = $this->popupController;
$form = $this->ItemEditForm($this->gridField, $request);
// TODO Coupling with CMS
if($controller instanceof LeftAndMain) {
$form->addExtraClass('cms-edit-form');
$form->setTemplate($controller->getTemplatesWithSuffix('_EditForm'));
$form->addExtraClass('cms-content center ss-tabset ' . $controller->BaseCSSClasses());
if($form->Fields()->hasTabset()) $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
}
$return = $this->customise(array(
'Backlink' => $controller->Link(),
'ItemEditForm' => $form,
@ -173,7 +183,8 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
// If not requested by ajax, we need to render it within the controller context+template
return $controller->customise(array(
$this->popupFormName => $return,
// TODO Allow customization
'Content' => $return,
));
}
}