Hey folks,

Needed to add a reference dialog to a custom field, and was thrilled to see how robust the API is for adding your own. One issue though, my custom field is a fieldset, and the default target doesn't account for that. Attaching a patch below that allows you to specify your own target, with a $key token of what the default is. Here's some example code for usage:

/**
 * Implements hook_references_dialog_widgets().
 */
function image_caption_ref_references_dialog_widgets() {
  return array(
    'image_caption_ref' => array(
      'element_type' => 'fieldset',
      'dialog_form' => 'node_reference_dialog_form',
      'entity_type' => 'node',
      'format' => '$label [nid:$entity_id]',
      'target' => '$key-entity-id', // Will become something like "edit-field-images-und-0-entity-id"
      'views_query' => 'image_caption_ref_dialog_views_query',
      'operations' => array(
        'search' => array(
          'function' => 'references_dialog_get_field_search_links',
          'title' => t('Search Dialog'),
        ),
        'edit' => array(
          'function' => 'references_dialog_node_reference_edit_link',
          'title' => t('Edit dialog'),
        ),
        'add' => array(
          'function' => 'references_dialog_node_reference_add_link',
          'title' => t('Add dialog'),
        ),
      ),
    ),
  );
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wbobeirne’s picture

Status: Active » Needs review
FileSize
1.61 KB
Anonymous’s picture

Issue summary: View changes
FileSize
1.63 KB

I re-rolled this against the latest dev

Status: Needs review » Needs work

The last submitted patch, 2: custom_target-1928296-2.patch, failed testing.