ViewEditForm::renderDisplayTop

public ViewEditForm::renderDisplayTop(ViewUI $view)

Render the top of the display so it can be updated during ajax operations.

File

core/modules/views_ui/src/ViewEditForm.php, line 672

Class

ViewEditForm
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

public function renderDisplayTop(ViewUI $view) {
  $display_id = $this->displayID;
  $element['#theme_wrappers'][] = 'views_ui_container';
  $element['#attributes']['class'] = array('views-display-top', 'clearfix');
  $element['#attributes']['id'] = array('views-display-top');

  // Extra actions for the display
  $element['extra_actions'] = array(
    '#type' => 'dropbutton',
    '#attributes' => array(
      'id' => 'views-display-extra-actions',
    ),
    '#links' => array(
      'edit-details' => array(
        'title' => $this->t('Edit view name/description'),
        'url' => Url::fromRoute('views_ui.form_edit_details', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]),
        'attributes' => array('class' => array('views-ajax-link')),
      ),
      'analyze' => array(
        'title' => $this->t('Analyze view'),
        'url' => Url::fromRoute('views_ui.form_analyze', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]),
        'attributes' => array('class' => array('views-ajax-link')),
      ),
      'duplicate' => array(
        'title' => $this->t('Duplicate view'),
        'url' => $view->urlInfo('duplicate-form'),
      ),
      'reorder' => array(
        'title' => $this->t('Reorder displays'),
        'url' => Url::fromRoute('views_ui.form_reorder_displays', ['js' => 'nojs', 'view' => $view->id(), 'display_id' => $display_id]),
        'attributes' => array('class' => array('views-ajax-link')),
      ),
    ),
  );

  if ($view->access('delete')) {
    $element['extra_actions']['#links']['delete'] = array(
      'title' => $this->t('Delete view'),
      'url' => $view->urlInfo('delete-form'),
    );
  }

  // Let other modules add additional links here.
  \Drupal::moduleHandler()->alter('views_ui_display_top_links', $element['extra_actions']['#links'], $view, $display_id);

  if (isset($view->type) && $view->type != $this->t('Default')) {
    if ($view->type == $this->t('Overridden')) {
      $element['extra_actions']['#links']['revert'] = array(
        'title' => $this->t('Revert view'),
        'href' => "admin/structure/views/view/{$view->id()}/revert",
        'query' => array('destination' => $view->url('edit-form')),
      );
    }
    else {
      $element['extra_actions']['#links']['delete'] = array(
        'title' => $this->t('Delete view'),
        'url' => $view->urlInfo('delete-form'),
      );
    }
  }

  // Determine the displays available for editing.
  if ($tabs = $this->getDisplayTabs($view)) {
    if ($display_id) {
      $tabs[$display_id]['#active'] = TRUE;
    }
    $tabs['#prefix'] = '<h2 class="visually-hidden">' . $this->t('Secondary tabs') . '</h2><ul id = "views-display-menu-tabs" class="tabs secondary">';
    $tabs['#suffix'] = '</ul>';
    $element['tabs'] = $tabs;
  }

  // Buttons for adding a new display.
  foreach (Views::fetchPluginNames('display', NULL, array($view->get('base_table'))) as $type => $label) {
    $element['add_display'][$type] = array(
      '#type' => 'submit',
      '#value' => $this->t('Add @display', array('@display' => $label)),
      '#limit_validation_errors' => array(),
      '#submit' => array('::submitDisplayAdd', '::submitDelayDestination'),
      '#attributes' => array('class' => array('add-display')),
      // Allow JavaScript to remove the 'Add ' prefix from the button label when
      // placing the button in a "Add" dropdown menu.
      '#process' => array_merge(array('views_ui_form_button_was_clicked'), $this->elementInfo->getInfoProperty('submit', '#process', array())),
      '#values' => array($this->t('Add @display', array('@display' => $label)), $label),
    );
  }

  return $element;
}
doc_Drupal
2016-10-29 09:53:59
Comments
Leave a Comment

Please login to continue.