Commit 3448d949 authored by Dries's avatar Dries

- Patch #592572 by c960657 | moshe weitzman: API clean-up, always pass nodes as objects.

parent df83f786
......@@ -622,7 +622,7 @@ function _node_types_build() {
if (is_object($_node_types)) {
return $_node_types;
}
$_node_types = (object) array('types' => array(), 'names' => array());
$_node_types = (object)array('types' => array(), 'names' => array());
$info_array = module_invoke_all('node_info');
foreach ($info_array as $type => $info) {
......@@ -713,7 +713,7 @@ function node_type_set_defaults($info = array()) {
* Determine whether a node hook exists.
*
* @param $node
* Either a node object, node array, or a string containing the node type.
* A node object or a string containing the node type.
* @param $hook
* A string containing the name of the hook.
* @return
......@@ -728,7 +728,7 @@ function node_hook($node, $hook) {
* Invoke a node hook.
*
* @param $node
* Either a node object, node array, or a string containing the node type.
* A node object or a string containing the node type.
* @param $hook
* A string containing the name of the hook.
* @param $a2, $a3, $a4
......@@ -791,8 +791,6 @@ function node_load($nid = NULL, $vid = NULL, $reset = FALSE) {
* Perform validation checks on the given node.
*/
function node_validate($node, $form = array()) {
// Convert the node to an object, if necessary.
$node = (object)$node;
$type = node_type_get_type($node);
if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
......@@ -825,9 +823,6 @@ function node_validate($node, $form = array()) {
function node_submit($node) {
global $user;
// Convert the node to an object, if necessary.
$node = (object)$node;
if (user_access('administer nodes')) {
// Populate the "authored by" field.
if ($account = user_load_by_name($node->name)) {
......@@ -1040,7 +1035,7 @@ function node_revision_delete($revision_id) {
* Generate an array for rendering the given node.
*
* @param $node
* A node array or node object.
* A node object.
* @param $build_mode
* Build mode, e.g. 'full', 'teaser'...
*
......@@ -1048,8 +1043,6 @@ function node_revision_delete($revision_id) {
* An array as expected by drupal_render().
*/
function node_build($node, $build_mode = 'full') {
$node = (object)$node;
// Populate $node->content with a render() array.
node_build_content($node, $build_mode);
......@@ -2215,8 +2208,8 @@ function node_search_validate($form, &$form_state) {
* - "delete"
* - "create"
* @param $node
* The node object (or node array) on which the operation is to be performed,
* or node type (e.g. 'forum') for "create" operation.
* The node object on which the operation is to be performed, or node type
* (e.g. 'forum') for "create" operation.
* @param $account
* Optional, a user object representing the user for whom the operation is to
* be performed. Determines access for a user other than the current user.
......@@ -2231,10 +2224,6 @@ function node_access($op, $node, $account = NULL) {
// supported ones, we return access denied.
return FALSE;
}
// Convert the node to an object if necessary:
if ($op != 'create') {
$node = (object)$node;
}
// If no user object is supplied, the access check is for the current user.
if (empty($account)) {
$account = $user;
......
......@@ -61,7 +61,7 @@ function node_add($type) {
// If a node type has been specified, validate its existence.
if (isset($types[$type]) && node_access('create', $type)) {
// Initialize settings:
$node = array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => '');
$node = (object)array('uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => $type, 'language' => '');
drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH);
$output = drupal_get_form($type . '_node_form', $node);
......@@ -71,12 +71,11 @@ function node_add($type) {
}
function node_form_validate($form, &$form_state) {
$node = $form_state['values'];
$node = (object)$form_state['values'];
node_validate($node, $form);
// Field validation. Requires access to $form_state, so this cannot be
// done in node_validate() as it currently exists.
$node = (object)$node;
field_attach_form_validate('node', $node, $form, $form_state);
}
......@@ -111,12 +110,11 @@ function node_form($form, &$form_state, $node) {
global $user;
if (isset($form_state['node'])) {
$node = $form_state['node'] + (array)$node;
$node = (object)($form_state['node'] + (array)$node);
}
if (isset($form_state['node_preview'])) {
$form['#prefix'] = $form_state['node_preview'];
}
$node = (object)$node;
foreach (array('title') as $key) {
if (!isset($node->$key)) {
$node->$key = NULL;
......@@ -441,7 +439,7 @@ function node_form_submit_build_node($form, &$form_state) {
// functions to process the form values into an updated node.
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$node = node_submit($form_state['values']);
$node = node_submit((object)$form_state['values']);
field_attach_submit('node', $node, $form, $form_state);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment