abstract class ViewsFormBase implements ViewsFormInterface {
protected $id;
protected $type;
protected function setID($id) {
if ($id) {
$this->id = $id;
}
}
protected function setType($type) {
if ($type) {
$this->type = $type;
}
}
public function getFormState(ViewStorageInterface $view, $display_id, $js) {
$ajax = is_string($js) ? $js === 'ajax' : $js;
return array(
'form_id' => $this
->getFormID(),
'form_key' => $this
->getFormKey(),
'ajax' => $ajax,
'display_id' => $display_id,
'view' => $view,
'type' => $this->type,
'id' => $this->id,
'no_redirect' => TRUE,
'build_info' => array(
'args' => array(),
'callback_object' => $this,
),
);
}
public function getForm(ViewStorageInterface $view, $display_id, $js) {
$form_state = $this
->getFormState($view, $display_id, $js);
$view = $form_state['view'];
$key = $form_state['form_key'];
\Drupal::moduleHandler()
->loadInclude('views_ui', 'inc', 'admin');
\Drupal::moduleHandler()
->loadInclude('views', 'inc', 'includes/ajax');
$seen_ids_init =& drupal_static('drupal_html_id:init');
$seen_ids_init = array();
if (!empty($view->stack)) {
$identifier = implode('-', array_filter(array(
$key,
$view
->id(),
$display_id,
$form_state['type'],
$form_state['id'],
)));
reset($view->stack);
list($key, $top) = each($view->stack);
unset($view->stack[$key]);
if (array_shift($top) != $identifier) {
$view->stack = array();
}
}
if (isset($view->form_cache) && $view->form_cache['key'] != $key) {
unset($view->form_cache);
}
$drupal_add_js_original = drupal_add_js();
$drupal_add_js =& drupal_static('drupal_add_js');
$response = views_ajax_form_wrapper($form_state['form_id'], $form_state);
if (!$form_state['submitted'] || !empty($form_state['rerender'])) {
return $response;
}
if (!empty($view->stack)) {
$drupal_add_js = $drupal_add_js_original;
$stack = $view->stack;
$top = array_shift($stack);
$reflection = new \ReflectionClass($view::$forms[$top[1]]);
$form_state = $reflection
->newInstanceArgs(array_slice($top, 3, 2))
->getFormState($view, $top[2], $form_state['ajax']);
$form_state['input'] = array();
$form_url = views_ui_build_form_url($form_state);
if (!$form_state['ajax']) {
return new RedirectResponse(url($form_url, array(
'absolute' => TRUE,
)));
}
$form_state['url'] = url($form_url);
$response = views_ajax_form_wrapper($form_state['form_id'], $form_state);
}
elseif (!$form_state['ajax']) {
return new RedirectResponse(url("admin/structure/views/view/{$view->id()}/edit/{$form_state['display_id']}", array(
'absolute' => TRUE,
)));
}
else {
$response = new AjaxResponse();
$response
->addCommand(new Ajax\DismissFormCommand());
$response
->addCommand(new Ajax\ShowButtonsCommand());
$response
->addCommand(new Ajax\TriggerPreviewCommand());
if (!empty($form_state['#page_title'])) {
$response
->addCommand(new Ajax\ReplaceTitleCommand($form_state['#page_title']));
}
}
if ($display_id !== '') {
\Drupal::entityManager()
->getFormController('view', 'edit')
->rebuildCurrentTab($view, $response, $display_id);
}
return $response;
}
public function validateForm(array &$form, array &$form_state) {
}
public function submitForm(array &$form, array &$form_state) {
}
}