Skip to content

Instantly share code, notes, and snippets.

@owldesign
Created November 6, 2014 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owldesign/6e92e67364e762d68253 to your computer and use it in GitHub Desktop.
Save owldesign/6e92e67364e762d68253 to your computer and use it in GitHub Desktop.
FormBuilder_FieldRecord.php
<?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