2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-09-22 20:59:00 +02:00
|
|
|
* Create a dropdown from all instances of a class.
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-relational
|
2008-09-22 20:59:00 +02:00
|
|
|
*
|
2008-10-19 02:41:16 +02:00
|
|
|
* @deprecated 2.3 Misleading naming, and having an entire class dedicated
|
|
|
|
* to just setting the source mapping for a DropdownField is overkill. Just
|
|
|
|
* use a standard DropdownField instead.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class TypeDropdown extends DropdownField {
|
|
|
|
|
2008-09-22 20:59:00 +02:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
2007-10-25 04:47:45 +02:00
|
|
|
$optionArray = array( '0' => _t('TypeDropdown.NONE', 'None') );
|
2008-09-22 20:59:00 +02:00
|
|
|
|
|
|
|
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;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|