From f6aba9147dabf9308e191afda5e1c533eeb52203 Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Wed, 22 Oct 2008 03:42:57 +0000 Subject: [PATCH] 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 --- forms/TypeDropdown.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/forms/TypeDropdown.php b/forms/TypeDropdown.php index 630938576..edecd5cbc 100755 --- a/forms/TypeDropdown.php +++ b/forms/TypeDropdown.php @@ -11,15 +11,23 @@ * @subpackage fields-relational */ 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 = array( '0' => _t('TypeDropdown.NONE', 'None') ); + $optionArray = $includeNone ? array('0' => _t('TypeDropdown.NONE', 'None')) : array(); if($options) foreach($options as $option) { - $optionArray[$option->ID] = $option->Title; + $optionArray[$option->ID] = $option->$titleField; } parent::__construct( $name, $title, $optionArray, $value, $form );