Commit 32eb0bc9 authored by webchick's avatar webchick
Browse files

Issue #1987624 by disasm, robeano, piyuesh23, dawehner | vijaycs85: Convert...

Issue #1987624 by disasm, robeano, piyuesh23, dawehner | vijaycs85: Convert batch_test() page callbacks to a new style controller.
parent de067341
......@@ -44,50 +44,34 @@ function batch_test_menu() {
// Programmatic form: the page submits the 'Chained' form through
// drupal_form_submit().
$items['batch-test/programmatic'] = array(
'title' => 'Programmatic',
'page callback' => 'batch_test_programmatic',
'access callback' => TRUE,
'route_name' => 'batch_test_programmatic',
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
// No form: fire a batch simply by accessing a page.
$items['batch-test/no-form'] = array(
'title' => 'Simple page',
'page callback' => 'batch_test_no_form',
'access callback' => TRUE,
'route_name' => 'batch_test_no_form',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
// No form: fire a batch; return > 100% complete
$items['batch-test/large-percentage'] = array(
'title' => 'Simple page with batch over 100% complete',
'page callback' => 'batch_test_large_percentage',
'access callback' => TRUE,
'route_name' => 'batch_test_large_percentage',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
// Tests programmatic form submission within a batch operation.
$items['batch-test/nested-programmatic'] = array(
'title' => 'Nested programmatic',
'page callback' => 'batch_test_nested_drupal_form_submit',
'access callback' => TRUE,
'route_name' => 'batch_test_nested_programmatic',
'type' => MENU_LOCAL_TASK,
'weight' => 6,
);
// Landing page to test redirects.
$items['batch-test/redirect'] = array(
'title' => 'Redirect',
'page callback' => 'batch_test_redirect_page',
'access callback' => TRUE,
'route_name' => 'batch_test_redirect',
'type' => MENU_LOCAL_TASK,
'weight' => 7,
);
// This item lives under 'admin' so that the page uses the admin theme.
$items['admin/batch-test/test-theme'] = array(
'page callback' => 'batch_test_theme_batch',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
......@@ -274,29 +258,6 @@ function batch_test_chained_form_submit_4($form, &$form_state) {
$form_state['redirect'] = 'batch-test/redirect';
}
/**
* Menu callback: Submits the 'Chained' form programmatically.
*/
function batch_test_programmatic($value = 1) {
$form_state = array(
'values' => array('value' => $value)
);
drupal_form_submit('batch_test_chained_form', $form_state);
return 'Got out of a programmatic batched form.';
}
/**
* Menu callback: Submits a form within a batch programmatically.
*/
function batch_test_nested_drupal_form_submit($value = 1) {
// Set the batch and process it.
$batch['operations'] = array(
array('_batch_test_nested_drupal_form_submit_callback', array($value)),
);
batch_set($batch);
return batch_process('batch-test/redirect');
}
/**
* Batch operation: Submits form_test_mock_form() using drupal_form_submit().
*/
......@@ -332,33 +293,6 @@ function batch_test_mock_form_submit($form, &$form_state) {
batch_test_stack('mock form submitted with value = ' . $form_state['values']['test_value']);
}
/**
* Menu callback: Fires a batch process without a form submission.
*/
function batch_test_no_form() {
batch_test_stack(NULL, TRUE);
batch_set(_batch_test_batch_1());
return batch_process('batch-test/redirect');
}
/**
* Menu callback: Fires a batch process without a form submission.
*/
function batch_test_large_percentage() {
batch_test_stack(NULL, TRUE);
batch_set(_batch_test_batch_5());
return batch_process('batch-test/redirect');
}
/**
* Menu callback: Redirects successfuly.
*/
function batch_test_redirect_page() {
return 'Redirection successful.';
}
/**
* Batch 0: Does nothing.
*/
......@@ -496,20 +430,6 @@ function _batch_test_batch_5() {
return $batch;
}
/**
* Menu callback: Runs a batch for testing theme used on the progress page.
*/
function batch_test_theme_batch() {
batch_test_stack(NULL, TRUE);
$batch = array(
'operations' => array(
array('_batch_test_theme_callback', array()),
),
);
batch_set($batch);
return batch_process('batch-test/redirect');
}
/**
* Tests the progress page theme by performing a batch callback.
*/
......
batch_test_redirect:
pattern: '/batch-test/redirect'
defaults:
_content: '\Drupal\batch_test\Controller\BatchTestController::testRedirect'
_title: 'Redirect'
requirements:
_access: 'TRUE'
batch_test_large_percentage:
pattern: '/batch-test/large-percentage'
defaults:
_content: '\Drupal\batch_test\Controller\BatchTestController::testLargePercentage'
_title: 'Simple page with batch over 100% complete'
requirements:
_access: 'TRUE'
batch_test_nested_programmatic:
pattern: '/batch-test/nested-programmatic/{value}'
defaults:
_content: '\Drupal\batch_test\Controller\BatchTestController::testNestedDrupalFormSubmit'
_title: 'Nested programmatic'
value: '1'
requirements:
_access: 'TRUE'
batch_test_no_form:
pattern: '/batch-test/no-form'
defaults:
_content: '\Drupal\batch_test\Controller\BatchTestController::testNoForm'
_title: 'Simple page'
requirements:
_access: 'TRUE'
batch_test_programmatic:
pattern: '/batch-test/programmatic/{value}'
defaults:
_content: '\Drupal\batch_test\Controller\BatchTestController::testProgrammatic'
_title: 'Programmatic'
value: '1'
requirements:
_access: 'TRUE'
batch_test_test_theme:
pattern: '/admin/batch-test/test-theme'
defaults:
_content: '\Drupal\batch_test\Controller\BatchTestController::testThemeBatch'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\batch_test\Controller\BatchTestController.
*/
namespace Drupal\batch_test\Controller;
/**
* Controller routines for batch tests.
*/
class BatchTestController {
/**
* Redirects successfuly.
*
* @return array
* Render array containing success message.
*/
public function testRedirect() {
return array(
'success' => array(
'#type' => 'markup',
'#markup' => 'Redirection successful.',
)
);
}
/**
* Fires a batch process without a form submission.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|null
* A redirect response if the batch is progressive. No return value otherwise.
*/
public function testLargePercentage() {
batch_test_stack(NULL, TRUE);
batch_set(_batch_test_batch_5());
return batch_process('batch-test/redirect');
}
/**
* Submits a form within a batch programmatically.
*
* @param int $value
* Some value passed to a custom batch callback.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|null
* A redirect response if the batch is progressive. No return value otherwise.
*/
public function testNestedDrupalFormSubmit($value = 1) {
// Set the batch and process it.
$batch['operations'] = array(
array('_batch_test_nested_drupal_form_submit_callback', array($value)),
);
batch_set($batch);
return batch_process('batch-test/redirect');
}
/**
* Fires a batch process without a form submission.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|null
* A redirect response if the batch is progressive. No return value otherwise.
*/
public function testNoForm() {
batch_test_stack(NULL, TRUE);
batch_set(_batch_test_batch_1());
return batch_process('batch-test/redirect');
}
/**
* Submits the 'Chained' form programmatically.
*
* Programmatic form: the page submits the 'Chained' form through
* drupal_form_submit().
*
* @param int $value
* Some value passed to a the chained form.
*
* @return array
* Render array containing markup.
*/
function testProgrammatic($value = 1) {
$form_state = array(
'values' => array('value' => $value)
);
drupal_form_submit('batch_test_chained_form', $form_state);
return array(
'success' => array(
'#type' => 'markup',
'#markup' => 'Got out of a programmatic batched form.',
)
);
}
/**
* Runs a batch for testing theme used on the progress page.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse|null
* A redirect response if the batch is progressive. No return value otherwise.
*/
public function testThemeBatch() {
batch_test_stack(NULL, TRUE);
$batch = array(
'operations' => array(
array('_batch_test_theme_callback', array()),
),
);
batch_set($batch);
return batch_process('batch-test/redirect');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment