mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Add ability to disable 'None' option and to choose the title field in TypeDropdown
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2@64635 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
4c73c41ca9
commit
f6aba9147d
@ -11,15 +11,23 @@
|
|||||||
* @subpackage fields-relational
|
* @subpackage fields-relational
|
||||||
*/
|
*/
|
||||||
class TypeDropdown extends DropdownField {
|
class TypeDropdown extends DropdownField {
|
||||||
|
/**
|
||||||
function __construct( $name, $title, $className, $value = null, $form = null ) {
|
* Create a type dropdown field.
|
||||||
|
* @param string $name The field name
|
||||||
|
* @param string $title The field title
|
||||||
|
* @param string $className The class name of the related class
|
||||||
|
* @param int $value The current value
|
||||||
|
* @param Form $form The parent form
|
||||||
|
* @param boolean $includeNone Include 'None' in the dropdown
|
||||||
|
* @param string $titleField The field on the object to use as the title in the dropdown
|
||||||
|
*/
|
||||||
|
function __construct($name, $title, $className, $value = null, $form = null, $includeNone = true, $titleField = 'Title') {
|
||||||
|
$options = DataObject::get($className);
|
||||||
|
|
||||||
$options = DataObject::get( $className );
|
$optionArray = $includeNone ? array('0' => _t('TypeDropdown.NONE', 'None')) : array();
|
||||||
|
|
||||||
$optionArray = array( '0' => _t('TypeDropdown.NONE', 'None') );
|
|
||||||
|
|
||||||
if($options) foreach($options as $option) {
|
if($options) foreach($options as $option) {
|
||||||
$optionArray[$option->ID] = $option->Title;
|
$optionArray[$option->ID] = $option->$titleField;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct( $name, $title, $optionArray, $value, $form );
|
parent::__construct( $name, $title, $optionArray, $value, $form );
|
||||||
|
Loading…
Reference in New Issue
Block a user