You are here

function nodereference_node_deploy in Deploy - Content Staging 6

Implementation of hook_node_deploy(),

@todo does this work with select lists as well? or just with autocomplete lists?

Parameters

$nid: Unique identifier for the node we're deploying.

Return value

The results of our xmlrpc call.

File

modules/nodereference_deploy/nodereference_deploy.module, line 18
Deployment module for nodereferences

Code

function nodereference_node_deploy(&$node) {
  $nodereference_fields = nodereference_deploy_get_nodereference_fields();
  foreach ($nodereference_fields as $field_name) {
    if (property_exists($node, $field_name)) {
      $field = array();
      foreach ($node->{$field_name} as $key => $nodereference) {
        if (!empty($nodereference['nid']['nid'])) {

          // The nid is actually stored as follows sent to us as
          // <node title> [nid:<nid>]
          // The following regex comes from nodereference.module to parse the nid out
          // of that string. We then put it back together when we get our remote nid.
          preg_match('/^(?:\\s*|(.*) )?\\[\\s*nid\\s*:\\s*(\\d+)\\s*\\]$/', $nodereference['nid']['nid'], $matches);
          if (!empty($matches)) {
            $uuid = deploy_uuid_get_node_uuid($matches[2]);
            $remote_data = deploy_get_remote_key(deploy_uuid_get_node_uuid($matches[2]), 'node');
            if ($remote_data) {
              $field[$key]['nid'] = array(
                'nid' => '[nid:' . $remote_data['nid'] . ']',
              );
            }
          }
          elseif (is_numeric($key)) {

            // Then this is a select list so we get the data in a different format.
            $uuid = deploy_uuid_get_node_uuid($nodereference['nid']);
            $remote_data = deploy_get_remote_key(deploy_uuid_get_node_uuid($nodereference['nid']), 'node');
            if ($remote_data) {

              // This format works for all widgets.
              $field['nid']['nid'][$remote_data['nid']] = $remote_data['nid'];
            }
          }
        }
        else {
          $field[$key]['nid'] = array(
            'nid' => '',
          );
        }
      }
      $node->{$field_name} = $field;
    }
  }
}