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 setDateFormat($format)
{
$this->dateFormat = $format;
return $this;
} | Set date format in CLDR standard format.
Only applicable with {@link setHTML5(false)}.
@see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table
@param string $format
@return $this | setDateFormat | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
protected function getInternalFormatter()
{
$formatter = IntlDateFormatter::create(
DBDate::ISO_LOCALE,
IntlDateFormatter::MEDIUM,
IntlDateFormatter::NONE
);
$formatter->setLenient(false);
// CLDR ISO 8601 date.
$formatter->setPattern(DBDate::ISO_DATE);
return $formatter;
} | Get a date formatter for the ISO 8601 format
@return IntlDateFormatter | getInternalFormatter | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
public function setValue($value, $data = null)
{
// Save raw value for later validation
$this->rawValue = $value;
// Null case
if (!$value) {
$this->value = null;
return $this;
}
// Re-run through formatter to tidy up (e.g. remove time component)
$this->value = $this->tidyInternal($value);
return $this;
} | Assign value based on {@link $datetimeFormat}, which might be localised.
When $html5=true, assign value from ISO 8601 string.
@param mixed $value
@param mixed $data
@return $this | setValue | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
public function getLocale()
{
// Use iso locale for html5
if ($this->getHTML5()) {
return DBDate::ISO_LOCALE;
}
return $this->locale ?: i18n::get_locale();
} | Get locale to use for this field
@return string | getLocale | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
protected function frontendToInternal($date)
{
if (!$date) {
return null;
}
$fromFormatter = $this->getFrontendFormatter();
$toFormatter = $this->getInternalFormatter();
$timestamp = $fromFormatter->parse($date);
if ($timestamp === false) {
return null;
}
return $toFormatter->format($timestamp) ?: null;
} | Convert frontend date to the internal representation (ISO 8601).
The frontend date is also in ISO 8601 when $html5=true.
@param string $date
@return string The formatted date, or null if not a valid date | frontendToInternal | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
protected function internalToFrontend($date)
{
$date = $this->tidyInternal($date);
if (!$date) {
return null;
}
$fromFormatter = $this->getInternalFormatter();
$toFormatter = $this->getFrontendFormatter();
$timestamp = $fromFormatter->parse($date);
if ($timestamp === false) {
return null;
}
return $toFormatter->format($timestamp) ?: null;
} | Convert the internal date representation (ISO 8601) to a format used by the frontend,
as defined by {@link $dateFormat}. With $html5=true, the frontend date will also be
in ISO 8601.
@param string $date
@return string The formatted date, or null if not a valid date | internalToFrontend | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
protected function tidyInternal($date)
{
if (!$date) {
return null;
}
// Re-run through formatter to tidy up (e.g. remove time component)
$formatter = $this->getInternalFormatter();
$timestamp = $formatter->parse($date);
if ($timestamp === false) {
// Fallback to strtotime
$timestamp = strtotime($date ?? '', DBDatetime::now()->getTimestamp());
if ($timestamp === false) {
return null;
}
}
return $formatter->format($timestamp);
} | Tidy up the internal date representation (ISO 8601),
and fall back to strtotime() if there's parsing errors.
@param string $date Date in ISO 8601 or approximate form
@return string ISO 8601 date, or null if not valid | tidyInternal | php | silverstripe/silverstripe-framework | src/Forms/DateField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DateField.php | BSD-3-Clause |
public function setAllowedExtensions($rules)
{
$this->getValidator()->setAllowedExtensions($rules);
return $this;
} | Limit allowed file extensions. Empty by default, allowing all extensions.
To allow files without an extension, use an empty string.
See {@link File::$allowed_extensions} to get a good standard set of
extensions that are typically not harmful in a webserver context.
See {@link setAllowedMaxFileSize()} to limit file size by extension.
@param array $rules List of extensions
@return $this | setAllowedExtensions | php | silverstripe/silverstripe-framework | src/Forms/UploadReceiver.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/UploadReceiver.php | BSD-3-Clause |
public function setAllowedFileCategories($category)
{
$extensions = File::get_category_extensions(func_get_args());
return $this->setAllowedExtensions($extensions);
} | Limit allowed file extensions by specifying categories of file types.
These may be 'image', 'image/supported', 'audio', 'video', 'archive', 'flash', or 'document'
See {@link File::$allowed_extensions} for details of allowed extensions
for each of these categories
@param string $category Category name
@param string ...$categories Additional category names
@return $this | setAllowedFileCategories | php | silverstripe/silverstripe-framework | src/Forms/UploadReceiver.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/UploadReceiver.php | BSD-3-Clause |
public function getAllowedExtensions()
{
return $this->getValidator()->getAllowedExtensions();
} | Returns list of extensions allowed by this field, or an empty array
if there is no restriction
@return array | getAllowedExtensions | php | silverstripe/silverstripe-framework | src/Forms/UploadReceiver.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/UploadReceiver.php | BSD-3-Clause |
public function getValidator()
{
return $this->getUpload()->getValidator();
} | Get custom validator for this field
@return Upload_Validator | getValidator | php | silverstripe/silverstripe-framework | src/Forms/UploadReceiver.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/UploadReceiver.php | BSD-3-Clause |
public function setValidator(Upload_Validator $validator)
{
$this->getUpload()->setValidator($validator);
return $this;
} | Set custom validator for this field
@param Upload_Validator $validator
@return $this | setValidator | php | silverstripe/silverstripe-framework | src/Forms/UploadReceiver.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/UploadReceiver.php | BSD-3-Clause |
public function setSubmittedValue($value, $data = null)
{
// Save raw value for later validation
$this->rawValue = $value;
// Null case
if (!$value) {
$this->value = null;
return $this;
}
// Parse from submitted value
$this->value = $this->frontendToInternal($value);
return $this;
} | Assign value posted from form submission, based on {@link $datetimeFormat}.
When $html5=true, this needs to be normalised ISO format (with "T" separator).
@param mixed $value
@param mixed $data
@return $this | setSubmittedValue | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
public function frontendToInternal($datetime)
{
if (!$datetime) {
return null;
}
$fromFormatter = $this->getFrontendFormatter();
$toFormatter = $this->getInternalFormatter();
// Try to parse time with seconds
$timestamp = $fromFormatter->parse($datetime);
// Try to parse time without seconds, since that's a valid HTML5 submission format
// See https://html.spec.whatwg.org/multipage/infrastructure.html#times
if ($timestamp === false && $this->getHTML5()) {
$fromFormatter->setPattern(str_replace(':ss', '', $fromFormatter->getPattern() ?? ''));
$timestamp = $fromFormatter->parse($datetime);
}
if ($timestamp === false) {
return null;
}
return $toFormatter->format($timestamp) ?: null;
} | Convert frontend date to the internal representation (ISO 8601).
The frontend date is also in ISO 8601 when $html5=true.
Assumes the value is in the defined {@link $timezone} (if one is set),
and adjusts for server timezone.
@param string $datetime
@return string The formatted date, or null if not a valid date | frontendToInternal | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
protected function getInternalFormatter($timezone = null)
{
if (!$timezone) {
$timezone = date_default_timezone_get(); // Default to server timezone
}
$formatter = IntlDateFormatter::create(
DBDate::ISO_LOCALE,
IntlDateFormatter::MEDIUM,
IntlDateFormatter::MEDIUM,
$timezone
);
$formatter->setLenient(false);
// Note we omit timezone from this format, and we always assume server TZ
$formatter->setPattern(DBDatetime::ISO_DATETIME);
return $formatter;
} | Get a date formatter for the ISO 8601 format
@param string $timezone Optional timezone identifier (defaults to server timezone)
@return IntlDateFormatter | getInternalFormatter | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
public function setValue($value, $data = null)
{
// Save raw value for later validation
$this->rawValue = $value;
// Empty value
if (empty($value)) {
$this->value = null;
return $this;
}
// Validate iso 8601 date
// If invalid, assign for later validation failure
$internalFormatter = $this->getInternalFormatter();
$timestamp = $internalFormatter->parse($value);
// Retry with "T" separator
if (!$timestamp) {
$fallbackFormatter = $this->getInternalFormatter();
$fallbackFormatter->setPattern(DBDatetime::ISO_DATETIME_NORMALISED);
$timestamp = $fallbackFormatter->parse($value);
}
if ($timestamp === false) {
return $this;
}
// Cleanup date
$value = $internalFormatter->format($timestamp);
// Save value
$this->value = $value;
return $this;
} | Assign value based on {@link $datetimeFormat}, which might be localised.
The value needs to be in the server timezone.
When $html5=true, assign value from ISO 8601 normalised string (with a "T" separator).
Falls back to an ISO 8601 string (with a whitespace separator).
@param mixed $value
@param mixed $data
@return $this | setValue | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
public function Value()
{
return $this->internalToFrontend($this->value);
} | Returns the frontend representation of the field value,
according to the defined {@link dateFormat}.
With $html5=true, this will be in ISO 8601 format.
@return string | Value | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
public function internalToFrontend($datetime)
{
$datetime = $this->tidyInternal($datetime);
if (!$datetime) {
return null;
}
$fromFormatter = $this->getInternalFormatter();
$toFormatter = $this->getFrontendFormatter();
$timestamp = $fromFormatter->parse($datetime);
if ($timestamp === false) {
return null;
}
return $toFormatter->format($timestamp) ?: null;
} | Convert the internal date representation (ISO 8601) to a format used by the frontend,
as defined by {@link $dateFormat}. With $html5=true, the frontend date will also be
in ISO 8601.
@param string $datetime
@return string The formatted date and time, or null if not a valid date and time | internalToFrontend | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
public function tidyInternal($datetime)
{
if (!$datetime) {
return null;
}
// Re-run through formatter to tidy up (e.g. remove time component)
$formatter = $this->getInternalFormatter();
$timestamp = $formatter->parse($datetime);
if ($timestamp === false) {
// Fallback to strtotime
$timestamp = strtotime($datetime ?? '', DBDatetime::now()->getTimestamp());
if ($timestamp === false) {
return null;
}
}
return $formatter->format($timestamp);
} | Tidy up the internal date representation (ISO 8601),
and fall back to strtotime() if there's parsing errors.
@param string $datetime Date in ISO 8601 or approximate form
@return string ISO 8601 date, or null if not valid | tidyInternal | php | silverstripe/silverstripe-framework | src/Forms/DatetimeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/DatetimeField.php | BSD-3-Clause |
public function setFullAction($fullAction)
{
$this->action = $fullAction;
return $this;
} | Set the full action name, including action_
This provides an opportunity to replace it with something else
@param string $fullAction
@return $this | setFullAction | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function setButtonContent($content)
{
$this->buttonContent = (string) $content;
return $this;
} | Add content inside a button field. This should be pre-escaped raw HTML and should be used sparingly.
@param string $content
@return $this | setButtonContent | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function getButtonContent()
{
return $this->buttonContent;
} | Gets the content inside the button field. This is raw HTML, and should be used sparingly.
@return string | getButtonContent | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function setUseButtonTag($bool)
{
$this->useButtonTag = $bool;
return $this;
} | Enable or disable the rendering of this action as a <button />
@param boolean $bool
@return $this | setUseButtonTag | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function getUseButtonTag()
{
return $this->useButtonTag;
} | Determine if this action is rendered as a <button />
@return boolean | getUseButtonTag | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function setValidationExempt($exempt = true)
{
$this->validationExempt = $exempt;
return $this;
} | Set whether this action can be performed without validating the data
@param bool $exempt
@return $this | setValidationExempt | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function getValidationExempt()
{
return $this->validationExempt;
} | Get whether this action can be performed without validating the data
@return bool | getValidationExempt | php | silverstripe/silverstripe-framework | src/Forms/FormAction.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormAction.php | BSD-3-Clause |
public function __construct(array $validators = [])
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\\Forms\\Validation\\CompositeValidator',
Deprecation::SCOPE_CLASS
);
$this->validators = array_values($validators ?? []);
parent::__construct();
} | CompositeValidator constructor.
@param array<Validator> $validators | __construct | php | silverstripe/silverstripe-framework | src/Forms/CompositeValidator.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeValidator.php | BSD-3-Clause |
public function fieldIsRequired($fieldName)
{
foreach ($this->getValidators() as $validator) {
if ($validator->fieldIsRequired($fieldName)) {
return true;
}
}
return false;
} | Returns whether the field in question is required. This will usually display '*' next to the
field.
@param string $fieldName
@return bool | fieldIsRequired | php | silverstripe/silverstripe-framework | src/Forms/CompositeValidator.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeValidator.php | BSD-3-Clause |
public function FieldList()
{
return $this->children;
} | Returns all the sub-fields, suitable for <% loop FieldList %>
@return FieldList | FieldList | php | silverstripe/silverstripe-framework | src/Forms/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
public function collateDataFields(&$list, $saveableOnly = false)
{
foreach ($this->children as $field) {
if (! $field instanceof FormField) {
continue;
}
if ($field instanceof CompositeField) {
$field->collateDataFields($list, $saveableOnly);
}
if ($saveableOnly) {
$isIncluded = ($field->hasData() && !$field->isReadonly() && !$field->isDisabled());
} else {
$isIncluded = ($field->hasData());
}
if ($isIncluded) {
$name = $field->getName();
if ($name) {
$formName = (isset($this->form)) ? $this->form->FormName() : '(unknown form)';
if (isset($list[$name])) {
$fieldClass = get_class($field);
$otherFieldClass = get_class($list[$name]);
throw new \RuntimeException(
"collateDataFields() I noticed that a field called '$name' appears twice in"
. " your form: '{$formName}'. One is a '{$fieldClass}' and the other is a"
. " '{$otherFieldClass}'"
);
}
$list[$name] = $field;
}
}
}
} | Add all of the non-composite fields contained within this field to the
list.
Sequentialisation is used when connecting the form to its data source
@param array $list
@param bool $saveableOnly | collateDataFields | php | silverstripe/silverstripe-framework | src/Forms/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
public function push(FormField $field)
{
$this->children->push($field);
} | Add a new child field to the end of the set.
@param FormField $field | push | php | silverstripe/silverstripe-framework | src/Forms/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
public function unshift(FormField $field)
{
$this->children->unshift($field);
} | Add a new child field to the beginning of the set.
@param FormField $field | unshift | php | silverstripe/silverstripe-framework | src/Forms/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
public function removeByName($fieldName, $dataFieldOnly = false)
{
$this->children->removeByName($fieldName, $dataFieldOnly);
} | Remove a field from this CompositeField by Name.
The field could also be inside a CompositeField.
@param string $fieldName The name of the field
@param boolean $dataFieldOnly If this is true, then a field will only
be removed if it's a data field. Dataless fields, such as tabs, will
be left as-is. | removeByName | php | silverstripe/silverstripe-framework | src/Forms/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
public function replaceField($fieldName, $newField, $dataFieldOnly = true)
{
return $this->children->replaceField($fieldName, $newField, $dataFieldOnly);
} | @param $fieldName
@param $newField
@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
not be considered for replacement.
@return bool | replaceField | php | silverstripe/silverstripe-framework | src/Forms/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
public function fieldPosition($field)
{
if (is_string($field)) {
$field = $this->fieldByName($field);
}
if (!$field) {
return false;
}
$i = 0;
foreach ($this->children as $child) {
if ($child->getName() == $field->getName()) {
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/CompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/CompositeField.php | BSD-3-Clause |
protected function getAcceptFileTypes()
{
$extensions = $this->getValidator()->getAllowedExtensions();
if (!$extensions) {
return [];
}
$accept = [];
$mimeTypes = HTTP::config()->uninherited('MimeTypes');
foreach ($extensions as $extension) {
$accept[] = ".{$extension}";
// Check for corresponding mime type
if (isset($mimeTypes[$extension])) {
$accept[] = $mimeTypes[$extension];
}
}
return array_unique($accept ?? []);
} | Returns a list of file extensions (and corresponding mime types) that will be accepted
@return array | getAcceptFileTypes | php | silverstripe/silverstripe-framework | src/Forms/FileField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FileField.php | BSD-3-Clause |
public function validate($validator)
{
return $this->extendValidationResult(true, $validator);
} | Ignore validation as the field is readonly
@param Validator $validator
@return bool | validate | php | silverstripe/silverstripe-framework | src/Forms/SingleLookupField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SingleLookupField.php | BSD-3-Clause |
public function saveInto(DataObjectInterface $record)
{
} | Stubbed so invalid data doesn't save into the DB
@param DataObjectInterface $record DataObject to save data into | saveInto | php | silverstripe/silverstripe-framework | src/Forms/SingleLookupField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SingleLookupField.php | BSD-3-Clause |
public function Field($properties = [])
{
$label = $this->valueToLabel();
if (!is_null($label)) {
$attrValue = Convert::raw2xml($label);
$inputValue = $this->value;
} else {
$attrValue = '<i>(' . _t('SilverStripe\\Forms\\FormField.NONE', 'none') . ')</i>';
$inputValue = '';
}
$properties = array_merge($properties, [
'AttrValue' => DBField::create_field('HTMLFragment', $attrValue),
'InputValue' => $inputValue
]);
return parent::Field($properties);
} | Returns a readonly span containing the correct value.
@param array $properties
@return string | Field | php | silverstripe/silverstripe-framework | src/Forms/SingleLookupField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/SingleLookupField.php | BSD-3-Clause |
public function __construct(
$name,
$title = null,
$sourceObject = null,
$keyField = 'ID',
$labelField = 'TreeTitle',
$showSearch = true
) {
if (!is_a($sourceObject, DataObject::class, true)) {
throw new InvalidArgumentException("SourceObject must be a DataObject subclass");
}
if (!DataObject::has_extension($sourceObject, Hierarchy::class)) {
throw new InvalidArgumentException("SourceObject must have Hierarchy extension");
}
$this->setSourceObject($sourceObject);
$this->setKeyField($keyField);
$this->setLabelField($labelField);
$this->setShowSearch($showSearch);
// Extra settings for Folders
if (strcasecmp($sourceObject ?? '', Folder::class) === 0) {
$this->setChildrenMethod('ChildFolders');
$this->setNumChildrenMethod('numChildFolders');
}
$this->addExtraClass('single');
// Set a default value of 0 instead of null
// Because TreedropdownField requires SourceObject to have the Hierarchy extension, make the default
// value the same as the default value for a RelationID, which is 0.
$value = 0;
parent::__construct($name, $title, $value);
} | CAVEAT: for search to work properly $labelField must be a database field,
or you need to setSearchFunction.
@param string $name the field name
@param string $title the field label
@param string $sourceObject A DataObject class name with the {@link Hierarchy} extension.
@param string $keyField to field on the source class to save as the
field value (default ID).
@param string $labelField the field name to show as the human-readable
value on the tree (default Title).
@param bool $showSearch enable the ability to search the tree by
entering the text in the input field. | __construct | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getTreeBaseID()
{
return $this->baseID;
} | Set the ID of the root node of the tree. This defaults to 0 - i.e.
displays the whole tree.
@return int | getTreeBaseID | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setTreeBaseID($ID)
{
$this->baseID = (int) $ID;
return $this;
} | Set the ID of the root node of the tree. This defaults to 0 - i.e.
displays the whole tree.
@param int $ID
@return $this | setTreeBaseID | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getFilterFunction()
{
return $this->filterCallback;
} | Get a callback used to filter the values of the tree before
displaying to the user.
@return callable | getFilterFunction | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setFilterFunction($callback)
{
if (!is_callable($callback, true)) {
throw new InvalidArgumentException('TreeDropdownField->setFilterCallback(): not passed a valid callback');
}
$this->filterCallback = $callback;
return $this;
} | Set a callback used to filter the values of the tree before
displaying to the user.
@param callable $callback
@return $this | setFilterFunction | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getDisableFunction()
{
return $this->disableCallback;
} | Get the callback used to disable checkboxes for some items in the tree
@return callable | getDisableFunction | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setDisableFunction($callback)
{
if (!is_callable($callback, true)) {
throw new InvalidArgumentException('TreeDropdownField->setDisableFunction(): not passed a valid callback');
}
$this->disableCallback = $callback;
return $this;
} | Set a callback used to disable checkboxes for some items in the tree
@param callable $callback
@return $this | setDisableFunction | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getSearchFunction()
{
return $this->searchCallback;
} | Set a callback used to search the hierarchy globally, even before
applying the filter.
@return callable | getSearchFunction | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setSearchFunction($callback)
{
if (!is_callable($callback, true)) {
throw new InvalidArgumentException('TreeDropdownField->setSearchFunction(): not passed a valid callback');
}
$this->searchCallback = $callback;
return $this;
} | Set a callback used to search the hierarchy globally, even before
applying the filter.
@param callable $callback
@return $this | setSearchFunction | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getChildrenMethod()
{
return $this->childrenMethod;
} | Get method to invoke on each node to get the child collection
@return string | getChildrenMethod | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setChildrenMethod($method)
{
$this->childrenMethod = $method;
return $this;
} | @param string $method The parameter to ChildrenMethod to use when calling Hierarchy->getChildrenAsUL in
{@link Hierarchy}. The method specified determines the structure of the returned list. Use "ChildFolders"
in place of the default to get a drop-down listing with only folders, i.e. not including the child elements in
the currently selected folder. setNumChildrenMethod() should be used as well for proper functioning.
See {@link Hierarchy} for a complete list of possible methods.
@return $this | setChildrenMethod | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getNumChildrenMethod()
{
return $this->numChildrenMethod;
} | Get method to invoke on nodes to count children
@return string | getNumChildrenMethod | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function filterMarking($node)
{
$callback = $this->getFilterFunction();
if ($callback && !call_user_func($callback, $node)) {
return false;
}
if ($this->search) {
return isset($this->searchIds[$node->ID]) && $this->searchIds[$node->ID] ? true : false;
}
return true;
} | Marking public function for the tree, which combines different filters sensibly.
If a filter function has been set, that will be called. And if search text is set,
filter on that too. Return true if all applicable conditions are true, false otherwise.
@param DataObject $node
@return bool | filterMarking | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function nodeIsDisabled($node)
{
$callback = $this->getDisableFunction();
return $callback && call_user_func($callback, $node);
} | Marking a specific node in the tree as disabled
@param $node
@return boolean | nodeIsDisabled | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getAttributes()
{
$attributes = [
'class' => $this->extraClass(),
'id' => $this->ID(),
'data-schema' => json_encode($this->getSchemaData()),
'data-state' => json_encode($this->getSchemaState()),
];
$attributes = array_merge($attributes, $this->attributes);
$this->extend('updateAttributes', $attributes);
return $attributes;
} | Attributes to be given for this field type
@return array | getAttributes | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setLabelField($field)
{
$this->labelField = $field;
return $this;
} | HTML-encoded label for this node, including css classes and other markup.
@param string $field
@return $this | setLabelField | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getLabelField()
{
return $this->labelField;
} | HTML-encoded label for this node, including css classes and other markup.
@return string | getLabelField | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function getTitleField()
{
return $this->titleField;
} | Field to use for plain text item titles.
@return string | getTitleField | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public function setTitleField($field)
{
$this->titleField = $field;
return $this;
} | Set field to use for item title
@param string $field
@return $this | setTitleField | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
protected function populateIDs()
{
// get all the leaves to be displayed
$res = $this->getSearchResults();
if (!$res) {
return;
}
// iteratively fetch the parents in bulk, until all the leaves can be accessed using the tree control
foreach ($res as $row) {
if ($row->ParentID) {
$parents[$row->ParentID] = true;
}
$this->searchIds[$row->ID] = true;
}
$this->realSearchIds = $res->column();
$sourceObject = $this->getSourceObject();
while (!empty($parents)) {
$items = DataObject::get($sourceObject)
->filter("ID", array_keys($parents ?? []));
$parents = [];
foreach ($items as $item) {
if ($item->ParentID) {
$parents[$item->ParentID] = true;
}
$this->searchIds[$item->ID] = true;
$this->searchExpanded[$item->ID] = true;
}
}
} | Populate $this->searchIds with the IDs of the pages matching the searched parameter and their parents.
Reverse-constructs the tree starting from the leaves. Initially taken from CMSSiteTreeFilter, but modified
with pluggable search function. | populateIDs | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
protected function getSearchResults()
{
$callback = $this->getSearchFunction();
if ($callback) {
return call_user_func($callback, $this->getSourceObject(), $this->getLabelField(), $this->search);
}
$sourceObject = $this->getSourceObject();
$filters = [];
$sourceObjectInstance = DataObject::singleton($sourceObject);
$candidates = array_unique([
$this->getLabelField(),
$this->getTitleField(),
'Title',
'Name'
]);
$searchFilter = $this->config()->get('search_filter') ?? 'PartialMatch';
foreach ($candidates as $candidate) {
if ($sourceObjectInstance->hasDatabaseField($candidate)) {
$filters["{$candidate}:{$searchFilter}"] = $this->search;
}
}
if (empty($filters)) {
throw new InvalidArgumentException(sprintf(
'Cannot query by %s.%s, not a valid database column',
$sourceObject,
$this->getTitleField()
));
}
return DataObject::get($this->getSourceObject())->filterAny($filters);
} | Get the DataObjects that matches the searched parameter.
@return DataList | getSearchResults | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
protected function objectForKey($key)
{
if (!is_string($key) && !is_int($key)) {
return null;
}
return DataObject::get($this->getSourceObject())
->filter($this->getKeyField(), $key)
->first();
} | Get the object where the $keyField is equal to a certain value
@param string|int $key
@return DataObject|null | objectForKey | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
protected function getCacheKey()
{
$target = $this->getSourceObject();
if (!isset(TreeDropdownField::$cacheKeyCache[$target])) {
TreeDropdownField::$cacheKeyCache[$target] = DataList::create($target)->max('LastEdited');
}
return TreeDropdownField::$cacheKeyCache[$target];
} | Ensure cache is keyed by last modified datetime of the underlying list.
Caches the key for the respective underlying list types, since it doesn't need to query again.
@return DBDatetime | getCacheKey | php | silverstripe/silverstripe-framework | src/Forms/TreeDropdownField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TreeDropdownField.php | BSD-3-Clause |
public static function addManyManyRelationshipFields(
FieldList &$fields,
$relationship,
$overrideFieldClass,
$tabbed,
DataObject $dataObject
) {
$includeInOwnTab = true;
$fieldLabel = $dataObject->fieldLabel($relationship);
if ($overrideFieldClass) {
/** @var GridField */
$manyManyField = Injector::inst()->create(
$overrideFieldClass,
$relationship,
$fieldLabel,
$dataObject->$relationship(),
GridFieldConfig_RelationEditor::create()
);
} else {
$manyManyComponent = DataObject::getSchema()->manyManyComponent(get_class($dataObject), $relationship);
/** @var DataObject */
$manyManySingleton = singleton($manyManyComponent['childClass']);
$manyManyField = $manyManySingleton->scaffoldFormFieldForManyMany($relationship, $fieldLabel, $dataObject, $includeInOwnTab);
}
if ($tabbed) {
if ($includeInOwnTab) {
$fields->findOrMakeTab(
"Root.$relationship",
$fieldLabel
);
$fields->addFieldToTab("Root.$relationship", $manyManyField);
} else {
$fields->addFieldToTab('Root.Main', $manyManyField);
}
} else {
$fields->push($manyManyField);
}
} | Adds the default many-many relation fields for the relationship provided.
@param FieldList $fields Reference to the @FieldList to add fields to.
@param string $relationship The relationship identifier.
@param string|null $overrideFieldClass Specify the field class to use here or leave as null to use default.
@param bool $tabbed Whether this relationship has it's own tab or not.
@param DataObject $dataObject The @DataObject that has the relation. | addManyManyRelationshipFields | php | silverstripe/silverstripe-framework | src/Forms/FormScaffolder.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/FormScaffolder.php | BSD-3-Clause |
public function Tabs()
{
return $this->children;
} | Return a set of all this classes tabs
@return FieldList | Tabs | php | silverstripe/silverstripe-framework | src/Forms/TabSet.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TabSet.php | BSD-3-Clause |
public function insertBefore($insertBefore, $field, $appendIfMissing = true)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
return parent::insertBefore($insertBefore, $field, $appendIfMissing);
} | Inserts a field before a particular field in a FieldList.
@param string $insertBefore Name of the field to insert before
@param FormField $field The form field to insert
@param bool $appendIfMissing
@return FormField|null | insertBefore | php | silverstripe/silverstripe-framework | src/Forms/TabSet.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TabSet.php | BSD-3-Clause |
public function insertAfter($insertAfter, $field, $appendIfMissing = true)
{
if ($field instanceof Tab || $field instanceof TabSet) {
$field->setTabSet($this);
}
return parent::insertAfter($insertAfter, $field, $appendIfMissing);
} | Inserts a field after a particular field in a FieldList.
@param string $insertAfter Name of the field to insert after
@param FormField $field The form field to insert
@param bool $appendIfMissing
@return FormField|null | insertAfter | php | silverstripe/silverstripe-framework | src/Forms/TabSet.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/TabSet.php | BSD-3-Clause |
public function setStartClosed($startClosed)
{
$this->startClosed = (bool) $startClosed;
return $this;
} | Controls whether the field is open or closed by default. By default the field is closed.
@param bool $startClosed
@return $this | setStartClosed | php | silverstripe/silverstripe-framework | src/Forms/ToggleCompositeField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ToggleCompositeField.php | BSD-3-Clause |
public function setCanBeEmpty($value)
{
$this->canBeEmpty = (bool)$value;
$this->updateRightTitle();
return $this;
} | Can be empty is a flag that turns on / off empty field checking.
For example, set this to false (the default) when creating a user account,
and true when displaying on an edit form.
@param boolean $value
@return ConfirmedPasswordField | setCanBeEmpty | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function setChildrenTitles($titles)
{
$expectedChildren = $this->getRequireExistingPassword() ? 3 : 2;
if (is_array($titles) && count($titles ?? []) === $expectedChildren) {
foreach ($this->getChildren() as $field) {
if (isset($titles[0])) {
$field->setTitle($titles[0]);
array_shift($titles);
}
}
}
return $this;
} | Set child field titles. Titles in order should be:
- "Current Password" (if getRequireExistingPassword() is set)
- "Password"
- "Confirm Password"
@param array $titles List of child titles
@return $this | setChildrenTitles | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function setValue($value, $data = null)
{
// If $data is a DataObject, don't use the value, since it's a hashed value
if ($data && $data instanceof DataObject) {
$value = '';
}
//store this for later
$oldValue = $this->value;
$oldConfirmValue = $this->confirmValue;
if (is_array($value)) {
$this->value = $value['_Password'];
$this->confirmValue = $value['_ConfirmPassword'];
$this->currentPasswordValue = ($this->getRequireExistingPassword() && isset($value['_CurrentPassword']))
? $value['_CurrentPassword']
: null;
if ($this->showOnClick && isset($value['_PasswordFieldVisible'])) {
$this->getChildren()->fieldByName($this->getName() . '[_PasswordFieldVisible]')
->setValue($value['_PasswordFieldVisible']);
}
} else {
if ($value || (!$value && $this->canBeEmpty)) {
$this->value = $value;
$this->confirmValue = $value;
}
}
//looking up field by name is expensive, so lets check it needs to change
if ($oldValue != $this->value) {
$this->getChildren()->fieldByName($this->getName() . '[_Password]')
->setValue($this->value);
}
if ($oldConfirmValue != $this->confirmValue) {
$this->getChildren()->fieldByName($this->getName() . '[_ConfirmPassword]')
->setValue($this->confirmValue);
}
return $this;
} | Value is sometimes an array, and sometimes a single value, so we need
to handle both cases.
@param mixed $value
@param mixed $data
@return $this | setValue | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function setName($name)
{
$this->getPasswordField()->setName($name . '[_Password]');
$this->getConfirmPasswordField()->setName($name . '[_ConfirmPassword]');
if ($this->hiddenField) {
$this->hiddenField->setName($name . '[_PasswordFieldVisible]');
}
parent::setName($name);
return $this;
} | Update the names of the child fields when updating name of field.
@param string $name new name to give to the field.
@return $this | setName | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function isSaveable()
{
return !$this->showOnClick
|| ($this->showOnClick && $this->hiddenField && $this->hiddenField->Value());
} | Determines if the field was actually shown on the client side - if not,
we don't validate or save it.
@return boolean | isSaveable | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function saveInto(DataObjectInterface $record)
{
if (!$this->isSaveable()) {
return;
}
// Create a random password if password is blank and the flag is set
if (!$this->value
&& $this->canBeEmpty
&& $this->randomPasswordCallback
) {
if (!is_callable($this->randomPasswordCallback)) {
throw new LogicException('randomPasswordCallback must be callable');
}
$this->value = call_user_func_array($this->randomPasswordCallback, [$this->maxLength ?: 0]);
}
if ($this->value || $this->canBeEmtpy) {
parent::saveInto($record);
}
} | Only save if field was shown on the client, and is not empty or random password generation is enabled | saveInto | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function performReadonlyTransformation()
{
$field = $this->castedCopy(ReadonlyField::class)
->setTitle($this->title ? $this->title : _t('SilverStripe\\Security\\Member.PASSWORD', 'Password'))
->setValue('*****');
return $field;
} | Makes a read only field with some stars in it to replace the password
@return ReadonlyField | performReadonlyTransformation | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function getRequireExistingPassword()
{
return $this->requireExistingPassword;
} | Check if existing password is required
@return bool | getRequireExistingPassword | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function setRequireExistingPassword($show)
{
// Don't modify if already added / removed
if ((bool)$show === $this->requireExistingPassword) {
return $this;
}
$this->requireExistingPassword = $show;
$name = $this->getName();
$currentName = "{$name}[_CurrentPassword]";
if ($show) {
$confirmField = PasswordField::create($currentName, _t('SilverStripe\\Security\\Member.CURRENT_PASSWORD', 'Current Password'));
$this->getChildren()->unshift($confirmField);
} else {
$this->getChildren()->removeByName($currentName, true);
}
return $this;
} | Set if the existing password should be required
@param bool $show Flag to show or hide this field
@return $this | setRequireExistingPassword | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function setMinLength($minLength)
{
$this->minLength = (int) $minLength;
return $this;
} | Set the minimum length required for passwords
@param int $minLength
@return $this | setMinLength | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public function setMaxLength($maxLength)
{
$this->maxLength = (int) $maxLength;
return $this;
} | Set the maximum length required for passwords
@param int $maxLength
@return $this | setMaxLength | php | silverstripe/silverstripe-framework | src/Forms/ConfirmedPasswordField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/ConfirmedPasswordField.php | BSD-3-Clause |
public static function get($identifier = null)
{
if (!$identifier) {
return static::get_active();
}
// Create new instance if unconfigured
if (!isset(HTMLEditorConfig::$configs[$identifier])) {
HTMLEditorConfig::$configs[$identifier] = static::create();
HTMLEditorConfig::$configs[$identifier]->setOption('editorIdentifier', $identifier);
}
return HTMLEditorConfig::$configs[$identifier];
} | Get the HTMLEditorConfig object for the given identifier. This is a correct way to get an HTMLEditorConfig
instance - do not call 'new'
@param string $identifier The identifier for the config set. If omitted, the active config is returned.
@return static The configuration object.
This will be created if it does not yet exist for that identifier | get | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public static function set_config($identifier, HTMLEditorConfig $config = null)
{
if ($config) {
HTMLEditorConfig::$configs[$identifier] = $config;
HTMLEditorConfig::$configs[$identifier]->setOption('editorIdentifier', $identifier);
} else {
unset(HTMLEditorConfig::$configs[$identifier]);
}
return $config;
} | Assign a new config, or clear existing, for the given identifier
@param string $identifier A specific identifier
@param HTMLEditorConfig $config Config to set, or null to clear
@return HTMLEditorConfig The assigned config | set_config | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public static function getThemes()
{
if (isset(static::$current_themes)) {
return static::$current_themes;
}
return Config::inst()->get(static::class, 'user_themes');
} | Gets the current themes, if it is not set this will fallback to config
@return array | getThemes | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public static function set_active_identifier($identifier)
{
HTMLEditorConfig::$current = $identifier;
} | Set the currently active configuration object. Note that the existing active
config will not be renamed to the new identifier.
@param string $identifier The identifier for the config set | set_active_identifier | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public static function get_active_identifier()
{
$identifier = HTMLEditorConfig::$current ?: static::config()->get('default_config');
return $identifier;
} | Get the currently active configuration identifier. Will fall back to default_config
if unassigned.
@return string The active configuration identifier | get_active_identifier | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public static function get_active()
{
$identifier = HTMLEditorConfig::get_active_identifier();
return HTMLEditorConfig::get($identifier);
} | Get the currently active configuration object
@return HTMLEditorConfig The active configuration object | get_active | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public static function set_active(HTMLEditorConfig $config)
{
$identifier = static::get_active_identifier();
return static::set_config($identifier, $config);
} | Assigns the currently active config an explicit instance
@param HTMLEditorConfig $config
@return HTMLEditorConfig The given config | set_active | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public function getConfigSchemaData()
{
return [
'attributes' => $this->getAttributes(),
'editorjs' => null,
];
} | Provide additional schema data for the field this object configures
@return array | getConfigSchemaData | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorConfig.php | BSD-3-Clause |
public function __construct(HTMLEditorConfig $config)
{
$valid = $config->getOption('valid_elements');
if ($valid) {
$this->addValidElements($valid);
}
$valid = $config->getOption('extended_valid_elements');
if ($valid) {
$this->addValidElements($valid);
}
} | Construct a sanitiser from a given HTMLEditorConfig
Note that we build data structures from the current state of HTMLEditorConfig - later changes to
the passed instance won't cause this instance to update it's whitelist
@param HTMLEditorConfig $config | __construct | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorSanitiser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorSanitiser.php | BSD-3-Clause |
protected function patternToRegex($str)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::patternToRegex()'
);
return '/^' . preg_replace('/([?+*])/', '.$1', $str ?? '') . '$/';
} | Given a TinyMCE pattern (close to unix glob style), create a regex that does the match
@param $str - The TinyMCE pattern
@return string - The equivalent regex
@deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::patternToRegex() | patternToRegex | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorSanitiser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorSanitiser.php | BSD-3-Clause |
protected function getRuleForElement($tag)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::getRuleForElement()'
);
if (isset($this->elements[$tag])) {
return $this->elements[$tag];
}
foreach ($this->elementPatterns as $element) {
if (preg_match($element->pattern ?? '', $tag ?? '')) {
return $element;
}
}
return null;
} | Given an element tag, return the rule structure for that element
@param string $tag The element tag
@return stdClass The element rule
@deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::getRuleForElement() | getRuleForElement | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorSanitiser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorSanitiser.php | BSD-3-Clause |
protected function getRuleForAttribute($elementRule, $name)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with logic in SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule'
);
if (isset($elementRule->attributes[$name])) {
return $elementRule->attributes[$name];
}
foreach ($elementRule->attributePatterns as $attribute) {
if (preg_match($attribute->pattern ?? '', $name ?? '')) {
return $attribute;
}
}
return null;
} | Given an attribute name, return the rule structure for that attribute
@param object $elementRule
@param string $name The attribute name
@return stdClass The attribute rule
@deprecated 5.4.0 Will be replaced with logic in SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule | getRuleForAttribute | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorSanitiser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorSanitiser.php | BSD-3-Clause |
protected function elementMatchesRule($element, $rule = null)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::isElementAllowed()'
);
// If the rule doesn't exist at all, the element isn't allowed
if (!$rule) {
return false;
}
// If the rule has attributes required, check them to see if this element has at least one
if ($rule->attributesRequired) {
$hasMatch = false;
foreach ($rule->attributesRequired as $attr) {
if ($element->getAttribute($attr)) {
$hasMatch = true;
break;
}
}
if (!$hasMatch) {
return false;
}
}
// If the rule says to remove empty elements, and this element is empty, remove it
if ($rule->removeEmpty && !$element->firstChild) {
return false;
}
// No further tests required, element passes
return true;
} | Given a DOMElement and an element rule, check if that element passes the rule
@param DOMElement $element The element to check
@param stdClass $rule The rule to check against
@return bool True if the element passes (and so can be kept), false if it fails (and so needs stripping)
@deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorRuleSet::isElementAllowed() | elementMatchesRule | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorSanitiser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorSanitiser.php | BSD-3-Clause |
protected function attributeMatchesRule($attr, $rule = null)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule::isAttributeAllowed()'
);
// If the rule doesn't exist at all, the attribute isn't allowed
if (!$rule) {
return false;
}
// If the rule has a set of valid values, check them to see if this attribute is one
if (isset($rule->validValues) && !in_array($attr->value, $rule->validValues ?? [])) {
return false;
}
// No further tests required, attribute passes
return true;
} | Given a DOMAttr and an attribute rule, check if that attribute passes the rule
@param DOMAttr $attr - the attribute to check
@param stdClass $rule - the rule to check against
@return bool - true if the attribute passes (and so can be kept), false if it fails (and so needs stripping)
@deprecated 5.4.0 Will be replaced with SilverStripe\Forms\HTMLEditor\HTMLEditorElementRule::isAttributeAllowed() | attributeMatchesRule | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorSanitiser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorSanitiser.php | BSD-3-Clause |
public function getEditorConfig()
{
// Instance override
if ($this->editorConfig instanceof HTMLEditorConfig) {
return $this->editorConfig;
}
// Get named / active config
return HTMLEditorConfig::get($this->editorConfig);
} | Gets the HTMLEditorConfig instance
@return HTMLEditorConfig | getEditorConfig | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorField.php | BSD-3-Clause |
public function setEditorConfig($config)
{
$this->editorConfig = $config;
return $this;
} | Assign a new configuration instance or identifier
@param string|HTMLEditorConfig $config
@return $this | setEditorConfig | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorField.php | BSD-3-Clause |
public function __construct($name, $title = null, $value = '', $config = null)
{
parent::__construct($name, $title, $value);
if ($config) {
$this->setEditorConfig($config);
}
$this->setRows(HTMLEditorField::config()->default_rows);
} | Creates a new HTMLEditorField.
@see TextareaField::__construct()
@param string $name The internal field name, passed to forms.
@param string $title The human-readable field label.
@param mixed $value The value of the field.
@param string $config HTMLEditorConfig identifier to be used. Default to the active one. | __construct | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/HTMLEditorField.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/HTMLEditorField.php | BSD-3-Clause |
public function enablePlugins($plugin)
{
$plugins = func_get_args();
if (is_array(current($plugins ?? []))) {
$plugins = current($plugins ?? []);
}
foreach ($plugins as $name => $path) {
// if plugins are passed without a path
if (is_numeric($name)) {
$name = $path;
$path = null;
}
if (!array_key_exists($name, $this->plugins ?? [])) {
$this->plugins[$name] = $path;
}
}
return $this;
} | Enable one or several plugins. Will maintain unique list if already
enabled plugin is re-passed. If passed in as a map of plugin-name to path,
the plugin will be loaded by tinymce.PluginManager.load() instead of through tinyMCE.init().
Keep in mind that these externals plugins require a dash-prefix in their name.
@see https://www.tiny.cloud/docs/tinymce/6/editor-important-options/#external_plugins
If passing in a non-associative array, the plugin name should be located in the standard tinymce
plugins folder.
If passing in an associative array, the key of each item should be the plugin name.
The value of each item is one of:
- null - Will be treated as a standard plugin in the standard location
- relative path - Will be treated as a relative url
- absolute url - Some url to an external plugin
- An instance of ModuleResource object containing the plugin
@param string|array ...$plugin a string, or several strings, or a single array of strings - The plugins to enable
@return $this | enablePlugins | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/TinyMCEConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/TinyMCEConfig.php | BSD-3-Clause |
public function getInternalPlugins()
{
// Return only plugins with no custom url
$plugins = [];
foreach ($this->getPlugins() as $name => $url) {
if (empty($url)) {
$plugins[] = $name;
}
}
return $plugins;
} | Get list of plugins without custom locations, which is the set of
plugins which can be loaded via the standard plugin path, and could
potentially be minified
@return array | getInternalPlugins | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/TinyMCEConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/TinyMCEConfig.php | BSD-3-Clause |
public function getButtons()
{
return array_filter($this->buttons ?? []);
} | Get all button rows, skipping empty rows
@return array | getButtons | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/TinyMCEConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/TinyMCEConfig.php | BSD-3-Clause |
public function setButtonsForLine($line, $buttons)
{
if (func_num_args() > 2) {
$buttons = func_get_args();
array_shift($buttons);
}
$this->buttons[$line] = is_array($buttons) ? $buttons : [$buttons];
return $this;
} | Totally re-set the buttons on a given line
@param int $line The line number to redefine, from 1 to 3
@param string|string[] $buttons,... An array of strings, or one or more strings.
The button names to assign to this line.
@return $this | setButtonsForLine | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/TinyMCEConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/TinyMCEConfig.php | BSD-3-Clause |
public function addButtonsToLine($line, $buttons)
{
if (func_num_args() > 2) {
$buttons = func_get_args();
array_shift($buttons);
}
if (!is_array($buttons)) {
$buttons = [$buttons];
}
foreach ($buttons as $button) {
$this->buttons[$line][] = $button;
}
return $this;
} | Add buttons to the end of a line
@param int $line The line number to redefine, from 1 to 3
@param string ...$buttons A string or several strings, or a single array of strings.
The button names to add to this line
@return $this | addButtonsToLine | php | silverstripe/silverstripe-framework | src/Forms/HTMLEditor/TinyMCEConfig.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Forms/HTMLEditor/TinyMCEConfig.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.