2008-08-11 01:17:51 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* A special type Int field used for primary keys.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-08-11 01:17:51 +02:00
|
|
|
* @todo Allow for custom limiting/filtering of scaffoldFormField dropdown
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-03-22 23:59:14 +01:00
|
|
|
* @subpackage model
|
2008-08-11 01:17:51 +02:00
|
|
|
*/
|
|
|
|
class PrimaryKey extends Int {
|
|
|
|
/**
|
2014-08-15 08:53:05 +02:00
|
|
|
* @var DataObject
|
2008-08-11 01:17:51 +02:00
|
|
|
*/
|
|
|
|
protected $object;
|
2008-08-11 01:29:30 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $default_search_filter_class = 'ExactMatchFilter';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-03-22 23:59:14 +01:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
|
|
|
|
*/
|
2012-09-19 12:07:39 +02:00
|
|
|
public function __construct($name = null, $object) {
|
2008-08-11 01:17:51 +02:00
|
|
|
$this->object = $object;
|
|
|
|
parent::__construct($name);
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-10-14 00:20:41 +02:00
|
|
|
public function scaffoldFormField($title = null, $params = null) {
|
2012-05-23 12:45:04 +02:00
|
|
|
$titleField = ($this->object->hasField('Title')) ? 'Title' : 'Name';
|
|
|
|
$map = DataList::create(get_class($this->object))->map('ID', $titleField);
|
|
|
|
$field = new DropdownField($this->name, $title, $map);
|
|
|
|
$field->setEmptyString(' ');
|
|
|
|
return $field;
|
2008-08-11 01:17:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|