You are here

function node_field_node_reference_widget in Node Field 7.2

Widget for node_reference field.

1 string reference to 'node_field_node_reference_widget'
node_field_types_info in includes/node_field.field.inc
Node field types info.

File

includes/node_field.field.inc, line 429
Field types, settings, widget and formatters.

Code

function node_field_node_reference_widget($node_field) {
  $path = drupal_get_path('module', 'node_field');
  require_once $path . '/model/node_field.db.inc';
  $options = [];
  if (empty($node_field['settings'])) {
    drupal_set_message("Please select content type for field \"" . $node_field['title'] . "\"");
    return;
  }
  else {
    $content_type = $node_field['settings']['options'];
    $nodes = node_field_node_reference_db_get_nodes($content_type);
    foreach ($nodes as $nid => $title) {
      $options[$nid] = $title;
    }
    $form = [
      '#type' => 'select',
      '#title' => $node_field['title'],
      '#default_value' => $node_field['value'],
      '#options' => $options,
    ];
    return $form;
  }
}