You are here

function cf_node_create in Common Functionality 7.2

Same name and namespace in other branches
  1. 7 modules/cf_node/cf_node.module \cf_node_create()

Programatically creates a node of the form type and returns any errors.

This flushes the error buffer allowing for multiple calls. This will always return an array.

Parameters

string $form_id: The node type to initialize.

string $node_class: Should be created via the cf_node_initialize_class() function and then altered as necessary.

Return value

array An array of all errors (if any) that occurred during the creation process.

Related topics

File

modules/cf_node/cf_node.module, line 90
Common Functionality - Node module.

Code

function cf_node_create($form_id, $node_class) {
  if (cf_is_empty_or_non_string('form_id', $form_id, WATCHDOG_ERROR)) {
    return array();
  }
  if (!is_object($node_class)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_object('node_class');
    }
    return array();
  }
  $node_state = array(
    'values' => (array) $node_class,
  );
  $node_state['values']['op'] = t('Save');
  if (!cf_has_array_key('name', $node_state['values'])) {
    $current_user = cf_current_user();
    $node_state['values']['name'] = $current_user->name;
  }
  drupal_execute($form_id, $custom_state, $custom_node);
  $form_errors = form_get_errors();
  if (!is_array($form_errors)) {
    $form_errors = array();
  }

  // reset form error array
  form_set_error(NULL, '', TRUE);
  return $form_errors;
}