How to get the standard text format widget for a custom field type? I've created a custom field that loads content from a given URL. The content is rendered with the given input format. That works fine.

Currently, I just gabe a list of available text input using filter_formats and show this with a select widget. How can I replace this with the standard input format widget that is available underneath the node body textarea?

This is how it's done now:

/**
 * Implements hook_field_widget_form().
 */
function remote_content_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {

    $url = isset($items[$delta]['url']) ? $items[$delta]['url'] : '';
    $tformatter = isset($items[$delta]['tformatter']) ? $items[$delta]['tformatter'] : 0;

    $widget = $element;

    $widget += array(
        ...
    );

    $widget['url'] = array(
        ...
    );
    $widget['tformatter'] = array(
        '#type' =&gt; 'select',
        '#title' =&gt; t('Text format'),
        '#options' =&gt; _remote_content_create_format_options(),
        '#default_value' =&gt; $tformatter,
        '#description' =&gt; t('Choose the appropriate text format.'),
    );

    $element = $widget;

    return $element;
}

function _remote_content_create_format_options() {
    global $user;

    $formats = filter_formats($user);
    $options = array();

    foreach($formats as $f) {
        $options[$f-&gt;format] = $f-&gt;name;
    }

    return $options;
}
You are looking for '#type' =&gt; 'text_format'. Usage example:

$form['text'] = array(
  '#type' =&gt; 'text_format',
  '#title' =&gt; t('Text'),
  '#default_value' =&gt; $text,
  '#format' =&gt; $format,
);


You will get the text in $form_state['values']['text']['value'] and the format in $form_state['values']['text']['format'].