You are here

function references_dialog_node_reference_edit_link in References dialog 7

Edit link callback for node references.

2 string references to 'references_dialog_node_reference_edit_link'
hook_references_dialog_widgets in ./references_dialog.api.php
Define a widget to which you want to attach add, search or edit links.
references_dialog_references_dialog_widgets in ./references_dialog.dialog_widgets.inc
Implements hook_references_dialog_widgets().

File

./references_dialog.dialog_widgets.inc, line 101
Implements dialogs for node reference and user reference fields.

Code

function references_dialog_node_reference_edit_link($element, $widget_settings, $field, $instance) {
  if (isset($element['#default_value']) || isset($element['#value'])) {
    if (isset($element['#default_value'])) {
      $value = $element['#default_value'];
    }
    else {

      // Take "label [nid:id]', match the id from parenthesis.
      if (preg_match('/^(?:\\s*|(.*) )?\\[\\s*nid\\s*:\\s*(\\d+)\\s*\\]$/', $element['#value'], $matches)) {
        list(, $title, $value) = $matches;
      }
      else {
        return array();
      }
    }
    $node = node_load($value);
    if (node_access('update', $node)) {
      return array(
        array(
          'title' => t('Edit'),
          'href' => 'node/' . $value . '/edit',
        ),
      );
    }
  }
  return array();
}