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:
Andrew O'Neil 2008-10-22 03:42:57 +00:00 committed by Sam Minnee
parent 4c73c41ca9
commit f6aba9147d

View File

@ -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 );