2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2010-10-15 02:04:14 +02:00
|
|
|
* Represents a field in a form.
|
|
|
|
*
|
2011-10-28 03:37:27 +02:00
|
|
|
* A FieldList contains a number of FormField objects which make up the whole of a form.
|
2007-07-19 12:40:28 +02:00
|
|
|
* In addition to single fields, FormField objects can be "composite", for example, the {@link TabSet}
|
|
|
|
* field. Composite fields let us define complex forms without having to resort to custom HTML.
|
2010-10-15 02:04:14 +02:00
|
|
|
*
|
|
|
|
* <b>Subclassing</b>
|
|
|
|
*
|
|
|
|
* Define a {@link dataValue()} method that returns a value suitable for inserting into a single database field.
|
|
|
|
* For example, you might tidy up the format of a date or currency field.
|
|
|
|
* Define {@link saveInto()} to totally customise saving.
|
|
|
|
* For example, data might be saved to the filesystem instead of the data record,
|
|
|
|
* or saved to a component of the data record instead of the data record itself.
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage core
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-10-30 23:03:21 +01:00
|
|
|
class FormField extends RequestHandler {
|
2011-03-23 05:12:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var Form
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $form;
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $name, $title, $value ,$message, $messageType, $extraClass;
|
2007-10-05 00:17:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var $description string Adds a "title"-attribute to the markup.
|
2008-01-11 02:49:50 +01:00
|
|
|
* @todo Implement in all subclasses
|
2007-10-05 00:17:44 +02:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $description;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var $extraClasses array Extra CSS-classes for the formfield-container
|
|
|
|
*/
|
|
|
|
protected $extraClasses;
|
|
|
|
|
|
|
|
public $dontEscape;
|
|
|
|
|
|
|
|
/**
|
2012-06-01 05:00:21 +02:00
|
|
|
* @var $rightTitle string Used in SmallFieldHolder to force a right-aligned label, or in FieldHolder
|
|
|
|
* to create contextual label.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
protected $rightTitle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var $leftTitle string Used in SmallFieldHolder() to force a left-aligned label with correct spacing.
|
2009-06-27 09:00:01 +02:00
|
|
|
* Please use $title for FormFields rendered with FieldHolder().
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
protected $leftTitle;
|
|
|
|
|
2008-09-11 02:02:49 +02:00
|
|
|
/**
|
2011-10-28 03:37:27 +02:00
|
|
|
* Stores a reference to the FieldList that contains this object.
|
|
|
|
* @var FieldList
|
2012-05-14 04:42:54 +02:00
|
|
|
*/
|
|
|
|
protected $containerFieldList;
|
2008-04-06 06:01:28 +02:00
|
|
|
|
2008-08-12 04:58:48 +02:00
|
|
|
/**
|
2012-04-14 07:32:29 +02:00
|
|
|
* @var boolean
|
2008-08-12 04:58:48 +02:00
|
|
|
*/
|
|
|
|
protected $readonly = false;
|
|
|
|
|
|
|
|
/**
|
2012-04-14 07:32:29 +02:00
|
|
|
* @var boolean
|
2008-08-12 04:58:48 +02:00
|
|
|
*/
|
|
|
|
protected $disabled = false;
|
|
|
|
|
2011-04-16 05:09:30 +02:00
|
|
|
/**
|
2012-04-14 07:32:29 +02:00
|
|
|
* @var string custom validation message for the Field
|
2009-04-29 01:55:53 +02:00
|
|
|
*/
|
|
|
|
protected $customValidationMessage = "";
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
/**
|
2012-04-14 07:32:29 +02:00
|
|
|
* Name of the template used to render this form field. If not set, then
|
|
|
|
* will look up the class ancestry for the first matching template where
|
|
|
|
* the template name equals the class name.
|
|
|
|
*
|
|
|
|
* To explicitly use a custom template or one named other than the form
|
|
|
|
* field see {@link setTemplate()}, {@link setFieldHolderTemplate()}
|
|
|
|
*
|
2011-03-23 05:12:25 +01:00
|
|
|
* @var string
|
|
|
|
*/
|
2012-04-14 07:32:29 +02:00
|
|
|
protected
|
|
|
|
$template,
|
|
|
|
$fieldHolderTemplate,
|
|
|
|
$smallFieldHolderTemplate;
|
|
|
|
|
2011-12-22 13:10:57 +01:00
|
|
|
/**
|
|
|
|
* @var array All attributes on the form field (not the field holder).
|
|
|
|
* Partially determined based on other instance properties, please use {@link getAttributes()}.
|
|
|
|
*/
|
|
|
|
protected $attributes = array();
|
|
|
|
|
2012-04-12 02:18:55 +02:00
|
|
|
/**
|
|
|
|
* Takes a fieldname and converts camelcase to spaced
|
|
|
|
* words. Also resolves combined fieldnames with dot syntax
|
|
|
|
* to spaced words.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* - 'TotalAmount' will return 'Total Amount'
|
|
|
|
* - 'Organisation.ZipCode' will return 'Organisation Zip Code'
|
|
|
|
*
|
|
|
|
* @param string $fieldName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function name_to_label($fieldName) {
|
|
|
|
if(strpos($fieldName, '.') !== false) {
|
|
|
|
$parts = explode('.', $fieldName);
|
|
|
|
$label = $parts[count($parts)-2] . ' ' . $parts[count($parts)-1];
|
|
|
|
} else {
|
|
|
|
$label = $fieldName;
|
|
|
|
}
|
|
|
|
$label = preg_replace("/([a-z]+)([A-Z])/","$1 $2", $label);
|
|
|
|
|
|
|
|
return $label;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Create a new field.
|
|
|
|
* @param name The internal field name, passed to forms.
|
|
|
|
* @param title The field label.
|
|
|
|
* @param value The value of the field.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($name, $title = null, $value = null) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->name = $name;
|
2012-09-25 16:12:53 +02:00
|
|
|
$this->title = ($title === null) ? self::name_to_label($name) : $title;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2010-04-14 06:40:04 +02:00
|
|
|
if($value !== NULL) $this->setValue($value);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2008-08-09 05:29:30 +02:00
|
|
|
/**
|
|
|
|
* Return a Link to this field
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Link($action = null) {
|
2009-10-11 02:07:16 +02:00
|
|
|
return Controller::join_links($this->form->FormAction(), 'field/' . $this->name, $action);
|
2008-08-09 05:29:30 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the HTML ID of the field - used in the template by label tags.
|
|
|
|
* The ID is generated as FormName_FieldName. All Field functions should ensure
|
|
|
|
* that this ID is included in the field.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function ID() {
|
2012-02-27 22:14:02 +01:00
|
|
|
$name = preg_replace('/(^-)|(-$)/', '', preg_replace('/[^A-Za-z0-9_-]+/', '-', $this->name));
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->form) return $this->form->FormName() . '_' . $name;
|
|
|
|
else return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the field name - used by templates.
|
2009-03-17 12:38:52 +01:00
|
|
|
*
|
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getName() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->name;
|
|
|
|
}
|
2011-05-05 16:48:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated 3.0 Use {@link getName()}.
|
|
|
|
*/
|
|
|
|
public function Name() {
|
2011-10-29 01:02:11 +02:00
|
|
|
Deprecation::notice('3.0', 'Use getName() instead.');
|
2011-05-05 16:48:45 +02:00
|
|
|
return $this->getName();
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
2009-03-17 12:38:52 +01:00
|
|
|
* Returns the field message, used by form validation.
|
|
|
|
* Use {@link setError()} to set this property.
|
|
|
|
*
|
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Message() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-03-17 12:38:52 +01:00
|
|
|
* Returns the field message type, used by form validation.
|
|
|
|
* Arbitrary value which is mostly used for CSS classes
|
|
|
|
* in the rendered HTML, e.g. "required".
|
|
|
|
* Use {@link setError()} to set this property.
|
|
|
|
*
|
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function MessageType() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->messageType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the field value - used by templates.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Value() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to save this form field into the given data object.
|
|
|
|
* By default, makes use of $this->dataValue()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function saveInto(DataObjectInterface $record) {
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->name) {
|
|
|
|
$record->setCastedField($this->name, $this->dataValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the field value suitable for insertion into the data object
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function dataValue() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the field label - used by templates.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Title() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setTitle($val) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->title = $val;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-06-01 05:00:21 +02:00
|
|
|
/**
|
|
|
|
* Gets the contextual label than can be used for additional field description.
|
|
|
|
* Can be shown to the right or under the field in question.
|
|
|
|
*
|
|
|
|
* @return string Contextual label text.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function RightTitle() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->rightTitle;
|
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-06-01 05:00:21 +02:00
|
|
|
/**
|
|
|
|
* Sets the contextual label.
|
|
|
|
*
|
|
|
|
* @param $val string Text to set on the label.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setRightTitle($val) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->rightTitle = $val;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function LeftTitle() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->leftTitle;
|
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setLeftTitle($val) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->leftTitle = $val;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2008-04-06 06:01:28 +02:00
|
|
|
/**
|
|
|
|
* Set tabindex HTML attribute
|
|
|
|
* (defaults to none).
|
|
|
|
*
|
2012-03-07 17:45:14 +01:00
|
|
|
* @deprecated 3.0 Use setAttribute("tabindex") instead
|
2008-04-06 06:01:28 +02:00
|
|
|
* @param int $index
|
|
|
|
*/
|
|
|
|
public function setTabIndex($index) {
|
2012-03-07 17:45:14 +01:00
|
|
|
Deprecation::notice('3.0', 'Use setAttribute("tabindex") instead');
|
|
|
|
$this->setAttribute($index);
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-04-06 06:01:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2008-04-06 06:01:28 +02:00
|
|
|
/**
|
|
|
|
* Get tabindex (if previously set)
|
2012-03-07 17:45:14 +01:00
|
|
|
*
|
|
|
|
* @deprecated 3.0 Use getAttribute("tabindex") instead
|
2008-04-06 06:01:28 +02:00
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getTabIndex() {
|
2012-03-07 17:45:14 +01:00
|
|
|
Deprecation::notice('3.0', 'Use getAttribute("tabindex") instead');
|
|
|
|
return $this->getAttribute('tabindex');
|
2008-04-06 06:01:28 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Compiles all CSS-classes. Optionally includes a "nolabel"-class
|
|
|
|
* if no title was set on the formfield.
|
2009-03-17 12:38:52 +01:00
|
|
|
* Uses {@link Message()} and {@link MessageType()} to add validatoin
|
|
|
|
* error classes which can be used to style the contained tags.
|
2007-07-19 12:40:28 +02:00
|
|
|
*
|
2012-04-14 07:32:29 +02:00
|
|
|
* @return string CSS-classnames
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function extraClass() {
|
2011-12-22 13:10:57 +01:00
|
|
|
$classes = array();
|
|
|
|
|
|
|
|
$classes[] = $this->Type();
|
|
|
|
|
|
|
|
if($this->extraClasses) $classes = array_merge($classes, array_values($this->extraClasses));
|
2009-03-17 12:38:52 +01:00
|
|
|
|
|
|
|
// Allow customization of label and field tag positioning
|
2011-12-22 13:10:57 +01:00
|
|
|
if(!$this->Title()) $classes[] = "nolabel";
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2009-03-17 12:38:52 +01:00
|
|
|
// Allow custom styling of any element in the container based
|
|
|
|
// on validation errors, e.g. red borders on input tags.
|
|
|
|
// CSS-Class needs to be different from the one rendered
|
|
|
|
// through {@link FieldHolder()}
|
2011-12-22 13:10:57 +01:00
|
|
|
if($this->Message()) $classes[] .= "holder-" . $this->MessageType();
|
2009-03-17 12:38:52 +01:00
|
|
|
|
2011-12-22 13:10:57 +01:00
|
|
|
return implode(' ', $classes);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a CSS-class to the formfield-container.
|
|
|
|
*
|
|
|
|
* @param $class String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function addExtraClass($class) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->extraClasses[$class] = $class;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a CSS-class from the formfield-container.
|
|
|
|
*
|
|
|
|
* @param $class String
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function removeExtraClass($class) {
|
2012-10-31 15:44:57 +01:00
|
|
|
$pos = array_search($class, $this->extraClasses);
|
|
|
|
if($pos !== false) unset($this->extraClasses[$pos]);
|
|
|
|
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 13:10:57 +01:00
|
|
|
/**
|
|
|
|
* Set an HTML attribute on the field element, mostly an <input> tag.
|
|
|
|
*
|
2012-04-21 01:05:47 +02:00
|
|
|
* Some attributes are best set through more specialized methods, to avoid interfering with built-in behaviour:
|
2012-03-07 17:45:14 +01:00
|
|
|
* - 'class': {@link addExtraClass()}
|
|
|
|
* - 'title': {@link setDescription()}
|
|
|
|
* - 'value': {@link setValue}
|
|
|
|
* - 'name': {@link setName}
|
|
|
|
*
|
2011-12-22 13:10:57 +01:00
|
|
|
* CAUTION Doesn't work on most fields which are composed of more than one HTML form field:
|
2012-09-26 23:34:00 +02:00
|
|
|
* AjaxUniqueTextField, CheckboxSetField, ComplexTableField, CompositeField, ConfirmedPasswordField,
|
|
|
|
* CountryDropdownField, CreditCardField, CurrencyField, DateField, DatetimeField, FieldGroup, GridField,
|
|
|
|
* HtmlEditorField, ImageField, ImageFormAction, InlineFormAction, ListBoxField, etc.
|
2011-12-22 13:10:57 +01:00
|
|
|
*
|
2012-04-14 07:32:29 +02:00
|
|
|
* @param string
|
|
|
|
* @param string
|
2011-12-22 13:10:57 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setAttribute($name, $value) {
|
2011-12-22 13:10:57 +01:00
|
|
|
$this->attributes[$name] = $value;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2011-12-22 13:10:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an HTML attribute defined by the field, or added through {@link setAttribute()}.
|
|
|
|
* Caution: Doesn't work on all fields, see {@link setAttribute()}.
|
|
|
|
*
|
2012-04-14 07:32:29 +02:00
|
|
|
* @return string
|
2011-12-22 13:10:57 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttribute($name) {
|
2011-12-22 13:10:57 +01:00
|
|
|
$attrs = $this->getAttributes();
|
|
|
|
return @$attrs[$name];
|
|
|
|
}
|
2012-06-13 09:57:54 +02:00
|
|
|
|
2011-12-22 13:10:57 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributes() {
|
2011-12-22 13:10:57 +01:00
|
|
|
$attrs = array(
|
|
|
|
'type' => 'text',
|
|
|
|
'name' => $this->getName(),
|
|
|
|
'value' => $this->Value(),
|
|
|
|
'class' => $this->extraClass(),
|
|
|
|
'id' => $this->ID(),
|
|
|
|
'disabled' => $this->isDisabled(),
|
2012-03-07 11:54:48 +01:00
|
|
|
'title' => $this->getDescription(),
|
2011-12-22 13:10:57 +01:00
|
|
|
);
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2011-12-22 13:10:57 +01:00
|
|
|
return array_merge($attrs, $this->attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Array Custom attributes to process. Falls back to {@link getAttributes()}.
|
|
|
|
* If at least one argument is passed as a string, all arguments act as excludes by name.
|
2012-04-14 07:32:29 +02:00
|
|
|
* @return string HTML attributes, ready for insertion into an HTML tag
|
2011-12-22 13:10:57 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getAttributesHTML($attrs = null) {
|
2011-12-22 13:10:57 +01:00
|
|
|
$exclude = (is_string($attrs)) ? func_get_args() : null;
|
|
|
|
|
|
|
|
if(!$attrs || is_string($attrs)) $attrs = $this->getAttributes();
|
|
|
|
|
|
|
|
// Remove empty
|
2012-04-20 02:22:40 +02:00
|
|
|
$attrs = array_filter((array)$attrs, function($v) {
|
|
|
|
return ($v || $v === 0 || $v === '0');
|
|
|
|
});
|
2011-12-22 13:10:57 +01:00
|
|
|
|
|
|
|
// Remove excluded
|
|
|
|
if($exclude) $attrs = array_diff_key($attrs, array_flip($exclude));
|
|
|
|
|
|
|
|
// Create markkup
|
|
|
|
$parts = array();
|
|
|
|
foreach($attrs as $name => $value) {
|
|
|
|
$parts[] = ($value === true) ? "{$name}=\"{$name}\"" : "{$name}=\"" . Convert::raw2att($value) . "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(' ', $parts);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a version of a title suitable for insertion into an HTML attribute
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function attrTitle() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return Convert::raw2att($this->title);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns a version of a title suitable for insertion into an HTML attribute
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function attrValue() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return Convert::raw2att($this->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the field value.
|
|
|
|
* Returns $this.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setValue($value) {
|
2012-07-28 01:11:03 +02:00
|
|
|
$this->value = $value;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-11-22 04:33:00 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the field name
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setName($name) {
|
2008-11-22 04:33:00 +01:00
|
|
|
$this->name = $name;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-11-22 04:33:00 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the container form.
|
|
|
|
* This is called whenever you create a new form and put fields inside it, so that you don't
|
|
|
|
* have to worry about linking the two.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setForm($form) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->form = $form;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-04-06 05:33:55 +02:00
|
|
|
/**
|
|
|
|
* Get the currently used form.
|
|
|
|
*
|
|
|
|
* @return Form
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getForm() {
|
2008-04-06 05:33:55 +02:00
|
|
|
return $this->form;
|
|
|
|
}
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2009-06-27 10:48:42 +02:00
|
|
|
/**
|
|
|
|
* Return TRUE if security token protection is enabled on the parent {@link Form}.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function securityTokenEnabled() {
|
2011-10-29 06:10:02 +02:00
|
|
|
$form = $this->getForm();
|
|
|
|
if(!$form) return false;
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2011-10-29 06:10:02 +02:00
|
|
|
return $form->getSecurityToken()->isEnabled();
|
2009-06-27 10:48:42 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Sets the error message to be displayed on the form field
|
|
|
|
* Set by php validation of the form
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setError($message, $messageType) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->message = $message;
|
|
|
|
$this->messageType = $messageType;
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2009-04-29 01:55:53 +02:00
|
|
|
/**
|
|
|
|
* Set the custom error message to show instead of the default
|
|
|
|
* format of Please Fill In XXX. Different from setError() as
|
|
|
|
* that appends it to the standard error messaging
|
|
|
|
*
|
2012-04-14 07:32:29 +02:00
|
|
|
* @param string Message for the error
|
2009-04-29 01:55:53 +02:00
|
|
|
*/
|
|
|
|
public function setCustomValidationMessage($msg) {
|
|
|
|
$this->customValidationMessage = $msg;
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2009-04-29 01:55:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the custom error message for this form field. If a custom
|
|
|
|
* message has not been defined then just return blank. The default
|
|
|
|
* error is defined on {@link Validator}.
|
|
|
|
*
|
|
|
|
* @todo Should the default error message be stored here instead
|
2012-04-14 07:32:29 +02:00
|
|
|
* @return string
|
2009-04-29 01:55:53 +02:00
|
|
|
*/
|
|
|
|
public function getCustomValidationMessage() {
|
|
|
|
return $this->customValidationMessage;
|
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2011-04-16 05:09:30 +02:00
|
|
|
/**
|
2011-12-21 17:35:42 +01:00
|
|
|
* Set name of template (without path or extension).
|
|
|
|
* Caution: Not consistently implemented in all subclasses,
|
|
|
|
* please check the {@link Field()} method on the subclass for support.
|
2011-04-16 05:09:30 +02:00
|
|
|
*
|
2012-04-14 07:32:29 +02:00
|
|
|
* @param string
|
2011-04-16 05:09:30 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setTemplate($template) {
|
2011-04-16 05:09:30 +02:00
|
|
|
$this->template = $template;
|
2012-04-14 07:32:29 +02:00
|
|
|
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2011-04-16 05:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-14 07:32:29 +02:00
|
|
|
* @return string
|
2011-04-16 05:09:30 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getTemplate() {
|
2011-04-16 05:09:30 +02:00
|
|
|
return $this->template;
|
|
|
|
}
|
|
|
|
|
2012-04-14 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFieldHolderTemplate() {
|
|
|
|
return $this->fieldHolderTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set name of template (without path or extension) for the holder,
|
|
|
|
* which in turn is responsible for rendering {@link Field()}.
|
|
|
|
*
|
|
|
|
* Caution: Not consistently implemented in all subclasses,
|
|
|
|
* please check the {@link Field()} method on the subclass for support.
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
public function setFieldHolderTemplate($template) {
|
|
|
|
$this->fieldHolderTemplate = $template;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSmallFieldHolderTemplate() {
|
|
|
|
return $this->smallFieldHolderTemplate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set name of template (without path or extension) for the small holder,
|
|
|
|
* which in turn is responsible for rendering {@link Field()}.
|
|
|
|
*
|
|
|
|
* Caution: Not consistently implemented in all subclasses,
|
|
|
|
* please check the {@link Field()} method on the subclass for support.
|
|
|
|
*
|
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
public function setSmallFieldHolderTemplate($template) {
|
|
|
|
$this->smallFieldHolderTemplate = $template;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the form field - used by templates.
|
|
|
|
* Although FieldHolder is generally what is inserted into templates, all of the field holder
|
|
|
|
* templates make use of $Field. It's expected that FieldHolder will give you the "complete"
|
|
|
|
* representation of the field on the form, whereas Field will give you the core editing widget,
|
|
|
|
* such as an input tag.
|
|
|
|
*
|
2011-03-23 05:12:25 +01:00
|
|
|
* @param array $properties key value pairs of template variables
|
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Field($properties = array()) {
|
2011-12-21 17:35:42 +01:00
|
|
|
$obj = ($properties) ? $this->customise($properties) : $this;
|
2012-04-14 07:32:29 +02:00
|
|
|
|
|
|
|
return $obj->renderWith($this->getTemplates());
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2011-03-23 05:12:25 +01:00
|
|
|
* Returns a "field holder" for this field - used by templates.
|
2007-07-19 12:40:28 +02:00
|
|
|
*
|
2011-03-23 05:12:25 +01:00
|
|
|
* Forms are constructed by concatenating a number of these field holders.
|
|
|
|
* The default field holder is a label and a form field inside a div.
|
|
|
|
* @see FieldHolder.ss
|
2007-11-23 02:10:19 +01:00
|
|
|
*
|
2011-03-23 05:12:25 +01:00
|
|
|
* @param array $properties key value pairs of template variables
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function FieldHolder($properties = array()) {
|
2011-12-21 17:35:42 +01:00
|
|
|
$obj = ($properties) ? $this->customise($properties) : $this;
|
2012-04-14 07:32:29 +02:00
|
|
|
|
|
|
|
return $obj->renderWith($this->getFieldHolderTemplates());
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2011-03-23 05:12:25 +01:00
|
|
|
/**
|
|
|
|
* Returns a restricted field holder used within things like FieldGroups.
|
2012-04-14 07:32:29 +02:00
|
|
|
*
|
|
|
|
* @param array $properties
|
|
|
|
*
|
|
|
|
* @return string
|
2011-03-23 05:12:25 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function SmallFieldHolder($properties = array()) {
|
2012-04-14 07:32:29 +02:00
|
|
|
$obj = ($properties) ? $this->customise($properties) : $this;
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2012-04-14 07:32:29 +02:00
|
|
|
return $obj->renderWith($this->getSmallFieldHolderTemplates());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of templates to use for rendering {@link FieldH}
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getTemplates() {
|
|
|
|
return $this->_templates($this->getTemplate());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of templates to use for rendering {@link FieldHolder}
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFieldHolderTemplates() {
|
|
|
|
return $this->_templates(
|
|
|
|
$this->getFieldHolderTemplate(),
|
|
|
|
'_holder'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of templates to use for rendering {@link SmallFieldHolder}
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getSmallFieldHolderTemplates() {
|
|
|
|
return $this->_templates(
|
|
|
|
$this->getSmallFieldHolderTemplate(),
|
|
|
|
'_holder_small'
|
|
|
|
);
|
|
|
|
}
|
2011-03-23 05:12:25 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-04-14 07:32:29 +02:00
|
|
|
/**
|
|
|
|
* Generate an array of classname strings to use for rendering this form
|
|
|
|
* field into HTML
|
|
|
|
*
|
|
|
|
* @param string $custom custom template (if set)
|
|
|
|
* @param string $suffix template suffix
|
|
|
|
*
|
|
|
|
* @return array $stack a stack of
|
|
|
|
*/
|
|
|
|
private function _templates($custom = null, $suffix = null) {
|
|
|
|
$matches = array();
|
|
|
|
|
|
|
|
foreach(array_reverse(ClassInfo::ancestry($this)) as $className) {
|
|
|
|
$matches[] = $className . $suffix;
|
|
|
|
|
|
|
|
if($className == "FormField") break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($custom) array_unshift($matches, $custom);
|
|
|
|
|
|
|
|
return $matches;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns true if this field is a composite field.
|
|
|
|
* To create composite field types, you should subclass {@link CompositeField}.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function isComposite() {
|
2011-03-23 05:12:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns true if this field has its own data.
|
|
|
|
* Some fields, such as titles and composite fields, don't actually have any data. It doesn't
|
|
|
|
* make sense for data-focused methods to look at them. By overloading hasData() to return false,
|
|
|
|
* you can prevent any data-focused methods from looking at it.
|
|
|
|
*
|
2011-10-28 03:37:27 +02:00
|
|
|
* @see FieldList::collateDataFields()
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function hasData() {
|
2011-03-23 05:12:25 +01:00
|
|
|
return true;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2008-08-12 04:58:48 +02:00
|
|
|
/**
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function isReadonly() {
|
2008-08-12 04:58:48 +02:00
|
|
|
return $this->readonly;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets readonly-flag on form-field. Please use performReadonlyTransformation()
|
|
|
|
* to actually transform this instance.
|
|
|
|
* @param $bool boolean Setting "false" has no effect on the field-state.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setReadonly($bool) {
|
2008-08-12 04:58:48 +02:00
|
|
|
$this->readonly = $bool;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-08-12 04:58:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function isDisabled() {
|
2012-04-12 02:18:55 +02:00
|
|
|
return $this->disabled;
|
2008-08-12 04:58:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets disabed-flag on form-field. Please use performDisabledTransformation()
|
|
|
|
* to actually transform this instance.
|
|
|
|
* @param $bool boolean Setting "false" has no effect on the field-state.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setDisabled($bool) {
|
2012-04-12 02:18:55 +02:00
|
|
|
$this->disabled = $bool;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performReadonlyTransformation() {
|
2007-07-19 12:40:28 +02:00
|
|
|
$field = new ReadonlyField($this->name, $this->title, $this->value);
|
2008-10-16 02:43:00 +02:00
|
|
|
$field->addExtraClass($this->extraClass());
|
2007-07-19 12:40:28 +02:00
|
|
|
$field->setForm($this->form);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-04-12 02:18:55 +02:00
|
|
|
* Return a disabled version of this field.
|
|
|
|
* Tries to find a class of the class name of this field suffixed with "_Disabled",
|
|
|
|
* failing that, finds a method {@link setDisabled()}.
|
|
|
|
*
|
|
|
|
* @return FormField
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function performDisabledTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$disabledClassName = $clone->class . '_Disabled';
|
2012-04-12 02:18:55 +02:00
|
|
|
if(ClassInfo::exists($disabledClassName)) {
|
|
|
|
return new $disabledClassName($this->name, $this->title, $this->value);
|
|
|
|
} else {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone->setDisabled(true);
|
|
|
|
return $clone;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-12 02:18:55 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function transform(FormTransformation $trans) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $trans->transform($this);
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function hasClass($class){
|
2007-11-23 02:10:19 +01:00
|
|
|
$patten = '/'.strtolower($class).'/i';
|
2007-11-25 22:07:02 +01:00
|
|
|
$subject = strtolower($this->class." ".$this->extraClass());
|
2007-11-23 02:10:19 +01:00
|
|
|
return preg_match($patten, $subject);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns the field type - used by templates.
|
|
|
|
* The field type is the class name with the word Field dropped off the end, all lowercase.
|
2011-12-22 13:10:57 +01:00
|
|
|
* It's handy for assigning HTML classes. Doesn't signify the <input type> attribute,
|
|
|
|
* see {link getAttributes()}.
|
|
|
|
*
|
2011-03-23 05:12:25 +01:00
|
|
|
* @return string
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Type() {
|
2012-02-27 22:14:02 +01:00
|
|
|
return strtolower(preg_replace('/Field$/', '', $this->class));
|
2011-03-23 05:12:25 +01:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-03-17 12:38:52 +01:00
|
|
|
* Construct and return HTML tag.
|
|
|
|
*
|
2011-03-23 05:12:25 +01:00
|
|
|
* @deprecated 3.0 Please define your own FormField template using {@link setFieldTemplate()}
|
|
|
|
* and/or {@link renderFieldTemplate()}
|
|
|
|
*
|
2009-03-17 12:38:52 +01:00
|
|
|
* @todo Transform to static helper method.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function createTag($tag, $attributes, $content = null) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$preparedAttributes = '';
|
|
|
|
foreach($attributes as $k => $v) {
|
2012-09-26 23:34:00 +02:00
|
|
|
// Note: as indicated by the $k == value item here; the decisions over what to include in the attributes
|
|
|
|
// can sometimes get finicky
|
|
|
|
if(!empty($v) || $v === '0' || $k == 'value') {
|
|
|
|
$preparedAttributes .= " $k=\"" . Convert::raw2att($v) . "\"";
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-10-03 04:59:38 +02:00
|
|
|
if($content || $tag != 'input') return "<$tag$preparedAttributes>$content</$tag>";
|
2007-07-19 12:40:28 +02:00
|
|
|
else return "<$tag$preparedAttributes />";
|
|
|
|
}
|
2012-04-12 02:18:55 +02:00
|
|
|
|
2008-03-06 03:06:47 +01:00
|
|
|
/**
|
2012-04-12 02:18:55 +02:00
|
|
|
* Abstract method each {@link FormField} subclass must implement,
|
|
|
|
* determines whether the field is valid or not based on the value.
|
|
|
|
* @todo Make this abstract.
|
|
|
|
*
|
|
|
|
* @param Validator
|
|
|
|
* @return boolean
|
2008-03-06 03:06:47 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function validate($validator) {
|
2009-02-02 00:49:53 +01:00
|
|
|
return true;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-03-07 11:54:48 +01:00
|
|
|
/**
|
|
|
|
* @deprecated 3.0 Use setDescription()
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function describe($description) {
|
2012-03-07 11:54:48 +01:00
|
|
|
Deprecation::notice('3.0', 'Use setDescription()');
|
|
|
|
$this->setDescription($description);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Describe this field, provide help text for it.
|
2012-03-07 11:54:48 +01:00
|
|
|
* By default, renders as a "title" attribute on the form field.
|
2011-07-04 09:41:15 +02:00
|
|
|
*
|
|
|
|
* @return string Description
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setDescription($description) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->description = $description;
|
2012-04-12 02:18:55 +02:00
|
|
|
return $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2012-02-16 21:47:33 +01:00
|
|
|
|
|
|
|
/**
|
2012-04-14 07:32:29 +02:00
|
|
|
* @return string
|
2012-02-16 21:47:33 +01:00
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function getDescription() {
|
2012-02-16 21:47:33 +01:00
|
|
|
return $this->description;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function debug() {
|
2012-09-26 23:34:00 +02:00
|
|
|
return "$this->class ($this->name: $this->title : <font style='color:red;'>$this->message</font>)"
|
|
|
|
. " = $this->value";
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by the template processor. If you refer to a field as a $ variable, it
|
|
|
|
* will return the $Field value.
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function forTemplate() {
|
2007-07-19 12:40:28 +02:00
|
|
|
return $this->Field();
|
|
|
|
}
|
|
|
|
|
2009-03-17 12:38:52 +01:00
|
|
|
/**
|
|
|
|
* @uses Validator->fieldIsRequired()
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function Required() {
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->form && ($validator = $this->form->Validator)) {
|
|
|
|
return $validator->fieldIsRequired($this->name);
|
|
|
|
}
|
|
|
|
}
|
2012-04-12 02:18:55 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setContainerFieldSet($list) {
|
2012-05-14 04:42:54 +02:00
|
|
|
Deprecation::notice('3.0', 'Use setContainerFieldList() instead.');
|
|
|
|
return $this->setContainerFieldList($list);
|
|
|
|
}
|
|
|
|
|
2008-09-11 02:02:49 +02:00
|
|
|
/**
|
2012-05-14 04:42:54 +02:00
|
|
|
* Set the FieldList that contains this field.
|
2008-09-11 02:02:49 +02:00
|
|
|
*
|
2012-05-14 04:42:54 +02:00
|
|
|
* @param FieldList $list
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function setContainerFieldList($list) {
|
2012-05-14 04:42:54 +02:00
|
|
|
$this->containerFieldList = $list;
|
2012-02-17 13:35:26 +01:00
|
|
|
return $this;
|
2008-09-11 02:02:49 +02:00
|
|
|
}
|
2012-05-14 04:42:54 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function rootFieldSet() {
|
2012-05-14 04:42:54 +02:00
|
|
|
Deprecation::notice('3.0', 'Use rootFieldList() instead.');
|
|
|
|
return $this->rootFieldList();
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function rootFieldList() {
|
2012-05-14 04:42:54 +02:00
|
|
|
if(is_object($this->containerFieldList)) return $this->containerFieldList->rootFieldList();
|
|
|
|
else user_error("rootFieldList() called on $this->class object without a containerFieldList", E_USER_ERROR);
|
2008-09-11 02:02:49 +02:00
|
|
|
}
|
|
|
|
|
2012-02-27 22:14:02 +01:00
|
|
|
}
|