node_form

Хочешь помочь с переводом? Это очень просто и быстро. Лишь зарегистрируйся, и можешь тут же начать переводить.

modules/node/node.module, строка 2072

Версии
5
node_form($node, $form_values = NULL)
6
node_form(&$form_state, $node)

Generate the node add/edit form array.

Код

<?php
function node_form($node, $form_values = NULL) {
  global $user;

  $node = (object)$node;
  node_object_prepare($node);

  // Set the id of the top-level form tag
  $form['#id'] = 'node-form';

  /**
   * Basic node information.
   * These elements are just values so they are not even sent to the client.
   */
  foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) {
    $form[$key] = array('#type' => 'value', '#value' => $node->$key);
  }

  // Changed must be sent to the client, for later overwrite error checking.
  $form['changed'] = array('#type' => 'hidden', '#default_value' => $node->changed);

  // Get the node-specific bits.
  if ($extra = node_invoke($node, 'form', $form_values)) {
    $form = array_merge_recursive($form, $extra);
  }
  if (!isset($form['title']['#weight'])) {
    $form['title']['#weight'] = -5;
  }

  $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
  // If this is a new node, fill in the default values.
  if (!isset($node->nid)) {
    foreach (array('status', 'promote', 'sticky') as $key) {
      $node->$key = in_array($key, $node_options);
    }
    global $user;
    $node->uid = $user->uid;
  }
  // Always use the default revision setting.
  $node->revision = in_array('revision', $node_options);

  $form['#node'] = $node;

  // Add a log field if the "Create new revision" option is checked, or if the
  // current user has the ability to check that option.
  if ($node->revision || user_access('administer nodes')) {
    $form['log'] = array(
      '#type' => 'textarea',
      '#title' => t('Log message'),
      '#rows' => 2,
      '#weight' => 20,
      '#description' => t('An explanation of the additions or updates being made to help other authors understand your motivations.'),
    );
  }

  // Node author information for administrators
  $form['author'] = array(
    '#type' => 'fieldset',
    '#access' => user_access('administer nodes'),
    '#title' => t('Authoring information'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 20,
  );
  $form['author']['name'] = array('#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, '#autocomplete_path' => 'user/autocomplete', '#default_value' => $node->name ? $node->name : '', '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => variable_get('anonymous', t('Anonymous')))));
  $form['author']['date'] = array('#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#description' => t('Format: %time. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? $node->date : format_date($node->created, 'custom', 'Y-m-d H:i:s O'))));

  if (isset($node->date)) {
    $form['author']['date']['#default_value'] = $node->date;
  }

  // Node options for administrators
  $form['options'] = array(
    '#type' => 'fieldset',
    '#access' => user_access('administer nodes'),
    '#title' => t('Publishing options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 25,
  );
  $form['options']['status']   = array('#type' => 'checkbox', '#title' => t('Published'), '#default_value' => $node->status);
  $form['options']['promote']  = array('#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->promote);
  $form['options']['sticky']   = array('#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->sticky);
  $form['options']['revision'] = array('#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->revision);
  // These values are used when the user has no administrator access.
  foreach (array('uid', 'created') as $key) {
    $form[$key] = array('#type' => 'value', '#value' => $node->$key);
  }

  // Add the buttons.
  $form['preview'] = array('#type' => 'button', '#value' => t('Preview'), '#weight' => 40);
  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 45);
  if ($node->nid && node_access('delete', $node)) {
    $form['delete'] = array('#type' => 'button', '#value' => t('Delete'), '#weight' => 50);
  }
  $form['#after_build'] = array('node_form_add_preview');
  // Ensure that node_validate() will always get called.
  $form['#validate']['node_form_validate'] = array();
  // Also, if the module defines its own _validate() routine based on the
  // form_id, include that in the #validate array, as well.
  $node_validate = $node->type .'_node_form_validate';
  if (function_exists($node_validate)) {
    $form['#validate'][$node_validate] = array();
  }
  $form['#base'] = 'node_form';
  return $form;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии

Вход в систему