Skip to content

Instantly share code, notes, and snippets.

@mbopp
Last active May 16, 2016 15:16
Show Gist options
  • Save mbopp/ed3a596f629256d51996d5b3470284e7 to your computer and use it in GitHub Desktop.
Save mbopp/ed3a596f629256d51996d5b3470284e7 to your computer and use it in GitHub Desktop.
Contributed Field Widget in Custom Form
<?php
$field = field_info_field('field_some_youtube_video');
$instance = field_info_instance('node','field_some_youtube_video','custom_video');
$items = array();
if (isset($node->field_some_youtube_video[LANGUAGE_NONE][0])) {
$items = $node->field_some_youtube_video[LANGUAGE_NONE];
}
$form['#parents'] = array(); // a required element to use 'field_default_form' function below.
$video_field = field_default_form('node', $node, $field, $instance, LANGUAGE_NONE, $items, $form, $form_state);
$form['video'] = $video_field['field_some_youtube_video'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment