From f0621cdd91c5fc2a972d3869fd202f1a4bb32c08 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 5 Feb 2013 18:41:11 +0000 Subject: [PATCH] FEATURE: Added ability to query size of Varchar This allows a developer to programatically access the size of the DB Varchar field. This allows us to be a bit more DRY and to define the size in one place and limit TextFields to the same value --- model/fieldtypes/Varchar.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/model/fieldtypes/Varchar.php b/model/fieldtypes/Varchar.php index 98f8eba0a..0540c332f 100644 --- a/model/fieldtypes/Varchar.php +++ b/model/fieldtypes/Varchar.php @@ -32,6 +32,19 @@ class Varchar extends StringField { parent::__construct($name, $options); } + /** + * Allow the ability to access the size of the field programatically. This + * can be useful if you want to have text fields with a length limit that + * is dictated by the DB field. + * + * TextField::create('Title')->setMaxLength(singleton('SiteTree')->dbObject('Title')->getSize()) + * + * @return int The size of the field + */ + public function getSize() { + return $this->size; + } + /** * (non-PHPdoc) * @see DBField::requireField()