Created
November 6, 2014 02:38
-
-
Save owldesign/6e92e67364e762d68253 to your computer and use it in GitHub Desktop.
FormBuilder_FieldRecord.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
class FormBuilder_FieldRecord extends BaseRecord | |
{ | |
protected $reservedHandleWords = array( | |
'archived', | |
'children', | |
'dateCreated', | |
'dateUpdated', | |
'enabled', | |
'id', | |
'link', | |
'locale', | |
'parents', | |
'siblings', | |
'uid', | |
'uri', | |
'url', | |
'ref', | |
'status', | |
'title', | |
); | |
// Get Table Fields | |
public function getTableName() | |
{ | |
return 'formbuilder_fields'; | |
} | |
// Define Relationships | |
public function defineRelations() | |
{ | |
return array( | |
'form' => array(static::BELONGS_TO, 'FormBuilder_FormRecord', 'onDelete' => static::CASCADE), | |
); | |
} | |
public function defineIndexes() | |
{ | |
return array( | |
array('columns' => array('handle', 'context'), 'unique' => true), | |
array('columns' => array('context')), | |
); | |
} | |
public function scopes() | |
{ | |
return array( | |
'ordered' => array('order' => 'name'), | |
); | |
} | |
public function getAttributeConfigs() | |
{ | |
$attributeConfigs = parent::getAttributeConfigs(); | |
// Field handles must be <= 58 chars so that with "field_" prepended, they're <= 64 chars (MySQL's column | |
// name limit). | |
$attributeConfigs['handle']['maxLength'] = 64 - strlen(craft()->content->fieldColumnPrefix); | |
return $attributeConfigs; | |
} | |
protected function defineAttributes() | |
{ | |
return array( | |
'name' => array(AttributeType::Name, 'required' => true), | |
'handle' => array(AttributeType::Handle, 'required' => true, 'reservedWords' => $this->reservedHandleWords), | |
'context' => array(AttributeType::String, 'default' => 'global', 'required' => true), | |
'instructions' => array(AttributeType::String, 'column' => ColumnType::Text), | |
'translatable' => AttributeType::Bool, | |
'type' => array(AttributeType::ClassName, 'required' => true), | |
'settings' => AttributeType::Mixed, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment