View source
<?php
function biblio_fields_field_info() {
return array(
'biblio_text' => array(
'label' => t('Biblio Text'),
'description' => t('Standard Text Field with the addition of the option to select a vertical tab for the add/edit form.'),
'default_widget' => 'biblio_text_widget',
'default_formatter' => 'biblio_text_formatter',
'instance_settings' => array(
'vtab' => t('None'),
),
'property_type' => 'text',
'property_callbacks' => array(
'entity_metadata_field_text_property_callback',
),
),
);
}
function biblio_fields_field_is_empty($item, $field) {
if ($field['type'] == 'biblio_text') {
if (empty($item['value']) && empty($item['vtab'])) {
return TRUE;
}
}
return FALSE;
}
function biblio_fields_field_instance_settings_form($field, $instance) {
if ($field['type'] == 'biblio_text') {
$form['vtab'] = array(
'#type' => 'select',
'#title' => t('Add/Edit form Vertical Tab'),
'#options' => array(
t('None'),
t('Authors'),
t('Abstract'),
t('Full Text'),
t('Publication'),
t('Publisher'),
t('Identifiers'),
t('Locators'),
t('Keywords'),
t('Notes'),
t('Alternate Titles'),
t('Other'),
),
'#default_value' => isset($instance['settings']['vtab']) ? $instance['settings']['vtab'] : t('None'),
'#required' => TRUE,
'#description' => t('The vertical tab location of the field in the Biblio add/edit form. Select "None" to leave the field out of the vertical tabs.'),
);
return $form;
}
}
function biblio_fields_field_widget_info() {
return array(
'biblio_text_widget' => array(
'label' => t('Text field'),
'description' => t('Shows as a standard text field'),
'field types' => array(
'biblio_text',
),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_DEFAULT,
),
),
);
}
function biblio_fields_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$base = $element;
if ($instance['widget']['type'] == 'biblio_text_widget') {
$element['value'] = array(
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#vtab' => $instance['settings']['vtab'],
) + $base;
}
return $element;
}
function biblio_fields_field_formatter_info() {
return array(
'biblio_text_formatter' => array(
'label' => t('Default'),
'field types' => array(
'biblio_text',
),
),
);
}
function biblio_fields_field_formatter_view($obj_type, $object, $field, $instance, $langcode, $items, $display) {
$element = array();
foreach ($items as $delta => $item) {
$element[$delta] = biblio_format_field($item);
}
return $element;
}
function biblio_format_field($item) {
$element = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'field-item',
),
),
);
$element['value'] = array(
'item' => array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'field-item',
),
),
'text' => array(
'#markup' => $item['value'],
),
),
);
return $element;
}