silverstripe-framework/model/fieldtypes/PrimaryKey.php
Loz Calver 40bf945322 NEW: PHP 7 compatibility
This patch introduces PHP 7 compatability without breaking semver by adding DBInt
and DBFloat classes, with Int/Float classes that are only loaded into PHP 5 environments
2017-04-05 11:00:04 +10:00

36 lines
922 B
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 DBInt {
/**
* @var DataObject
*/
protected $object;
private static $default_search_filter_class = 'ExactMatchFilter';
/**
* @param string $name
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
*/
public function __construct($name = null, $object) {
$this->object = $object;
parent::__construct($name);
}
public function scaffoldFormField($title = null, $params = null) {
$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;
}
}