Posted by hkvega01 on March 9, 2013 at 12:51pm
i've created a custom field for a content type, which not yet provided with a form let users input value while adding content. i'm just want the field show my wanted value, the following is the testing code
function codeless_discounts_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
// This formatter simply outputs the field as text and with a color.
case 'default':
if (empty($items)) {
$item = array();
$item["codeless_discounts"] = 'test';
$items[] = $item;
}
foreach ($items as $delta => $item) {
$element['discount'] = array(
'#type' => 'html_tag',
'#tag' => 'p',
'#attributes' => array(
//'style' => 'color: ' . $item['codeless_discounts'],
),
'#value' => t('The color code in this field is @code', array('@code' => $item["codeless_discounts"])),
);
}
break;
}
return $element;
}i discovered that, if the field is empty of the content, the field don't displays, even i hardcode the #value, anyway i can solve the problem?
Comments
You might want to look at the
You might want to look at the field example in the developers example module.