silverstripe-framework/forms/InlineFormAction.php
Sam Minnee aeccb8b8e0 API: Move DBField subclasses into SilverStripe\Model\FieldType namespace
API: Deprecate SS_Datetime.

The DBField subclasses are have all been renamed to start with “DB” and
be in the SilverStripe\Model\FieldType namespace. To keep DataObject
definitions concise, the original short variations of their names are
preserved as service definitions. Most of the field generation code
doesn’t need to change, but where field classes are referenced directly,
changes will be needed.

SS_Datetime, which is commonly referenced outside the model system
itself, has been preserved as a subclass of DBDatetime. This has been
marked as deprecated and can be removed in SilverStripe 5.

A few places that referred to $db and $casting values weren’t using
the Injector to instantiate the relevant classes. This meant that the
remapping we have created as part of moving classes into a namespace
didn’t work.
2016-03-22 18:09:30 +13:00

100 lines
2.4 KiB
PHP

<?php
use SilverStripe\Model\FieldType\DBField;
/**
* Render a button that will submit the form its contained in through ajax.
* If you want to add custom behaviour, please set {@link includeDefaultJS()} to FALSE
*
* @see framework/javascript/dist/InlineFormAction.js
*
* @package forms
* @subpackage actions
*/
class InlineFormAction extends FormField {
protected $includeDefaultJS = true;
/**
* Create a new action button.
* @param action The method to call when the button is clicked
* @param title The label on the button
* @param extraClass A CSS class to apply to the button in addition to 'action'
*/
public function __construct($action, $title = "", $extraClass = '') {
$this->extraClass = ' '.$extraClass;
parent::__construct($action, $title);
}
public function performReadonlyTransformation() {
return $this->castedCopy('InlineFormAction_ReadOnly');
}
/**
* @param array $properties
* @return HTMLText
*/
public function Field($properties = array()) {
if($this->includeDefaultJS) {
Requirements::javascriptTemplate(FRAMEWORK_DIR . '/javascript/dist/InlineFormAction.js',
array('ID'=>$this->id()));
}
return DBField::create_field(
'HTMLText',
FormField::create_tag('input', array(
'type' => 'submit',
'name' => sprintf('action_%s', $this->getName()),
'value' => $this->title,
'id' => $this->ID(),
'class' => sprintf('action%s', $this->extraClass),
))
);
}
public function Title() {
return false;
}
/**
* Optionally disable the default javascript include (framework/javascript/dist/InlineFormAction.js),
* which routes to an "admin-custom"-URL.
*
* @param $bool boolean
*/
public function includeDefaultJS($bool) {
$this->includeDefaultJS = (bool)$bool;
}
}
/**
* Readonly version of {@link InlineFormAction}.
* @package forms
* @subpackage actions
*/
class InlineFormAction_ReadOnly extends FormField {
protected $readonly = true;
/**
* @param array $properties
* @return HTMLText
*/
public function Field($properties = array()) {
return DBField::create_field('HTMLText',
FormField::create_tag('input', array(
'type' => 'submit',
'name' => sprintf('action_%s', $this->name),
'value' => $this->title,
'id' => $this->id(),
'disabled' => 'disabled',
'class' => 'action disabled ' . $this->extraClass,
))
);
}
public function Title() {
return false;
}
}