1 node.pages.inc node_preview_banner_form(array $form, array $form_state, Node $node, $node_tempstore_id)

Get the preview form selection box.

@since 1.11.0

Parameters

$node: A node entity.

$node_tempstore_id: The tempstore ID of the node being previewed.

Return value

array $form: The form which provides access to node preview operations.

File

core/modules/node/node.pages.inc, line 662
Callbacks for adding, editing, and deleting content and managing revisions.

Code

function node_preview_banner_form(array $form, array $form_state, Node $node, $node_tempstore_id) {
  // Always add the 'default' view mode.
  $view_mode_options = array();

  // Get view mode options.
  $entity_info = entity_get_info('node');
  $view_modes = $entity_info['view modes'];
  if (is_array($view_modes)) {
    backdrop_sort($view_modes, array('label' => SORT_STRING));
  }

  foreach ($view_modes as $key => $info) {
    if (!in_array($key, array('rss', 'search_index', 'search_result'))) {
      $view_mode_options[$key] = $info['label'];
    }

    // In case this is the 'full' view mode, rename default.
    if ($key == 'full') {
      $view_mode_options[$key] = t('Default');
    }
  }

  $path = 'node/add/' . str_replace('_', '-', $node->bundle());
  if (!empty($node->nid)) {
    $path = 'node/' . $node->nid . '/edit';
  }
  $query = array('node_tempstore_id' => $node_tempstore_id);
  $url = url($path, array('query' => $query, 'absolute' => TRUE));

  // Get the view mode to render the preview in.
  $view_mode = empty($_GET['view_mode']) ? 'full' : $_GET['view_mode'];

  $form['node'] = array(
    '#type' => 'value',
    '#value' => $node,
  );

  $form['node_tempstore_id'] = array(
    '#type' => 'value',
    '#value' => $node_tempstore_id,
  );

  $form['backlink'] = array(
    '#type' => 'link',
    '#title' => t('Back to content editing'),
    '#href' => $url,
    '#attributes' => array('class' => array('node-preview-backlink')),
  );

  $form['view_mode'] = array(
    '#type' => 'select',
    '#title' => t('Select a display mode'),
    '#options' => $view_mode_options,
    '#default_value' => $view_mode,
    '#attributes' => array(
      'onChange' => 'this.form.submit()',
      'class' => array('node-preview-display-mode', 'preview-button'),
    )
  );
  // This must be the first submit function so the 'onChange' event calls it
  // before any other submit.
  $form['view_mode_submit'] = array(
    '#type' => 'submit',
    '#name' => 'op',
    '#submit' => array('node_preview_banner_form_view_mode_submit'),
    '#value' => t('Switch'),
    '#attributes' => array(
      'class' => array('node-preview-switch-button', 'preview-button', 'js-hide')
    )
  );
  $form['preview_node_submit'] = array(
    '#type' => 'submit',
    '#submit' => array('node_preview_banner_form_node_submit'),
    '#value' => t('Save'),
    '#attributes' => array(
      'class' => array('node-preview-save-button', 'preview-button'),
    )
  );
  $form['#theme'] = 'node_preview_banner_form';

  return $form;
}