Example #1
0
 /**
  * Throw a warning when a field is set to unique, while its maxLength is too large.
  */
 protected function _validateUniqueKeyLength(ArrayObject $config)
 {
     $restrictedFieldTypes = array('text', 'html');
     if (array_key_exists('inputs', $config)) {
         foreach ($config['inputs'] as $inputName => $input) {
             if (array_key_exists('unique', $input) && $input['unique'] && (!array_key_exists('type', $input) && !Garp_Spawn_Util::stringEndsIn('email', $inputName) && !Garp_Spawn_Util::stringEndsIn('url', $inputName) && !Garp_Spawn_Util::stringEndsIn('id', $inputName) && !Garp_Spawn_Util::stringEndsIn('date', $inputName) && !Garp_Spawn_Util::stringEndsIn('time', $inputName) || array_key_exists('type', $input) && in_array($input['type'], $restrictedFieldTypes)) && (!array_key_exists('maxLength', $input) || $input['maxLength'] > 255)) {
                 throw new Exception("You've set {$config['id']}.{$inputName} to unique, but this type of field has to have a maxLength of 255 at most to be made unique.");
             }
         }
     }
 }
Example #2
0
 protected function _setConditionalDefaults(array $config)
 {
     if (!array_key_exists('type', $config)) {
         foreach ($this->_defaultTypeByNameEnding as $ending => $type) {
             if (Garp_Spawn_Util::stringEndsIn($ending, $this->name)) {
                 $this->type = $type;
             }
         }
     }
     if (!array_key_exists('maxLength', $config)) {
         switch ($this->name) {
             case 'name':
             case 'subtitle':
                 $this->maxLength = self::TEXTFIELD_MAX_LENGTH;
                 break;
             case 'id':
                 $this->maxLength = 8;
                 break;
             case 'email':
                 $this->maxLength = 50;
                 break;
             default:
                 if (Garp_Spawn_Util::stringEndsIn('name', $this->name)) {
                     $this->maxLength = self::TEXTFIELD_MAX_LENGTH;
                 }
         }
     }
     if (!array_key_exists('multiline', $config) && $this->isTextual()) {
         $this->multiline = !$this->maxLength || $this->maxLength > self::TEXTFIELD_MAX_LENGTH;
     }
     if ($this->type === 'checkbox') {
         $this->required = false;
     }
     if (!array_key_exists('label', $config) || !$config['label']) {
         $this->label = Garp_Spawn_Util::underscored2readable(Garp_Spawn_Util::stringEndsIn('_id', $this->name) ? substr($this->name, 0, -3) : $this->name);
     } else {
         $this->label = ucfirst($this->label);
     }
     $this->required = (bool) $this->required;
 }