Overrides Drupal\Core\Entity\EntityFormController::form().
Overrides EntityFormController::form
public function form(array $form, array &$form_state) {
$view = $this->entity;
$display_id = $this->displayID;
// Do not allow the form to be cached, because $form_state['view'] can become
// stale between page requests.
// See views_ui_ajax_get_form() for how this affects #ajax.
// @todo To remove this and allow the form to be cacheable:
// - Change $form_state['view'] to $form_state['temporary']['view'].
// - Add a #process function to initialize $form_state['temporary']['view']
// on cached form submissions.
// - Use form_load_include().
$form_state['no_cache'] = TRUE;
if ($display_id) {
if (!$view
->get('executable')
->setDisplay($display_id)) {
$form['#markup'] = t('Invalid display id @display', array(
'@display' => $display_id,
));
return $form;
}
}
$form['#tree'] = TRUE;
$form['#attached']['library'][] = array(
'system',
'jquery.ui.tabs',
);
$form['#attached']['library'][] = array(
'system',
'jquery.ui.dialog',
);
$form['#attached']['library'][] = array(
'system',
'drupal.states',
);
$form['#attached']['library'][] = array(
'system',
'drupal.tabledrag',
);
if (!config('views.settings')
->get('no_javascript')) {
$form['#attached']['library'][] = array(
'views_ui',
'views_ui.admin',
);
}
$form['#attached']['css'] = static::getAdminCSS();
$form['#attached']['js'][] = array(
'data' => array(
'views' => array(
'ajax' => array(
'id' => '#views-ajax-body',
'title' => '#views-ajax-title',
'popup' => '#views-ajax-popup',
'defaultForm' => $view
->getDefaultAJAXMessage(),
),
),
),
'type' => 'setting',
);
$form += array(
'#prefix' => '',
'#suffix' => '',
);
$view_status = $view
->status() ? 'enabled' : 'disabled';
$form['#prefix'] .= '<div class="views-edit-view views-admin ' . $view_status . ' clearfix">';
$form['#suffix'] = '</div>' . $form['#suffix'];
$form['#attributes']['class'] = array(
'form-edit',
);
if ($view
->isLocked()) {
$form['locked'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'view-locked',
'messages',
'messages--warning',
),
),
'#children' => t('This view is being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to <a href="!break">break this lock</a>.', array(
'!user' => theme('username', array(
'account' => user_load($view->lock->owner),
)),
'!age' => format_interval(REQUEST_TIME - $view->lock->updated),
'!break' => url('admin/structure/views/view/' . $view
->id() . '/break-lock'),
)),
'#weight' => -10,
);
}
else {
$form['changed'] = array(
'#type' => 'container',
'#attributes' => array(
'class' => array(
'view-changed',
'messages',
'messages--warning',
),
),
'#children' => t('You have unsaved changes.'),
'#weight' => -10,
);
if (empty($view->changed)) {
$form['changed']['#attributes']['class'][] = 'js-hide';
}
}
$form['displays'] = array(
'#prefix' => '<h1 class="unit-title clearfix">' . t('Displays') . '</h1>',
'#type' => 'container',
'#attributes' => array(
'class' => array(
'views-displays',
),
),
);
$form['displays']['top'] = $this
->renderDisplayTop($view);
// The rest requires a display to be selected.
if ($display_id) {
$form_state['display_id'] = $display_id;
// The part of the page where editing will take place.
$form['displays']['settings'] = array(
'#type' => 'container',
'#id' => 'edit-display-settings',
);
$display_title = $this
->getDisplayLabel($view, $display_id, FALSE);
// Add a text that the display is disabled.
if ($view
->get('executable')->displayHandlers
->has($display_id)) {
if (!$view
->get('executable')->displayHandlers
->get($display_id)
->isEnabled()) {
$form['displays']['settings']['disabled']['#markup'] = t('This display is disabled.');
}
}
// Add the edit display content
$tab_content = $this
->getDisplayTab($view);
$tab_content['#theme_wrappers'] = array(
'container',
);
$tab_content['#attributes'] = array(
'class' => array(
'views-display-tab',
),
);
$tab_content['#id'] = 'views-tab-' . $display_id;
// Mark deleted displays as such.
$display = $view
->get('display');
if (!empty($display[$display_id]['deleted'])) {
$tab_content['#attributes']['class'][] = 'views-display-deleted';
}
// Mark disabled displays as such.
if ($view
->get('executable')->displayHandlers
->has($display_id) && !$view
->get('executable')->displayHandlers
->get($display_id)
->isEnabled()) {
$tab_content['#attributes']['class'][] = 'views-display-disabled';
}
$form['displays']['settings']['settings_content'] = array(
'#type' => 'container',
'tab_content' => $tab_content,
);
// The content of the popup dialog.
$form['ajax-area'] = array(
'#type' => 'container',
'#id' => 'views-ajax-popup',
);
$form['ajax-area']['ajax-title'] = array(
'#markup' => '<h2 id="views-ajax-title"></h2>',
);
$form['ajax-area']['ajax-body'] = array(
'#type' => 'container',
'#id' => 'views-ajax-body',
'#children' => $view
->getDefaultAJAXMessage(),
);
}
return $form;
}