mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-19 16:06:32 +02:00
10dece653f
BUG Fix namespace and getField on composite fields
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* A special type Int field used for primary keys.
|
|
*
|
|
* @todo Allow for custom limiting/filtering of scaffoldFormField dropdown
|
|
*
|
|
* @package framework
|
|
* @subpackage model
|
|
*/
|
|
class PrimaryKey extends Int {
|
|
/**
|
|
* @var DataObject
|
|
*/
|
|
protected $object;
|
|
|
|
private static $default_search_filter_class = 'ExactMatchFilter';
|
|
|
|
/**
|
|
* @var bool
|
|
*/
|
|
protected $autoIncrement = true;
|
|
|
|
public function setAutoIncrement($autoIncrement) {
|
|
$this->autoIncrement = $autoIncrement;
|
|
return $this;
|
|
}
|
|
|
|
public function getAutoIncrement() {
|
|
return $this->autoIncrement;
|
|
}
|
|
|
|
public function requireField() {
|
|
$spec = DB::get_schema()->IdColumn(false, $this->getAutoIncrement());
|
|
DB::require_field($this->getTable(), $this->getName(), $spec);
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
|
|
*/
|
|
public function __construct($name, $object = null) {
|
|
$this->object = $object;
|
|
parent::__construct($name);
|
|
}
|
|
|
|
public function scaffoldFormField($title = null, $params = null) {
|
|
return null;
|
|
}
|
|
|
|
public function scaffoldSearchField($title = null) {
|
|
parent::scaffoldFormField($title);
|
|
}
|
|
|
|
public function setValue($value, $record = null, $markChanged = true) {
|
|
parent::setValue($value, $record, $markChanged);
|
|
|
|
if($record instanceof DataObject) {
|
|
$this->object = $record;
|
|
}
|
|
}
|
|
}
|