code
stringlengths
17
247k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public function FieldMap() { return new Form_FieldMap($this); }
Returns an object where there is a method with the same name as each data field on the form. That method will return the field itself. It means that you can execute $firstName = $form->FieldMap()->FirstName()
FieldMap
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function sessionMessage($message, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT) { if ($cast === null) { Deprecation::notice( '5.4.0', 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', Deprecation::SCOPE_GLOBAL ); $cast = ValidationResult::CAST_TEXT; } $this->setMessage($message, $type, $cast); $result = $this->getSessionValidationResult() ?: ValidationResult::create(); $result->addMessage($message, $type, null, $cast); $this->setSessionValidationResult($result); }
Set a message to the session, for display next time this form is shown. @param string $message the text of the message @param string $type Should be set to good, bad, or warning. @param string|bool $cast Cast type; One of the CAST_ constant definitions. Bool values will be treated as plain text flag.
sessionMessage
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function sessionError($message, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT) { if ($cast === null) { Deprecation::notice( '5.4.0', 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', Deprecation::SCOPE_GLOBAL ); $cast = ValidationResult::CAST_TEXT; } $this->setMessage($message, $type, $cast); $result = $this->getSessionValidationResult() ?: ValidationResult::create(); $result->addError($message, $type, null, $cast); $this->setSessionValidationResult($result); }
Set an error to the session, for display next time this form is shown. @param string $message the text of the message @param string $type Should be set to good, bad, or warning. @param string|bool $cast Cast type; One of the CAST_ constant definitions. Bool values will be treated as plain text flag.
sessionError
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function sessionFieldError($message, $fieldName, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT) { if ($cast === null) { Deprecation::notice( '5.4.0', 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.', Deprecation::SCOPE_GLOBAL ); $cast = ValidationResult::CAST_TEXT; } $this->setMessage($message, $type, $cast); $result = $this->getSessionValidationResult() ?: ValidationResult::create(); $result->addFieldMessage($fieldName, $message, $type, null, $cast); $this->setSessionValidationResult($result); }
Set an error message for a field in the session, for display next time this form is shown. @param string $message the text of the message @param string $fieldName Name of the field to set the error message on it. @param string $type Should be set to good, bad, or warning. @param string|bool $cast Cast type; One of the CAST_ constant definitions. Bool values will be treated as plain text flag.
sessionFieldError
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function getRecord() { return $this->record; }
Returns the record that has given this form its data through {@link loadDataFrom()}. @return ViewableData
getRecord
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function getLegend() { return $this->legend; }
Get the legend value to be inserted into the <legend> element in Form.ss @return string
getLegend
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function validationResult() { Deprecation::notice('5.4.0', 'Use validate() instead'); return $this->validate(); }
Alias of validate() for backwards compatibility. @return ValidationResult @deprecated 5.4.0 Use validate() instead
validationResult
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function getData() { $dataFields = $this->fields->dataFields(); $data = []; if ($dataFields) { foreach ($dataFields as $field) { if ($field->getName()) { $data[$field->getName()] = $field->dataValue(); } } } return $data; }
Get the submitted data from this form through {@link FieldList->dataFields()}, which filters out any form-specific data like form-actions. Calls {@link FormField->dataValue()} on each field, which returns a value suitable for insertion into a record property. @return array
getData
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function forTemplate() { if (!$this->canBeCached()) { HTTPCacheControlMiddleware::singleton()->disableCache(); } $context = $this; $this->extend('onBeforeRender', $context); $return = $context->renderWith($context->getTemplates()); // Now that we're rendered, clear message $context->clearMessage(); return $return; }
Return a rendered version of this form. This is returned when you access a form as $FormObject rather than <% with FormObject %> @return DBHTMLText
forTemplate
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function forAjaxTemplate() { $view = SSViewer::create($this->getTemplates()); $return = $view->dontRewriteHashlinks()->process($this); // Now that we're rendered, clear message $this->clearMessage(); return $return; }
Return a rendered version of this form, suitable for ajax post-back. It triggers slightly different behaviour, such as disabling the rewriting of # links. @return DBHTMLText
forAjaxTemplate
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function renderWithoutActionButton($template) { $custom = $this->customise([ "Actions" => "", ]); if (is_string($template)) { $template = SSViewer::create($template); } return $template->process($custom); }
Render this form using the given template, and return the result as a string You can pass either an SSViewer or a template name @param string|array $template @return DBHTMLText
renderWithoutActionButton
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function defaultAction() { if ($this->hasDefaultAction && $this->actions) { return $this->actions->flattenFields()->filterByCallback(function ($field) { return $field instanceof FormAction; })->first(); } return null; }
Return the default button that should be clicked when another one isn't available. @return FormAction|null
defaultAction
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function disableDefaultAction() { $this->hasDefaultAction = false; return $this; }
Disable the default button. Ordinarily, when a form is processed and no action_XXX button is available, then the first button in the actions list will be pressed. However, if this is "delete", for example, this isn't such a good idea. @return Form
disableDefaultAction
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function disableSecurityToken() { $this->securityToken = new NullSecurityToken(); return $this; }
Disable the requirement of a security token on this form instance. This security protects against CSRF attacks, but you should disable this if you don't want to tie a form to a session - eg a search form. Check for token state with {@link getSecurityToken()} and {@link SecurityToken->isEnabled()}. @return Form
disableSecurityToken
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function getSecurityToken() { return $this->securityToken; }
Returns the security token for this form (if any exists). Doesn't check for {@link securityTokenEnabled()}. Use {@link SecurityToken::inst()} to get a global token. @return SecurityToken|null
getSecurityToken
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function hasExtraClass($class) { //split at white space $classes = preg_split('/\s+/', $class ?? ''); foreach ($classes as $class) { if (!isset($this->extraClasses[$class])) { return false; } } return true; }
Check if a CSS-class has been added to the form container. @param string $class A string containing a classname or several class names delimited by a single space. @return boolean True if all of the classnames passed in have been added.
hasExtraClass
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function addExtraClass($class) { //split at white space $classes = preg_split('/\s+/', $class ?? ''); foreach ($classes as $class) { //add classes one by one $this->extraClasses[$class] = $class; } return $this; }
Add a CSS-class to the form-container. If needed, multiple classes can be added by delimiting a string with spaces. @param string $class A string containing a classname or several class names delimited by a single space. @return $this
addExtraClass
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function getRequestHandler() { if (!$this->requestHandler) { $this->requestHandler = $this->buildRequestHandler(); } return $this->requestHandler; }
Get request handler for this form @return FormRequestHandler
getRequestHandler
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
public function setRequestHandler(FormRequestHandler $handler) { $this->requestHandler = $handler; return $this; }
Assign a specific request handler for this form @param FormRequestHandler $handler @return $this
setRequestHandler
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
protected function buildRequestHandler() { return FormRequestHandler::create($this); }
Scaffold new request handler for this form @return FormRequestHandler
buildRequestHandler
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
protected function canBeCached() { if ($this->getSecurityToken()->isEnabled()) { return false; } if ($this->FormMethod() !== 'GET') { return false; } $validator = $this->getValidator(); if (!$validator) { return true; } return $validator->canBeCached(); }
Can the body of this form be cached? @return bool
canBeCached
php
silverstripe/silverstripe-framework
src/Forms/Form.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Form.php
BSD-3-Clause
protected function getFieldOption($value, $title, $odd) { return new ArrayData([ 'ID' => $this->getOptionID($value), 'Class' => $this->getOptionClass($value, $odd), 'Role' => 'option', 'Name' => $this->getOptionName(), 'Value' => $value, 'Title' => $title, 'isChecked' => $this->isSelectedValue($value, $this->Value()), 'isDisabled' => $this->isDisabledValue($value) ]); }
Build a field option for template rendering @param mixed $value Value of the option @param string $title Title of the option @param boolean $odd True if this should be striped odd. Otherwise it should be striped even @return ArrayData Field option
getFieldOption
php
silverstripe/silverstripe-framework
src/Forms/OptionsetField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/OptionsetField.php
BSD-3-Clause
protected function getOptionID($value) { return $this->ID() . '_' . Convert::raw2htmlid($value); }
Generate an ID property for a single option @param string $value @return string
getOptionID
php
silverstripe/silverstripe-framework
src/Forms/OptionsetField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/OptionsetField.php
BSD-3-Clause
protected function getOptionName() { return $this->getName(); }
Get the "name" property for each item in the list @return string
getOptionName
php
silverstripe/silverstripe-framework
src/Forms/OptionsetField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/OptionsetField.php
BSD-3-Clause
protected function getOptionClass($value, $odd) { $oddClass = $odd ? 'odd' : 'even'; $valueClass = ' val' . Convert::raw2htmlid($value); return $oddClass . $valueClass; }
Get extra classes for each item in the list @param string $value Value of this item @param bool $odd If this item is odd numbered in the list @return string
getOptionClass
php
silverstripe/silverstripe-framework
src/Forms/OptionsetField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/OptionsetField.php
BSD-3-Clause
public function setID($id) { $this->id = $id; return $this; }
Set custom HTML ID to use for this tabset @param string $id @return $this
setID
php
silverstripe/silverstripe-framework
src/Forms/Tab.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/Tab.php
BSD-3-Clause
public function Field($properties = []) { $properties = array_merge($properties, [ 'Options' => $this->getOptions(), ]); return FormField::Field($properties); }
Returns a select tag containing all the appropriate option tags @param array $properties @return string
Field
php
silverstripe/silverstripe-framework
src/Forms/ListboxField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ListboxField.php
BSD-3-Clause
public function setSize($size) { $this->size = $size; return $this; }
Sets the size of this dropdown in rows. @param int $size The height in rows (e.g. 3) @return $this Self reference
setSize
php
silverstripe/silverstripe-framework
src/Forms/ListboxField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ListboxField.php
BSD-3-Clause
public function setDisabledItems($items) { $this->disabledItems = $items; return $this; }
Mark certain elements as disabled, regardless of the {@link setDisabled()} settings. @param array $items Collection of array keys, as defined in the $source array @return $this Self reference
setDisabledItems
php
silverstripe/silverstripe-framework
src/Forms/ListboxField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ListboxField.php
BSD-3-Clause
public function getSchemaDataDefaults() { $options = $this->getOptions(); $selected = $options->filter('Selected', true); $name = $this->getName(); $schema = array_merge( parent::getSchemaDataDefaults(), [ 'name' => $name, 'lazyLoad' => false, 'creatable' => false, 'multi' => true, 'value' => $selected->count() ? $selected->toNestedArray() : null, 'disabled' => $this->isDisabled() || $this->isReadonly(), ] ); $schema['options'] = array_values($options->toNestedArray() ?? []); return $schema; }
Provide ListboxField data to the JSON schema for the frontend component @return array
getSchemaDataDefaults
php
silverstripe/silverstripe-framework
src/Forms/ListboxField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ListboxField.php
BSD-3-Clause
protected function getOptionsArray($term) { $source = $this->getSourceList(); if (!$source) { return []; } $titleField = $this->getTitleField(); $query = $source ->filter($titleField . ':PartialMatch:nocase', $term) ->sort($titleField); // Map into a distinct list $items = []; $titleField = $this->getTitleField(); foreach ($query->map('ID', $titleField)->values() as $title) { $items[$title] = [ 'Title' => $title, 'Value' => $title, ]; } return array_values($items ?? []); }
Returns array of arrays representing tags. @param string $term @return array
getOptionsArray
php
silverstripe/silverstripe-framework
src/Forms/ListboxField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ListboxField.php
BSD-3-Clause
public function validate($validator) { $result = true; $this->value = trim($this->value ?? ''); $pattern = '^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$'; // Escape delimiter characters. $safePattern = str_replace('/', '\\/', $pattern ?? ''); if ($this->value && !preg_match('/' . $safePattern . '/i', $this->value ?? '')) { $validator->validationError( $this->name, _t('SilverStripe\\Forms\\EmailField.VALIDATION', 'Please enter an email address'), 'validation' ); $result = false; } return $this->extendValidationResult($result, $validator); }
Validates for RFC 2822 compliant email addresses. @see http://www.regular-expressions.info/email.html @see http://www.ietf.org/rfc/rfc2822.txt @param Validator $validator @return bool
validate
php
silverstripe/silverstripe-framework
src/Forms/EmailField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/EmailField.php
BSD-3-Clause
public function __construct(Form $form) { $this->form = $form; parent::__construct(); // Inherit parent controller request $parent = $this->form->getController(); if ($parent) { $this->setRequest($parent->getRequest()); } }
Build a new request handler for a given Form model @param Form $form
__construct
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
protected function addBackURLParam($link) { $backURL = $this->getBackURL(); if ($backURL) { return Controller::join_links($link, '?BackURL=' . urlencode($backURL ?? '')); } return $link; }
Helper to add ?BackURL= to any link @param string $link @return string
addBackURLParam
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
public function handleField($request) { $field = $this->form->Fields()->dataFieldByName($request->param('FieldName')); if ($field) { return $field; } else { // falling back to fieldByName, e.g. for getting tabs return $this->form->Fields()->fieldByName($request->param('FieldName')); } }
Handle a field request. Uses {@link Form->dataFieldByName()} to find a matching field, and falls back to {@link FieldList->fieldByName()} to look for tabs instead. This means that if you have a tab and a formfield with the same name, this method gives priority to the formfield. @param HTTPRequest $request @return FormField
handleField
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
public function setButtonClicked($funcName) { $this->buttonClickedFunc = $funcName; return $this; }
Sets the button that was clicked. This should only be called by the Controller. @param callable $funcName The name of the action method that will be called. @return $this
setButtonClicked
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
public function buttonClicked() { $actions = $this->getAllActions(); foreach ($actions as $action) { if ($this->buttonClickedFunc === $action->actionName()) { return $action; } } return null; }
Get instance of button which was clicked for this request @return FormAction
buttonClicked
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
protected function getAllActions() { $fields = $this->form->Fields()->dataFields(); $actions = $this->form->Actions()->dataFields(); $fieldsAndActions = array_merge($fields, $actions); $actions = array_filter($fieldsAndActions ?? [], function ($fieldOrAction) { return $fieldOrAction instanceof FormAction; }); return $actions; }
Get a list of all actions, including those in the main "fields" FieldList @return array
getAllActions
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
public function validationResult() { // Check if button is exempt, or if there is no validator $action = $this->buttonClicked(); $validator = $this->form->getValidator(); if (!$validator || $this->form->actionIsValidationExempt($action)) { return ValidationResult::create(); } // Invoke validator $result = $validator->validate(); $this->form->loadMessagesFrom($result); return $result; }
Processing that occurs before a form is executed. This includes form validation, if it fails, we throw a ValidationException This includes form validation, if it fails, we redirect back to the form with appropriate error messages. Always return true if the current form action is exempt from validation Triggered through {@link httpSubmission()}. Note that CSRF protection takes place in {@link httpSubmission()}, if it fails the form data will never reach this method. @return ValidationResult
validationResult
php
silverstripe/silverstripe-framework
src/Forms/FormRequestHandler.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormRequestHandler.php
BSD-3-Clause
protected function getFormatter() { if ($this->getHTML5()) { // Locale-independent html5 number formatter $formatter = NumberFormatter::create( i18n::config()->uninherited('default_locale'), NumberFormatter::DECIMAL ); $formatter->setAttribute(NumberFormatter::GROUPING_USED, false); $formatter->setSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, '.'); } else { // Locale-specific number formatter $formatter = NumberFormatter::create($this->getLocale(), NumberFormatter::DECIMAL); } // Set decimal precision $scale = $this->getScale(); if ($scale === 0) { $formatter->setAttribute(NumberFormatter::DECIMAL_ALWAYS_SHOWN, false); $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, 0); } else { $formatter->setAttribute(NumberFormatter::DECIMAL_ALWAYS_SHOWN, true); if ($scale === null) { // At least one digit to distinguish floating point from integer $formatter->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, 1); } else { $formatter->setAttribute(NumberFormatter::FRACTION_DIGITS, $scale); } } return $formatter; }
Get number formatter for localising this field @return NumberFormatter
getFormatter
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
protected function getNumberType() { $scale = $this->getScale(); if ($scale === 0) { return PHP_INT_SIZE > 4 ? NumberFormatter::TYPE_INT64 : NumberFormatter::TYPE_INT32; } return NumberFormatter::TYPE_DOUBLE; }
Get type argument for parse / format calls. one of TYPE_INT32, TYPE_INT64 or TYPE_DOUBLE @return int
getNumberType
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
protected function cast($value) { if (mb_strlen($value ?? '') === 0) { return null; } if ($this->getScale() === 0) { return (int)$value; } return (float)$value; }
Helper to cast non-localised strings to their native type @param string $value @return float|int
cast
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
public function getLocale() { if ($this->locale) { return $this->locale; } return i18n::get_locale(); }
Gets the current locale this field is set to. @return string
getLocale
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
public function setLocale($locale) { $this->locale = $locale; return $this; }
Override the locale for this field. @param string $locale @return $this
setLocale
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
public function getHTML5() { return $this->html5; }
Determine if we should use html5 number input @return bool
getHTML5
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
public function setHTML5($html5) { $this->html5 = $html5; return $this; }
Set whether this field should use html5 number input type. Note: If setting to true this will disable all number localisation. @param bool $html5 @return $this
setHTML5
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
public function getStep() { $scale = $this->getScale(); if ($scale === null) { return 'any'; } if ($scale === 0) { return '1'; } return '0.' . str_repeat('0', $scale - 1) . '1'; }
Step attribute for html5. E.g. '0.01' to enable two decimal places. Ignored if html5 isn't enabled. @return string
getStep
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
public function setScale($scale) { $this->scale = $scale; return $this; }
Get number of digits to show to the right of the decimal point. 0 for integer, any number for floating point, or null to flexible @param int|null $scale @return $this
setScale
php
silverstripe/silverstripe-framework
src/Forms/NumericField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/NumericField.php
BSD-3-Clause
protected function getFieldOption($value, $title) { // Check selection $selected = $this->isSelectedValue($value, $this->Value()); // Check disabled $disabled = false; if ($this->isDisabledValue($value) && $title != $this->getEmptyString()) { $disabled = 'disabled'; } return new ArrayData([ 'Title' => (string)$title, 'Value' => $value, 'Selected' => $selected, 'Disabled' => $disabled, ]); }
Build a field option for template rendering @param mixed $value Value of the option @param string $title Title of the option @return ArrayData Field option
getFieldOption
php
silverstripe/silverstripe-framework
src/Forms/DropdownField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DropdownField.php
BSD-3-Clause
public function getHasEmptyDefault() { return parent::getHasEmptyDefault() || $this->Required(); }
A required DropdownField must have a user selected attribute, so require an empty default for a required field @return bool
getHasEmptyDefault
php
silverstripe/silverstripe-framework
src/Forms/DropdownField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DropdownField.php
BSD-3-Clause
public function setIncludeHiddenField($includeHiddenField) { $this->includeHiddenField = $includeHiddenField; return $this; }
If true, a hidden field will be included in the HTML for the readonly field. This can be useful if you need to pass the data through on the form submission, as long as it's okay than an attacker could change the data before it's submitted. This is disabled by default as it can introduce security holes if the data is not allowed to be modified by the user. @param boolean $includeHiddenField @return $this
setIncludeHiddenField
php
silverstripe/silverstripe-framework
src/Forms/ReadonlyField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ReadonlyField.php
BSD-3-Clause
public function getValueCast() { // Casting class for 'none' text $value = $this->dataValue(); if (empty($value)) { return 'HTMLFragment'; } // Use default casting $casting = $this->config()->get('casting'); return $casting['Value']; }
Get custom cating helper for Value() field @return string
getValueCast
php
silverstripe/silverstripe-framework
src/Forms/ReadonlyField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ReadonlyField.php
BSD-3-Clause
public function setValue($value, $data = null) { if (!$value) { $value = 0.00; } $this->value = DBCurrency::config()->uninherited('currency_symbol') . number_format((double)preg_replace('/[^0-9.\-]/', '', $value ?? ''), 2); return $this; }
allows the value to be set. removes the first character if it is not a number (probably a currency symbol) @param mixed $value @param mixed $data @return $this
setValue
php
silverstripe/silverstripe-framework
src/Forms/CurrencyField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CurrencyField.php
BSD-3-Clause
public function dataValue() { if ($this->value) { return preg_replace('/[^0-9.\-]/', '', $this->value ?? ''); } return 0.00; }
Overwrite the datavalue before saving to the db ;-) return 0.00 if no value, or value is non-numeric
dataValue
php
silverstripe/silverstripe-framework
src/Forms/CurrencyField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CurrencyField.php
BSD-3-Clause
public function performReadonlyTransformation() { return $this->castedCopy(CurrencyField_Readonly::class); }
Create a new class for this field
performReadonlyTransformation
php
silverstripe/silverstripe-framework
src/Forms/CurrencyField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CurrencyField.php
BSD-3-Clause
public function setDisabledItems($items) { $this->disabledItems = $this->getListValues($items); return $this; }
Mark certain elements as disabled, regardless of the {@link setDisabled()} settings. These should be items that appear in the source list, not in addition to them. @param array|SS_List $items Collection of values or items @return $this
setDisabledItems
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
public function getDisabledItems() { return $this->disabledItems; }
Non-associative list of disabled item values @return array
getDisabledItems
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
protected function isDisabledValue($value) { if ($this->isDisabled()) { return true; } return in_array($value, $this->getDisabledItems() ?? []); }
Check if the given value is disabled @param string $value @return bool
isDisabledValue
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
protected function getSourceValues() { return array_keys($this->getSource() ?? []); }
Retrieve all values in the source array @return array
getSourceValues
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
public function getValidValues() { $valid = array_diff($this->getSourceValues() ?? [], $this->getDisabledItems()); // Renumber indexes from 0 return array_values($valid ?? []); }
Gets all valid values for this field. Does not include "empty" value if specified @return array
getValidValues
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
protected function getListMap($source) { // Extract source as an array if ($source instanceof SS_List) { $source = $source->map(); } if ($source instanceof Map) { $source = $source->toArray(); } if (!is_array($source) && !($source instanceof ArrayAccess)) { throw new \InvalidArgumentException('$source passed in as invalid type'); } return $source; }
Given a list of values, extract the associative map of id => title @param mixed $source @return array Associative array of ids and titles
getListMap
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
protected function getListValues($values) { // Empty values if (empty($values)) { return []; } // Direct array if (is_array($values)) { return array_values($values ?? []); } // Extract lists if ($values instanceof SS_List) { return $values->column('ID'); } return [trim($values ?? '')]; }
Given a non-array collection, extract the non-associative list of ids If passing as array, treat the array values (not the keys) as the ids @param mixed $values @return array Non-associative list of values
getListValues
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
public function isSelectedValue($dataValue, $userValue) { if ($dataValue === $userValue) { return true; } // Allow null to match empty strings if ($dataValue === '' && $userValue === null) { return true; } // Safety check against casting arrays as strings in PHP>5.4 if (is_array($dataValue) || is_array($userValue)) { return false; } // For non-falsey values do loose comparison if ($dataValue) { return $dataValue == $userValue; } // For empty values, use string comparison to perform visible value match return ((string) $dataValue) === ((string) $userValue); }
Determine if the current value of this field matches the given option value @param mixed $dataValue The value as extracted from the source of this field (or empty value if available) @param mixed $userValue The value as submitted by the user @return boolean True if the selected value matches the given option value
isSelectedValue
php
silverstripe/silverstripe-framework
src/Forms/SelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SelectField.php
BSD-3-Clause
public function performReadonlyTransformation() { $field = $this->castedCopy('SilverStripe\\Forms\\ReadonlyField'); $field->setValue('*****'); return $field; }
Creates a read-only version of the field. @return FormField
performReadonlyTransformation
php
silverstripe/silverstripe-framework
src/Forms/PasswordField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/PasswordField.php
BSD-3-Clause
public function setRecord($record) { $this->record = $record; return $this; }
Force a record to be used as "Parent" for uploaded Files (eg a Page with a has_one to File) @param DataObject $record @return $this
setRecord
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function getRecord() { if ($this->record) { return $this->record; } if (!$this->getForm()) { return null; } // Get record from form $record = $this->getForm()->getRecord(); if ($record && ($record instanceof DataObject)) { $this->record = $record; return $record; } // Get record from controller $controller = $this->getForm()->getController(); if ($controller && $controller->hasMethod('data') && ($record = $controller->data()) && ($record instanceof DataObject) ) { $this->record = $record; return $record; } return null; }
Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data() @return ?DataObject
getRecord
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function setItems(SS_List $items) { return $this->setValue(null, $items); }
Sets the items assigned to this field as an SS_List of File objects. Calling setItems will also update the value of this field, as well as updating the internal list of File items. @param SS_List $items @return $this self reference
setItems
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function getItems() { return $this->items ? $this->items : new ArrayList(); }
Retrieves the current list of files @return SS_List|File[]
getItems
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function getItemIDs() { $value = $this->Value(); return empty($value['Files']) ? [] : $value['Files']; }
Retrieves the list of selected file IDs @return array
getItemIDs
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
protected function saveTemporaryFile($tmpFile, &$error = null) { // Determine container object $error = null; $fileObject = null; if (empty($tmpFile)) { $error = _t('SilverStripe\\Forms\\FileUploadReceiver.FIELDNOTSET', 'File information not found'); return null; } if ($tmpFile['error']) { $this->getUpload()->validate($tmpFile); $error = implode(' ' . PHP_EOL, $this->getUpload()->getErrors()); return null; } // Search for relations that can hold the uploaded files, but don't fallback // to default if there is no automatic relation if ($relationClass = $this->getRelationAutosetClass(null)) { // Allow File to be subclassed if ($relationClass === File::class && isset($tmpFile['name'])) { $relationClass = File::get_class_for_file_extension( File::get_file_extension($tmpFile['name']) ); } // Create new object explicitly. Otherwise rely on Upload::load to choose the class. $fileObject = Injector::inst()->create($relationClass); if (! ($fileObject instanceof DataObject) || !($fileObject instanceof AssetContainer)) { throw new InvalidArgumentException("Invalid asset container $relationClass"); } } // Get the uploaded file into a new file object. try { $this->getUpload()->loadIntoFile($tmpFile, $fileObject, $this->getFolderName()); } catch (Exception $e) { // we shouldn't get an error here, but just in case $error = $e->getMessage(); return null; } // Check if upload field has an error if ($this->getUpload()->isError()) { $error = implode(' ' . PHP_EOL, $this->getUpload()->getErrors()); return null; } // return file return $this->getUpload()->getFile(); }
Loads the temporary file data into a File object @param array $tmpFile Temporary file data @param string $error Error message @return AssetContainer File object, or null if error
saveTemporaryFile
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function getRelationAutosetClass($default = File::class) { // Don't autodetermine relation if no relationship between parent record if (!$this->getRelationAutoSetting()) { return $default; } // Check record and name $name = $this->getName(); $record = $this->getRecord(); if (empty($name) || empty($record)) { return $default; } else { $class = $record->getRelationClass($name); return empty($class) ? $default : $class; } }
Gets the foreign class that needs to be created, or 'File' as default if there is no relationship, or it cannot be determined. @param string $default Default value to return if no value could be calculated @return string Foreign class name.
getRelationAutosetClass
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function setRelationAutoSetting($auto) { $this->relationAutoSetting = $auto; return $this; }
Set if relation can be automatically assigned to the underlying dataobject @param bool $auto @return $this
setRelationAutoSetting
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function getRelationAutoSetting() { return $this->relationAutoSetting; }
Check if relation can be automatically assigned to the underlying dataobject @return bool
getRelationAutoSetting
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
protected function extractUploadedFileData($postVars) { // Note: Format of posted file parameters in php is a feature of using // <input name='{$Name}[Uploads][]' /> for multiple file uploads $tmpFiles = []; if (!empty($postVars['tmp_name']) && is_array($postVars['tmp_name']) && !empty($postVars['tmp_name']['Uploads']) ) { for ($i = 0; $i < count($postVars['tmp_name']['Uploads'] ?? []); $i++) { // Skip if "empty" file if (empty($postVars['tmp_name']['Uploads'][$i])) { continue; } $tmpFile = []; foreach (['name', 'type', 'tmp_name', 'error', 'size'] as $field) { $tmpFile[$field] = $postVars[$field]['Uploads'][$i]; } $tmpFiles[] = $tmpFile; } } elseif (!empty($postVars['tmp_name'])) { // Fallback to allow single file uploads (method used by AssetUploadField) $tmpFiles[] = $postVars; } return $tmpFiles; }
Given an array of post variables, extract all temporary file data into an array @param array $postVars Array of posted form data @return array List of temporary file data
extractUploadedFileData
php
silverstripe/silverstripe-framework
src/Forms/FileUploadReceiver.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileUploadReceiver.php
BSD-3-Clause
public function recursiveWalk(callable $callback) { $stack = $this->toArray(); while (!empty($stack)) { $field = array_shift($stack); $callback($field); if ($field instanceof CompositeField) { $stack = array_merge($field->getChildren()->toArray(), $stack); } } }
Iterate over each field in the current list recursively @param callable $callback
recursiveWalk
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function dataFieldNames() { return array_keys($this->dataFields() ?? []); }
Return array of all field names @return array
dataFieldNames
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
protected function fieldNameError(FormField $field, $functionName) { if ($field->getForm()) { $errorSuffix = sprintf( " in your '%s' form called '%s'", get_class($field->getForm()), $field->getForm()->getName() ); } else { $errorSuffix = ''; } throw new \RuntimeException(sprintf( "%s() I noticed that a field called '%s' appears twice%s", $functionName, $field->getName(), $errorSuffix )); }
Trigger an error for duplicate field names @param FormField $field @param $functionName
fieldNameError
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function addFieldToTab($tabName, $field, $insertBefore = null) { // This is a cache that must be flushed $this->flushFieldsCache(); // Find the tab $tab = $this->findOrMakeTab($tabName); // Add the field to the end of this set if ($insertBefore) { $tab->insertBefore($insertBefore, $field); } else { $tab->push($field); } return $this; }
Add an extra field to a tab within this FieldList. This is most commonly used when overloading getCMSFields() @param string $tabName The name of the tab or tabset. Subtabs can be referred to as TabSet.Tab or TabSet.Tab.Subtab. This function will create any missing tabs. @param FormField $field The {@link FormField} object to add to the end of that tab. @param string $insertBefore The name of the field to insert before. Optional. @return $this
addFieldToTab
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function removeFieldFromTab($tabName, $fieldName) { $this->flushFieldsCache(); // Find the tab $tab = $this->findTab($tabName); if ($tab) { $tab->removeByName($fieldName); } return $this; }
Remove the given field from the given tab in the field. @param string $tabName The name of the tab @param string $fieldName The name of the field @return $this
removeFieldFromTab
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function replaceField($fieldName, $newField, $dataFieldOnly = true) { $this->flushFieldsCache(); foreach ($this as $i => $field) { if ($field->getName() == $fieldName && (!$dataFieldOnly || $field->hasData())) { $this->items[$i] = $newField; return true; } elseif ($field instanceof CompositeField) { if ($field->replaceField($fieldName, $newField)) { return true; } } } return false; }
Replace a single field with another. Ignores dataless fields such as Tabs and TabSets @param string $fieldName The name of the field to replace @param FormField $newField The field object to replace with @param boolean $dataFieldOnly If this is true, then a field will only be replaced if it's a data field. Dataless fields, such as tabs, will be not be considered for replacement. @return bool TRUE field was successfully replaced FALSE field wasn't found, nothing changed
replaceField
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function renameField($fieldName, $newFieldTitle) { $field = $this->dataFieldByName($fieldName); if (!$field) { return false; } $field->setTitle($newFieldTitle); return $field->Title() == $newFieldTitle; }
Rename the title of a particular field name in this set. @param string $fieldName Name of field to rename title of @param string $newFieldTitle New title of field @return bool
renameField
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function dataFieldByName($name) { if ($dataFields = $this->dataFields()) { foreach ($dataFields as $child) { if (trim($name ?? '') == trim($child->getName() ?? '') || $name == $child->id) { return $child; } } } return null; }
Returns a named field in a sequential set. Use this if you're using nested FormFields. @param string $name The name of the field to return @return FormField|null
dataFieldByName
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function push($item) { $this->onBeforeInsert($item); $item->setContainerFieldList($this); return parent::push($item); }
Push a single field onto the end of this FieldList instance. @param FormField $item The FormField to add
push
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function unshift($item) { $this->onBeforeInsert($item); $item->setContainerFieldList($this); return parent::unshift($item); }
Push a single field onto the beginning of this FieldList instance. @param FormField $item The FormField to add
unshift
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
protected function onBeforeInsert($item) { $this->flushFieldsCache(); if ($item->getName()) { $this->rootFieldList()->removeByName($item->getName(), true); } }
Handler method called before the FieldList is going to be manipulated. @param FormField $item
onBeforeInsert
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function rootFieldList() { if ($this->containerField) { return $this->containerField->rootFieldList(); } return $this; }
Returns the root field set that this belongs to @return FieldList|FormField
rootFieldList
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function makeReadonly() { return $this->transform(new ReadonlyTransformation()); }
Transforms this FieldList instance to readonly. @return FieldList
makeReadonly
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function fieldPosition($field) { if ($field instanceof FormField) { $field = $field->getName(); } $i = 0; foreach ($this->dataFields() as $child) { if ($child->getName() == $field) { return $i; } $i++; } return false; }
Find the numerical position of a field within the children collection. Doesn't work recursively. @param string|FormField $field @return int Position in children collection (first position starts with 0). Returns FALSE if the field can't be found.
fieldPosition
php
silverstripe/silverstripe-framework
src/Forms/FieldList.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FieldList.php
BSD-3-Clause
public function getMessage() { $message = $this->message; if ($this->getMessageCast() === ValidationResult::CAST_HTML) { $message = XssSanitiser::create()->sanitiseString($message); } return $message; }
Returns the field message, used by form validation. If the current cast is ValidationResult::CAST_HTML, the message will be sanitised. Use {@link setError()} to set this property. @return string
getMessage
php
silverstripe/silverstripe-framework
src/Forms/FormMessage.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormMessage.php
BSD-3-Clause
public function getMessageType() { return $this->messageType; }
Returns the field message type. 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
getMessageType
php
silverstripe/silverstripe-framework
src/Forms/FormMessage.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormMessage.php
BSD-3-Clause
public function getMessageCast() { return $this->messageCast; }
Casting type for this message. Will be 'text' or 'html' @return string
getMessageCast
php
silverstripe/silverstripe-framework
src/Forms/FormMessage.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormMessage.php
BSD-3-Clause
public function setMessage( $message, $messageType = ValidationResult::TYPE_ERROR, $messageCast = ValidationResult::CAST_TEXT ) { if (!in_array($messageCast, [ValidationResult::CAST_TEXT, ValidationResult::CAST_HTML])) { throw new InvalidArgumentException("Invalid message cast type"); } $this->message = $message; $this->messageType = $messageType; $this->messageCast = $messageCast; return $this; }
Sets the error message to be displayed on the form field. Allows HTML content, so remember to use Convert::raw2xml(). @param string $message Message string @param string $messageType Message type @param string $messageCast @return $this
setMessage
php
silverstripe/silverstripe-framework
src/Forms/FormMessage.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormMessage.php
BSD-3-Clause
protected function getMessageCastingHelper() { switch ($this->getMessageCast()) { case ValidationResult::CAST_TEXT: return 'Text'; case ValidationResult::CAST_HTML: return 'HTMLFragment'; default: return null; } }
Get casting helper for message cast, or null if not known @return string
getMessageCastingHelper
php
silverstripe/silverstripe-framework
src/Forms/FormMessage.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormMessage.php
BSD-3-Clause
public function __construct($name, $title = null, $value = '', $maxLength = null, $form = null) { if ($maxLength) { $this->setMaxLength($maxLength); } if ($form) { $this->setForm($form); } parent::__construct($name, $title, $value); }
Returns an input field. @param string $name @param null|string $title @param string $value @param null|int $maxLength Max characters to allow for this field. If this value is stored against a DB field with a fixed size it's recommended to set an appropriate max length matching this size. @param null|Form $form
__construct
php
silverstripe/silverstripe-framework
src/Forms/TextField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TextField.php
BSD-3-Clause
public function getValueArray() { return $this->getListValues($this->Value()); }
Extracts the value of this field, normalised as an array. Scalar values will return a single length array, even if empty @return array List of values as an array
getValueArray
php
silverstripe/silverstripe-framework
src/Forms/MultiSelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/MultiSelectField.php
BSD-3-Clause
public function setDefaultItems($items) { $this->defaultItems = $this->getListValues($items); return $this; }
Default selections, regardless of the {@link setValue()} settings. Note: Items marked as disabled through {@link setDisabledItems()} can still be selected by default through this method. @param array $items Collection of array keys, as defined in the $source array @return $this Self reference
setDefaultItems
php
silverstripe/silverstripe-framework
src/Forms/MultiSelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/MultiSelectField.php
BSD-3-Clause
public function saveInto(DataObjectInterface $record) { $fieldName = $this->getName(); if (empty($fieldName) || empty($record)) { return; } $relation = $record->hasMethod($fieldName) ? $record->$fieldName() : null; // Detect DB relation or field $items = $this->getValueArray(); if ($relation instanceof Relation) { // Save ids into relation $relation->setByIDList($items); } elseif ($record->hasField($fieldName)) { // Save dataValue into field... a CSV for DBMultiEnum if ($record->obj($fieldName) instanceof DBMultiEnum) { $record->$fieldName = $this->csvEncode($items); // ... JSON-encoded string for other fields } else { $record->$fieldName = $this->stringEncode($items); } } }
Save the current value of this MultiSelectField into a DataObject. If the field it is saving to is a has_many or many_many relationship, it is saved by setByIDList(), otherwise it creates a comma separated list for a standard DB text/varchar field. @param DataObject|DataObjectInterface $record The record to save into
saveInto
php
silverstripe/silverstripe-framework
src/Forms/MultiSelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/MultiSelectField.php
BSD-3-Clause
public function stringEncode($value) { return $value ? json_encode(array_values($value)) : null; }
Encode a list of values into a string, or null if empty (to simplify empty checks) @param array $value @return string|null
stringEncode
php
silverstripe/silverstripe-framework
src/Forms/MultiSelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/MultiSelectField.php
BSD-3-Clause
protected function stringDecode($value) { // Handle empty case if (empty($value)) { return []; } // If json deserialisation fails, then fallover to legacy format $result = json_decode($value ?? '', true); if ($result !== false) { return $result; } throw new \InvalidArgumentException("Invalid string encoded value for multi select field"); }
Extract a string value into an array of values @param string $value @return array
stringDecode
php
silverstripe/silverstripe-framework
src/Forms/MultiSelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/MultiSelectField.php
BSD-3-Clause
protected function csvEncode($value) { if (!$value) { return null; } return implode( ',', array_map( function ($x) { return str_replace(',', '', $x ?? ''); }, array_values($value ?? []) ) ); }
Encode a list of values into a string as a comma separated list. Commas will be stripped from the items passed in @param array $value @return string|null
csvEncode
php
silverstripe/silverstripe-framework
src/Forms/MultiSelectField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/MultiSelectField.php
BSD-3-Clause