mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allow setting the Form template by calling Form->setTemplate('MyTemplateName') without having to subclass Form
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@72950 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
30cd13f0af
commit
e5712d46ef
@ -79,6 +79,16 @@ class Form extends RequestHandler {
|
||||
*/
|
||||
protected $legend;
|
||||
|
||||
/**
|
||||
* The SS template to render this form HTML into.
|
||||
* Default is "Form", but this can be changed to
|
||||
* another template for customisation.
|
||||
*
|
||||
* @see Form->setTemplate()
|
||||
* @var string
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
protected $buttonClickedFunc;
|
||||
|
||||
protected $message;
|
||||
@ -507,6 +517,28 @@ class Form extends RequestHandler {
|
||||
$this->legend = $legend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the SS template that this form should use
|
||||
* to render with. The default is "Form".
|
||||
*
|
||||
* @param string $template The name of the template (without the .ss extension)
|
||||
*/
|
||||
function setTemplate($template) {
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template to render this form with.
|
||||
* If the template isn't set, then default to the
|
||||
* form class name e.g "Form".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTemplate() {
|
||||
if($this->template) return $this->template;
|
||||
else return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the encoding type of the form.
|
||||
* This will be either "multipart/form-data"" if there are any {@link FileField} instances,
|
||||
@ -955,14 +987,12 @@ class Form extends RequestHandler {
|
||||
/**
|
||||
* Return a rendered version of this form.
|
||||
*
|
||||
* This also allows for subclasses of Form to have their own template,
|
||||
* falling back to 'Form' if it doesn't exist.
|
||||
*
|
||||
* This is returned when you access a form as $FormObject rather than <% control FormObject %>
|
||||
* This is returned when you access a form as $FormObject rather
|
||||
* than <% control FormObject %>
|
||||
*/
|
||||
function forTemplate() {
|
||||
return $this->renderWith(array(
|
||||
$this->class,
|
||||
$this->getTemplate(),
|
||||
'Form'
|
||||
));
|
||||
}
|
||||
@ -972,7 +1002,7 @@ class Form extends RequestHandler {
|
||||
* It triggers slightly different behaviour, such as disabling the rewriting of # links
|
||||
*/
|
||||
function forAjaxTemplate() {
|
||||
$view = new SSViewer("Form");
|
||||
$view = new SSViewer($this->getTemplate());
|
||||
return $view->dontRewriteHashlinks()->process($this);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user