public function defineContentAttribute()
 {
     $maxLength = $this->getSettings()->maxLength;
     if (!$maxLength) {
         $columnType = ColumnType::Text;
     } else {
         $columnType = DbHelper::getTextualColumnTypeByContentLength($maxLength);
     }
     return array(AttributeType::String, 'column' => $columnType, 'maxLength' => $maxLength);
 }
Ejemplo n.º 2
0
 /**
  * @inheritDoc IFieldType::defineContentAttribute()
  *
  * @return mixed
  */
 public function defineContentAttribute()
 {
     if ($this->multi) {
         $options = $this->getSettings()->options;
         // See how much data we could possibly be saving if everything was selected.
         $length = 0;
         foreach ($options as $option) {
             if (!empty($option['value'])) {
                 // +3 because it will be json encoded. Includes the surrounding quotes and comma.
                 $length += strlen($option['value']) + 3;
             }
         }
         if ($length) {
             // Add +2 for the outer brackets and -1 for the last comma.
             $length += 1;
             $columnType = DbHelper::getTextualColumnTypeByContentLength($length);
         } else {
             $columnType = ColumnType::Varchar;
         }
         return array(AttributeType::Mixed, 'column' => $columnType, 'default' => $this->getDefaultValue());
     } else {
         return array(AttributeType::String, 'column' => ColumnType::Varchar, 'maxLength' => 255, 'default' => $this->getDefaultValue());
     }
 }