3

I've been trying to create a custom field for my module. I have used the field_example module as a guide but my field doesn't show up in the 'field type' dropdown on the 'manage fields' page.

Here is my code:

mantis.module

function mantis_field_info() {
    return array(
        'mantisform' => array(
            'label' => 'Mantis ' . t('Form'),
            'description' => 'Mantis Support Request Form',
            'default_widget' => 'mantis_mantisform_widget',
            'default_formatter' => 'mantisform_default'
         )
    );
}

function mantis_field_is_empty($item, $field) {
    if($field['type'] == 'mantisform') {
        if(empty($field['mantis_form_id'])) {
            return true;
        }
    }
    return false;
}

function mantis_field_widget_info() {

    return array(
    'mantis_mantisform_widget' => array(
        'label' => 'Mantis ' . t('Form'),
        'field_types' => array('mantisform'),
        'behaviors' => array(
            'multiple_values' => FIELD_BEHAVIOR_DEFAULT,
            'default_value' => FIELD_BEHAVIOR_NONE
            )
        )
    );
}

function mantis_field_widget_form($form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {

    $base = $element;

    if($instance['widget']['type'] == 'mantis_mantisform_widget') {
        $widget = $instance['settings'];
        $settings = $widget['settings'];

        $element['mantis_form_id'] = array(
            '#type' => 'select',
            '#title' => t('Support Request Form'),
            '#default_value' => isset($items[$delta]['mantis_form_id']) ? $items[$delta]['mantis_form_id'] : NULL
        );
    }
    return $element;
}

function mantis_field_formatter_info() {
    return array(
        'mantisform_default' => array(
            'label' => t('Default'),
            'description' => t('Allows a ') . 'mantis' . t('support form to be selected'),
            'field types' => array('mantisform'),
        )
    );
}

function mantis_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {

    $element = array();

    switch($display['type']) {
        case 'mantisform_default': {

        }
    }
    return $element;
}

mantis.install

function mantis_field_schema($field) {
    if($field['type'] == 'mantisform') {
        $schema['columns']['mantis_form_id'] = array(
                'type' => 'int',
                'not null' => false,
        );
        return $schema;
    }
}

I haven't completely fleshed out mantis_field_formatter_view but figured that I should still be able to see the new field as an option in the dropdown.

Can anyone see where I'm going wrong?

3
  • 1
    You cleared all caches? Feb 3 '13 at 20:53
  • Yeah, several times. Tried uninstalling the module and re-enabling it as well. Feb 4 '13 at 9:09
  • This does appear to have been a caching issue. The field has appeared now. weird. Feb 4 '13 at 14:57
0

This does appear to have been a caching issue. The field has appeared now. weird.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.