mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allowing empty selection in TypeDropdown
ENHANCEMENT Allowing to specify dropdown title field in TypeDropdown->setTitleFieldName() - patch by nicolaas (#2689) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62848 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2d8656e72b
commit
be90ef6573
@ -1,21 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Create a dropdown from all instances of a class
|
||||
* Create a dropdown from all instances of a class.
|
||||
*
|
||||
* @package forms
|
||||
* @subpackage fields-relational
|
||||
*
|
||||
* @deprecated 2.3 Misleading naming
|
||||
*/
|
||||
class TypeDropdown extends DropdownField {
|
||||
|
||||
function __construct( $name, $title, $className, $value = null, $form = null ) {
|
||||
|
||||
$options = DataObject::get( $className );
|
||||
|
||||
/**
|
||||
* @var string $titleFieldName The name of the DataObject property used for the dropdown options
|
||||
*/
|
||||
protected $titleFieldName = "Title";
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $title
|
||||
* @param string $className
|
||||
*/
|
||||
function __construct( $name, $title, $className, $value = null, $form = null, $emptyString = null) {
|
||||
$options = DataObject::get($className);
|
||||
|
||||
$optionArray = array( '0' => _t('TypeDropdown.NONE', 'None') );
|
||||
|
||||
foreach( $options as $option )
|
||||
$optionArray[$option->ID] = $option->Title;
|
||||
|
||||
parent::__construct( $name, $title, $optionArray, $value, $form );
|
||||
|
||||
if($options) foreach( $options as $option ) {
|
||||
$optionArray[$option->ID] = $option->{$this->titleFieldName};
|
||||
}
|
||||
|
||||
parent::__construct( $name, $title, $optionArray, $value, $form, $emptyString );
|
||||
}
|
||||
|
||||
function setTitleFieldName($name) {
|
||||
$this->titleFieldName = $name;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user