From 578ee5d9f24023246965f407f5b206e202f84f1f Mon Sep 17 00:00:00 2001 From: Andrew Aitken-Fincham Date: Tue, 23 Jan 2018 14:18:48 +0000 Subject: [PATCH] make dropdownFieldThreshold configurable on DBForeignKey --- src/ORM/FieldType/DBForeignKey.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ORM/FieldType/DBForeignKey.php b/src/ORM/FieldType/DBForeignKey.php index c01a945beb1..3c3fdcba49e 100644 --- a/src/ORM/FieldType/DBForeignKey.php +++ b/src/ORM/FieldType/DBForeignKey.php @@ -29,6 +29,16 @@ class DBForeignKey extends DBInt */ protected $object; + /** + * This represents the number of related objects to show in a dropdown before it reverts + * to a NumericField. If you are tweaking this value, you should also consider constructing + * your form field manually rather than allowing it to be scaffolded + * + * @config + * @var int + */ + private static $dropdown_field_threshold = 100; + private static $index = true; private static $default_search_filter_class = 'ExactMatchFilter'; @@ -63,11 +73,13 @@ public function scaffoldFormField($title = null, $params = null) $list = DataList::create($hasOneClass); // Don't scaffold a dropdown for large tables, as making the list concrete // might exceed the available PHP memory in creating too many DataObject instances - if ($list->count() < 100) { + $threshold = self::config()->get('dropdown_field_threshold'); + if ($list->count() < $threshold) { $field = new DropdownField($this->name, $title, $list->map('ID', $titleField)); $field->setEmptyString(' '); } else { $field = new NumericField($this->name, $title); + $field->setRightTitle('Too many related objects; fallback field in use'); } return $field; }