1 <?php
2 3 4 5 6
7 class Varchar extends StringField {
8
9 protected $size;
10
11 12 13 14 15 16 17
18 function __construct($name, $size = 50, $options = array()) {
19 $this->size = $size ? $size : 50;
20 parent::__construct($name, $options);
21 }
22
23 24 25 26
27 function requireField() {
28 $parts = array(
29 'datatype'=>'varchar',
30 'precision'=>$this->size,
31 'character set'=>'utf8',
32 'collate'=>'utf8_unicode_ci',
33 'arrayValue'=>$this->arrayValue
34 );
35
36 $values = array(
37 'type' => 'varchar',
38 'parts' => $parts
39 );
40
41 DB::requireField($this->tableName, $this->name, $values);
42 }
43
44 45 46
47 function Initial() {
48 if($this->hasValue()) return $this->value[0] . '.';
49 }
50
51 52 53
54 function URL() {
55 if(ereg('^[a-zA-Z]+://', $this->value)) return $this->value;
56 else return "http://" . $this->value;
57 }
58
59 60 61 62
63 function RTF() {
64 return str_replace("\n", '\par ', $this->value);
65 }
66
67 68 69 70 71 72
73 function LimitCharacters($limit = 20, $add = "...") {
74 $value = trim($this->value);
75 return (mb_strlen($value) > $limit) ? mb_substr($value, 0, $limit) . $add : $value;
76 }
77
78 79 80 81
82 public function scaffoldFormField($title = null, $params = null) {
83 if(!$this->nullifyEmpty) {
84
85 return new NullableField(new TextField($this->name, $title));
86 } else {
87
88 return parent::scaffoldFormField($title);
89 }
90 }
91 }
92
93 ?>
94
[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.
-