I'm getting a big performance hit on front end requests (+15 seconds) when using a model to store / use data from one of my custom fieldtypes, cp requests for the same data appear unaffected.
The prepValue function:
public function prepValue($value)
{
if( is_array($value) )
{
return FruitGrid_BlockModel::populateModels($value);
}
return $value;
}
And the model which is getting populated:
class FruitGrid_BlockModel extends BaseModel
{
protected function defineAttributes()
{
return array(
'row' => array(AttributeType::Number),
'col' => array(AttributeType::Number),
'sizex' => array(AttributeType::Number),
'sizey' => array(AttributeType::Number),
'entryid' => array(AttributeType::Number),
'rules' => array(AttributeType::Mixed),
);
}
public function getRuleClasses()
{
$string = '';
if(is_array($this->rules))
{
foreach ($this->rules as $rule => $value)
{
switch ($rule)
{
case 'fixedHeight':
$string .= ' height-'.$value;
break;
case 'desktopRuleOne':
$string .= ' desktop-'.$value;
break;
case 'tabletRuleOne':
$string .= ' tablet-'.$value;
break;
case 'mobileRuleOne':
$string .= ' mobile-'.$value;
break;
}
}
}
return trim($string);
}
public function getEntry()
{
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->id = $this->entryid;
return $criteria->first();
}
}
And pretty standard usage on the front end:
{% if entry.customFieldHandle|length %}
{% for block in entry.customFieldHandle %}
<h1>{{ block.entry.title }}</h2>
<p>{{ block.entry.text }}</p>
...
{% endfor %}
{% endif %}