You are here

function webform_node_value_nid_from_field in Webform Node Value 7

Set value of field in Webform with value from node.

Parameters

$settings:

$webform_value:

Return value

bool|string

1 call to webform_node_value_nid_from_field()
webform_node_value_client_submit in ./webform_node_value.module
Submit callback for the client form. Fetch node field value and insert it in Webform field.

File

./webform_node_value.module, line 191

Code

function webform_node_value_nid_from_field($settings, $webform_value) {
  if (empty($webform_value)) {
    return '';
  }
  $node_alias_path = ltrim($settings->prefix . $webform_value, '/');
  $path_parts = explode('/', $node_alias_path);
  if ($path_parts[0] != 'node' || !is_numeric($path_parts[1])) {
    $node_system_path = drupal_get_normal_path($node_alias_path);

    // No node system path found.
    if ($node_alias_path == $node_system_path) {
      watchdog('webform_node_value', 'System path not found %path', array(
        '%path' => $node_system_path,
      ));
      return '';
    }
    $path_parts = explode('/', $node_system_path);
  }
  if ($path_parts[0] != 'node' || !is_numeric($path_parts[1])) {
    watchdog('webform_node_value', t('Node not found.'));
    return '';
  }
  $nid = $path_parts[1];
  return $nid;
}