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(&$form, &$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' => 'select',
        '#title' => t('Text format'),
        '#options' => _remote_content_create_format_options(),
        '#default_value' => $tformatter,
        '#description' => 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->format] = $f->name;

    return $options;

1 Answer 1


You are looking for '#type' => 'text_format'. Usage example:

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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