Version: current

     1 <?php
     2 /**
     3  * A special type Int field used for primary keys.
     4  *
     5  * @todo Allow for custom limiting/filtering of scaffoldFormField dropdown
     6  *
     7  * @package sapphire
     8  * @subpackage model
     9  */
    10 class PrimaryKey extends Int {
    11     /**
    12      * @var DataObject
    13      */
    14     protected $object;
    15
    16     public static $default_search_filter_class = 'ExactMatchMultiFilter';
    17
    18     /**
    19      * @param string $name
    20      * @param DataOject $object The object that this is primary key for (should have a relation with $name)
    21      */
    22     function __construct($name, $object) {
    23         $this->object = $object;
    24         parent::__construct($name);
    25     }
    26
    27     public function scaffoldFormField($title = null, $params = null) {
    28         $titleField = ($this->object->hasField('Title')) ? "Title" : "Name";
    29         $map = new SQLMap($this->object->extendedSQL(), "ID", $titleField);
    30         return new DropdownField($this->name, $title, $map, null, null, ' ');
    31     }
    32 }
    33
    34 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -