You are here

public function ViewUI::buildPreviewForm in Views (for Drupal 7) 8.3

Provide the preview formulas and the preview output, too.

File

views_ui/lib/Drupal/views_ui/ViewUI.php, line 1430
Definition of Drupal\views_ui\ViewUI.

Class

ViewUI
Stores UI related temporary settings.

Namespace

Drupal\views_ui

Code

public function buildPreviewForm($form, &$form_state, $display_id = 'default') {

  // Reset the cache of IDs. Drupal rather aggressively prevents ID
  // duplication but this causes it to remember IDs that are no longer even
  // being used.
  $seen_ids_init =& drupal_static('drupal_html_id:init');
  $seen_ids_init = array();
  $form_state['no_cache'] = TRUE;
  $form_state['view'] = $this;
  $form['#attributes'] = array(
    'class' => array(
      'clearfix',
    ),
  );

  // Add a checkbox controlling whether or not this display auto-previews.
  $form['live_preview'] = array(
    '#type' => 'checkbox',
    '#id' => 'edit-displays-live-preview',
    '#title' => t('Auto preview'),
    '#default_value' => config('views.settings')
      ->get('ui.always_live_preview'),
  );

  // Add the arguments textfield
  $form['view_args'] = array(
    '#type' => 'textfield',
    '#title' => t('Preview with contextual filters:'),
    '#description' => t('Separate contextual filter values with a "/". For example, %example.', array(
      '%example' => '40/12/10',
    )),
    '#id' => 'preview-args',
  );

  // Add the preview button
  $form['button'] = array(
    '#type' => 'submit',
    '#value' => t('Update preview'),
    '#attributes' => array(
      'class' => array(
        'arguments-preview',
      ),
    ),
    '#prefix' => '<div id="preview-submit-wrapper">',
    '#suffix' => '</div>',
    '#id' => 'preview-submit',
    '#ajax' => array(
      'path' => 'admin/structure/views/view/' . $this->storage->name . '/preview/' . $display_id . '/ajax',
      'wrapper' => 'views-preview-wrapper',
      'event' => 'click',
      'progress' => array(
        'type' => 'throbber',
      ),
      'method' => 'replace',
    ),
    // Make ENTER in arguments textfield (and other controls) submit the form
    // as this button, not the Save button.
    // @todo This only works for JS users. To make this work for nojs users,
    //   we may need to split Preview into a separate form.
    '#process' => array_merge(array(
      array(
        $this,
        'processDefaultButton',
      ),
    ), element_info_property('submit', '#process', array())),
  );
  $form['#action'] = url('admin/structure/views/view/' . $this->storage->name . '/preview/' . $display_id);
  return $form;
}