2008-08-11 01:17:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A special type Int field used for primary keys.
|
|
|
|
*
|
|
|
|
* @todo Allow for custom limiting/filtering of scaffoldFormField dropdown
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
|
|
|
|
*/
|
|
|
|
class PrimaryKey extends Int {
|
|
|
|
/**
|
|
|
|
* @var DataObject
|
|
|
|
*/
|
|
|
|
protected $object;
|
2008-08-11 01:29:30 +02:00
|
|
|
|
|
|
|
protected static $default_search_filter_class = 'ExactMatchMultiFilter';
|
2008-08-11 01:17:51 +02:00
|
|
|
|
|
|
|
function __construct($name, $object) {
|
|
|
|
$this->object = $object;
|
|
|
|
parent::__construct($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function scaffoldFormField($title = null) {
|
|
|
|
$objs = DataObject::get($this->object->class);
|
2008-08-11 01:29:30 +02:00
|
|
|
|
2008-08-11 02:03:57 +02:00
|
|
|
$titleField = (singleton($this->object->class)->hasField('Title')) ? "Title" : "Name";
|
2008-08-11 01:29:30 +02:00
|
|
|
|
|
|
|
$map = ($objs) ? $objs->toDropdownMap("ID", $titleField) : false;
|
2008-08-11 01:17:51 +02:00
|
|
|
|
|
|
|
return new DropdownField($this->name, $title, $map, null, null, ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|