mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
0b1f297873
Conflicts: .travis.yml README.md admin/code/LeftAndMain.php admin/css/screen.css admin/scss/screen.scss api/RestfulService.php conf/ConfigureFromEnv.php control/injector/ServiceConfigurationLocator.php control/injector/SilverStripeServiceConfigurationLocator.php core/ClassInfo.php core/Object.php css/AssetUploadField.css css/ComplexTableField_popup.css dev/CSSContentParser.php dev/DevelopmentAdmin.php docs/en/changelogs/index.md docs/en/misc/contributing/code.md docs/en/reference/execution-pipeline.md filesystem/GD.php filesystem/ImagickBackend.php filesystem/Upload.php forms/Form.php forms/FormField.php forms/HtmlEditorConfig.php forms/gridfield/GridFieldDetailForm.php forms/gridfield/GridFieldSortableHeader.php lang/en.yml model/Aggregate.php model/DataList.php model/DataObject.php model/DataQuery.php model/Image.php model/MySQLDatabase.php model/SQLQuery.php model/fieldtypes/HTMLText.php model/fieldtypes/Text.php scss/AssetUploadField.scss search/filters/SearchFilter.php security/Authenticator.php security/LoginForm.php security/Member.php security/MemberAuthenticator.php security/MemberLoginForm.php security/Security.php tests/behat/features/bootstrap/SilverStripe/Framework/Test/Behaviour/CmsFormsContext.php tests/control/HTTPTest.php tests/control/RequestHandlingTest.php tests/filesystem/UploadTest.php tests/forms/FormTest.php tests/forms/NumericFieldTest.php tests/model/DataListTest.php tests/model/DataObjectTest.php tests/model/TextTest.php tests/security/MemberAuthenticatorTest.php tests/security/SecurityDefaultAdminTest.php tests/view/SSViewerCacheBlockTest.php tests/view/SSViewerTest.php
99 lines
2.0 KiB
PHP
99 lines
2.0 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);
|
|
}
|
|
|
|
/**
|
|
* @return LookupField
|
|
*/
|
|
public function performReadonlyTransformation() {
|
|
$clone = clone $this;
|
|
|
|
return $clone;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function Type() {
|
|
return "lookup readonly";
|
|
}
|
|
}
|
|
|