Skip to content

Instantly share code, notes, and snippets.

@owldesign
Last active August 29, 2015 14:08
Show Gist options
  • Save owldesign/79bda5f668533ca4c435 to your computer and use it in GitHub Desktop.
Save owldesign/79bda5f668533ca4c435 to your computer and use it in GitHub Desktop.
FormBuilder_FieldModel.php
<?php
namespace Craft;
class FormBuilder_FieldModel extends BaseComponentModel
{
// Properties
private $_fieldType;
// Public Methods
public function __toString()
{
return Craft::t($this->name);
}
//Returns the field type this field is using.
public function getFieldType()
{
if (!isset($this->_fieldType))
{
$this->_fieldType = craft()->formBuilder_fields->populateFieldType($this);
// Might not actually exist
if (!$this->_fieldType)
{
$this->_fieldType = false;
}
}
// Return 'null' instead of 'false' if it doesn't exist
if ($this->_fieldType)
{
return $this->_fieldType;
}
}
// Returns the field's form.
public function getForm()
{
return craft()->formBuilder_fields->getFormById($this->formId);
}
// Protected Methods
protected function defineAttributes()
{
return array_merge(parent::defineAttributes(), array(
'name' => AttributeType::String,
'handle' => AttributeType::String,
'context' => AttributeType::String,
'instructions' => AttributeType::String,
'required' => AttributeType::Bool,
'translatable' => AttributeType::Bool,
'oldHandle' => AttributeType::String,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment