mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-05 01:01:17 +02:00
The main benefit of this is so that authors who make use of .editorconfig don't end up with whitespace changes in their PRs. Spaces vs. tabs has been left alone, although that could do with a tidy-up in SS4 after the switch to PSR-1/2. The command used was this: for match in '*.ss' '*.css' '*.scss' '*.html' '*.yml' '*.php' '*.js' '*.csv' '*.inc' '*.php5'; do find . -path ./thirdparty -not -prune -o -path ./admin/thirdparty -not -prune -o -type f -name "$match" -exec sed -E -i '' 's/[[:space:]]+$//' {} \+ find . -path ./thirdparty -not -prune -o -path ./admin/thirdparty -not -prune -o -type f -name "$match" | xargs perl -pi -e 's/ +$//' done
117 lines
2.4 KiB
PHP
117 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Read-only complement of {@link DropdownField}.
|
|
*
|
|
* Shows the "human value" of the dropdown field for the currently selected
|
|
* value.
|
|
*
|
|
* @package forms
|
|
* @subpackage fields-basic
|
|
*/
|
|
class LookupField extends DropdownField {
|
|
|
|
/**
|
|
* @var boolean $readonly
|
|
*/
|
|
protected $readonly = true;
|
|
|
|
/**
|
|
* Returns a readonly span containing the correct value.
|
|
*
|
|
* @param array $properties
|
|
*
|
|
* @return string
|
|
*/
|
|
public function Field($properties = array()) {
|
|
$source = $this->getSource();
|
|
|
|
// Normalize value to array to simplify further processing
|
|
if(is_array($this->value) || is_object($this->value)) {
|
|
$values = $this->value;
|
|
} else {
|
|
$values = array(trim($this->value));
|
|
}
|
|
|
|
$mapped = array();
|
|
|
|
if($source instanceof SQLMap) {
|
|
foreach($values as $value) {
|
|
$mapped[] = $source->getItem($value);
|
|
}
|
|
} else if($source instanceof ArrayAccess || is_array($source)) {
|
|
$source = ArrayLib::flatten($source);
|
|
|
|
foreach($values as $value) {
|
|
if(isset($source[$value])) {
|
|
$mapped[] = $source[$value];
|
|
}
|
|
}
|
|
} else {
|
|
$mapped = array();
|
|
}
|
|
|
|
// Don't check if string arguments are matching against the source,
|
|
// as they might be generated HTML diff views instead of the actual values
|
|
if($this->value && !is_array($this->value) && !$mapped) {
|
|
$mapped = array(trim($this->value));
|
|
$values = array();
|
|
}
|
|
|
|
if($mapped) {
|
|
$attrValue = implode(', ', array_values($mapped));
|
|
|
|
if(!$this->dontEscape) {
|
|
$attrValue = Convert::raw2xml($attrValue);
|
|
}
|
|
|
|
$inputValue = implode(', ', array_values($values));
|
|
} else {
|
|
$attrValue = '<i>('._t('FormField.NONE', 'none').')</i>';
|
|
$inputValue = '';
|
|
}
|
|
|
|
$properties = array_merge($properties, array(
|
|
'AttrValue' => $attrValue,
|
|
'InputValue' => $inputValue
|
|
));
|
|
|
|
return parent::Field($properties);
|
|
}
|
|
|
|
/**
|
|
* Ignore validation as the field is readonly
|
|
*
|
|
* @param Validator $validator
|
|
* @return bool
|
|
*/
|
|
public function validate($validator) {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Stubbed so invalid data doesn't save into the DB
|
|
*
|
|
* @param DataObjectInterface $record DataObject to save data into
|
|
*/
|
|
public function saveInto(DataObjectInterface $record) {
|
|
}
|
|
|
|
/**
|
|
* @return LookupField
|
|
*/
|
|
public function performReadonlyTransformation() {
|
|
$clone = clone $this;
|
|
|
|
return $clone;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function Type() {
|
|
return "lookup readonly";
|
|
}
|
|
}
|
|
|