mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-19 16:06:32 +02:00
aeccb8b8e0
API: Deprecate SS_Datetime. The DBField subclasses are have all been renamed to start with “DB” and be in the SilverStripe\Model\FieldType namespace. To keep DataObject definitions concise, the original short variations of their names are preserved as service definitions. Most of the field generation code doesn’t need to change, but where field classes are referenced directly, changes will be needed. SS_Datetime, which is commonly referenced outside the model system itself, has been preserved as a subclass of DBDatetime. This has been marked as deprecated and can be removed in SilverStripe 5. A few places that referred to $db and $casting values weren’t using the Injector to instantiate the relevant classes. This meant that the remapping we have created as part of moving classes into a namespace didn’t work.
70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Model\FieldType;
|
|
|
|
use DataList;
|
|
use DropdownField;
|
|
use DB;
|
|
use DataObject;
|
|
|
|
/**
|
|
* A special type Int field used for primary keys.
|
|
*
|
|
* @todo Allow for custom limiting/filtering of scaffoldFormField dropdown
|
|
*
|
|
* @package framework
|
|
* @subpackage model
|
|
*/
|
|
class DBPrimaryKey extends DBInt {
|
|
/**
|
|
* @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;
|
|
}
|
|
}
|
|
}
|