1 views_ui.admin.inc | views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) |
Form builder callback for configuring a View.
See also
File
- core/
modules/ views_ui/ views_ui.admin.inc, line 1016 - Admin page callbacks for the Views UI module.
Code
function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) {
// 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.
$form_state['no_cache'] = TRUE;
if ($display_id) {
if (!$view->set_display($display_id)) {
$form['#markup'] = t('Invalid display id @display', array('@display' => $display_id));
return $form;
}
$view->fix_missing_relationships();
}
$form['#tree'] = TRUE;
// @todo When more functionality is added to this form, cloning here may be
// too soon. But some of what we do with $view later in this function
// results in making it unserializable due to PDO limitations.
$form_state['view'] = clone($view);
$form['#attached']['library'][] = array('system', 'ui.tabs');
$form['#attached']['library'][] = array('system', 'ui.dialog');
$form['#attached']['library'][] = array('system', 'backdrop.ajax');
$form['#attached']['library'][] = array('system', 'jquery.form');
// TODO: This should be getting added to the page when an ajax popup calls
// for it, instead of having to add it manually here.
$form['#attached']['js'][] = 'core/misc/tabledrag.js';
$form['#attached']['css'] = views_ui_get_admin_css();
$module_path = backdrop_get_path('module', 'views_ui');
$form['#attached']['js'][] = $module_path . '/js/views-admin.js';
$form['#attached']['js'][] = array(
'data' => array('views' => array('ajax' => array(
'id' => '#views-ajax-body',
'title' => '#views-ajax-title',
'popup' => '#views-ajax-popup',
'defaultForm' => views_ui_get_default_ajax_message(),
))),
'type' => 'setting',
);
$form += array(
'#prefix' => '',
'#suffix' => '',
);
$form['#prefix'] = $form['#prefix'] . '<div class="views-edit-view views-admin clearfix">';
$form['#suffix'] = '</div>' . $form['#suffix'];
$form['#attributes']['class'] = array('form-edit');
if (isset($view->locked) && is_object($view->locked)) {
$form['locked'] = array(
'#theme_wrappers' => array('container'),
'#attributes' => array('class' => array('view-locked', 'messages', 'warning')),
'#markup' => t('This view is being configured by user !user, and is therefore locked from configuring 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->locked->uid))), '!age' => format_interval(REQUEST_TIME - $view->locked->updated), '!break' => url('admin/structure/views/view/' . $view->name . '/break-lock'))),
);
}
if (isset($view->vid) && $view->vid == 'new') {
$message = t('* All changes are stored temporarily. Click Save to make your changes permanent. Click Cancel to discard the view.');
}
else {
$message = t('* All changes are stored temporarily. Click Save to make your changes permanent. Click Cancel to discard your changes.');
}
$form['changed'] = array(
'#theme_wrappers' => array('container'),
'#attributes' => array('class' => array('view-changed', 'messages', 'warning')),
'#markup' => $message,
'#access' => empty($view->locked),
);
if (empty($view->changed)) {
$form['changed']['#attributes']['class'][] = 'js-hide';
}
$form['actions'] = array(
'#type' => 'actions',
'#weight' => 0,
'#access' => empty($view->locked),
);
$form['actions']['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
// Taken from the "old" UI. @TODO: Review and rename.
'#validate' => array('views_ui_edit_view_form_validate'),
'#submit' => array('views_ui_edit_view_form_submit'),
);
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel'),
'#submit' => array('views_ui_edit_view_form_cancel'),
);
$form['displays'] = array(
'#prefix' => '<h1 class="unit-title">' . t('Displays') . '</h1>' . "\n" . '<div class="views-displays">',
'#suffix' => '</div>',
);
$form['displays']['top'] = views_ui_render_display_top($view, $display_id);
// The rest requires a display to be selected.
if ($display_id) {
$form_state['display_id'] = $display_id;
// The part of the page where configuring will take place.
$form['displays']['settings'] = array(
'#theme_wrappers' => array('container'),
'#id' => 'edit-display-settings',
'#attributes' => array(),
);
// Add a text that the display is disabled.
if (!empty($view->display[$display_id]->handler)) {
$enabled = $view->display[$display_id]->handler->get_option('enabled');
if (empty($enabled)) {
$form['displays']['settings']['disabled']['#markup'] = t('This display is disabled.');
}
}
$form['displays']['settings']['settings_content'] = array(
'#theme_wrappers' => array('container'),
'#id' => 'edit-display-settings-content',
'#attributes' => array(),
);
// Add the configure display content
$form['displays']['settings']['settings_content']['tab_content'] = views_ui_get_display_tab($view, $display_id);
$form['displays']['settings']['settings_content']['tab_content']['#theme_wrappers'] = array('container');
$form['displays']['settings']['settings_content']['tab_content']['#attributes'] = array('class' => array('views-display-tab'));
$form['displays']['settings']['settings_content']['tab_content']['#id'] = 'views-tab-' . $display_id;
// Mark deleted displays as such.
if (!empty($view->display[$display_id]->deleted)) {
$form['displays']['settings']['settings_content']['tab_content']['#attributes']['class'][] = 'views-display-deleted';
}
// Mark disabled displays as such.
if (empty($enabled)) {
$form['displays']['settings']['settings_content']['tab_content']['#attributes']['class'][] = 'views-display-disabled';
}
// The content of the popup dialog.
$form['ajax-area'] = array(
'#theme_wrappers' => array('container'),
'#id' => 'views-ajax-popup',
'#attributes' => array(),
);
$form['ajax-area']['ajax-title'] = array(
'#markup' => '<h2 id="views-ajax-title"></h2>',
);
$form['ajax-area']['ajax-body'] = array(
'#theme_wrappers' => array('container'),
'#id' => 'views-ajax-body',
'#attributes' => array(),
'#markup' => views_ui_get_default_ajax_message(),
);
}
// If relationships had to be fixed, we want to get that into the cache
// so that configurations work properly, and to try to get the user to save it
// so that it's not using weird fixed up relationships.
if (!empty($view->relationships_changed) && empty($_POST)) {
backdrop_set_message(t('Missing relationships have been fixed automatically. Please verify these changes before saving.'));
views_ui_cache_set($view);
}
return $form;
}