Like plugins, fieldtypes can have their own settings as you're aware but while you can grab your plugin settings from pretty much anywhere, fieldtypes are a little more contextual.
In any case, like @Bryan pointed out, your fieldtype needs to implement prepValue($value)
and ideally return a model containing the value as defined in defineAttributes()
and the maxNumber
as a property.
This basically means that when Craft calls your fieldtype's prepValue($value)
which it does when the value of your field is needed (editing/outputting) you can return a model with the value
and maxNumber
.
EDIT:
// MyFieldType.php
public function prepValue($value)
{
$model = new MyFieldModel;
$model->setAttribute('value', $value);
$model->setMaxNumber($this->getSettings()->getAttribute('maxNumber'));
return $model;
}
// MyFieldModel.php
// Explicit getter/setter for $maxNumber rather than defining it as an attribute
protected $maxNumber;
public function setMaxNumber($value)
{
$this->maxNumber = $value;
}
public function getMaxNumber()
{
return $this->maxNumber;
}
public function defineAttributes()
{
return array(
'value' => AttributeType::Number,
);
}
// _entry.html or other template name
{{ entry.myFieldHandle.value }}
{{ entry.myFieldHandle.maxNumber }}
@selvinortiz