silverstripe-framework/forms/FormAction.php
Hayden Smith 130ecfe5aa Merged [47044]: Introduces modifications to Sapphire's form handling that allows it to ignore fields marked as Disabled when saving the contents of a form's fields to a DataObject.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60469 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-08-12 02:58:48 +00:00

90 lines
2.5 KiB
PHP
Executable File

<?php
/**
* Single action button.
* The action buttons are <input type="submit"> tags.
* @package forms
* @subpackage actions
*/
class FormAction extends FormField {
protected $extraData;
protected $action;
/**
* Enables the use of <button> instead of <input>
* in {@link Field()} - for more customizeable styling.
*
* @var boolean $useButtonTag
*/
public $useButtonTag = false;
/**
* Create a new action button.
* @param action The method to call when the button is clicked
* @param title The label on the button
* @param form The parent form, auto-set when the field is placed inside a form
* @param extraData A piece of extra data that can be extracted with $this->extraData. Useful for
* calling $form->buttonClicked()->extraData()
* @param extraClass A CSS class to apply to the button in addition to 'action'
*/
function __construct($action, $title = "", $form = null, $extraData = null, $extraClass = '') {
$this->extraData = $extraData;
$this->extraClass = ' '.$extraClass;
$this->action = "action_$action";
parent::__construct($this->action, $title, null, $form);
}
static function create($action, $title = "", $extraData = null, $extraClass = null) {
return new FormAction($action, $title, null, $extraData, $extraClass);
}
function actionName() {
return substr($this->name,7);
}
/**
* Set the full action name, including action_
* This provides an opportunity to replace it with something else
*/
function setFullAction($fullAction) {
$this->action = $fullAction;
}
function extraData() {
return $this->extraData;
}
function Field() {
$titleAttr = $this->description ? "title=\"" . Convert::raw2att($this->description) . "\"" : '';
if($this->useButtonTag) {
return "<button class=\"action " . $this->extraClass() . "\" id=\"" . $this->id() . "\" type=\"submit\" name=\"$this->action\" $titleAttr />" . $this->attrTitle() . "</button>\n";
} else {
return "<input class=\"action " . $this->extraClass() . "\" id=\"" . $this->id() . "\" type=\"submit\" name=\"$this->action\" value=\"" . $this->attrTitle() . "\" $titleAttr />\n";
}
}
/**
* Does not transform to readonly by purpose.
* Globally disabled buttons would break the CMS.
*/
function performReadonlyTransformation() {
$this->setDisabled(true);
return $this;
}
function readonlyField() {
return $this;
}
}
/**
* @package forms
* @subpackage actions
*/
class FormAction_WithoutLabel extends FormAction {
function Title(){
return null;
}
}
?>