batch_test_stack example

/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  }

  /** * Form submission handler #1 for batch_test_chained_form. */
  public static function batchTestChainedFormSubmit1($form, FormStateInterface $form_state) {
    batch_test_stack(NULL, TRUE);

    batch_test_stack('submit handler 1');
    batch_test_stack('value = ' . $form_state->getValue('value'));

    $value = &$form_state->getValue('value');
    $value++;
    batch_set(_batch_test_batch_1());

    $form_state->setRedirect('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 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. */
'#type' => 'submit',
      '#value' => t('Submit'),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    batch_test_stack('mock form submitted with value = ' . $form_state->getValue('test_value'));
  }

}
    // step to the next via POST requests, but via GET requests, because it uses     // Batch API to advance through the steps.     $form['#cache']['max-age'] = 0;

    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    batch_test_stack(NULL, TRUE);

    $step = $form_state->get('step');
    switch ($step) {
      case 1:
        batch_set(_batch_test_batch_1());
        break;

      case 2:
        batch_set(_batch_test_batch_2());
        break;
    }

    

  protected $defaultTheme = 'starterkit_theme';

  /** * Tests batches triggered outside of form submission. */
  public function testBatchNoForm() {
    // Displaying the page triggers batch 1.     $this->drupalGet('batch-test/no-form');
    $this->assertBatchMessages($this->_resultMessages('batch_1'));
    $this->assertEquals($this->_resultStack('batch_1')batch_test_stack(), 'Execution order was correct.');
    $this->assertSession()->pageTextContains('Redirection successful.');
  }

  /** * Tests batches that redirect in the batch finished callback. */
  public function testBatchRedirectFinishedCallback() {
    // Displaying the page triggers batch 1.     $this->drupalGet('batch-test/finish-redirect');
    $this->assertBatchMessages($this->_resultMessages('batch_1'));
    $this->assertEquals($this->_resultStack('batch_1')batch_test_stack(), 'Execution order was correct.');
    
'#type' => 'submit',
      '#value' => 'Submit',
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    batch_test_stack(NULL, TRUE);

    foreach ($form_state->getValue('batch') as $batch) {
      $function = '_batch_test_' . $batch;
      batch_set($function());
    }

    $form_state->setRedirect('batch_test.redirect');
  }

}
// Log in as an administrator who can see the administrative theme.     $admin_user = $this->drupalCreateUser(['view the administration theme']);
    $this->drupalLogin($admin_user);
    // Visit an administrative page that runs a test batch, and check that the     // theme that was used during batch execution (which the batch callback     // function saved as a variable) matches the theme used on the     // administrative page.     $this->drupalGet('admin/batch-test/test-theme');
    // The stack should contain the name of the theme used on the progress     // page.     $this->assertEquals(['claro']batch_test_stack(), 'A progressive batch correctly uses the theme of the page that started the batch.');
  }

  /** * Tests that the batch API progress page shows the title correctly. */
  public function testBatchProgressPageTitle() {
    // Visit an administrative page that runs a test batch, and check that the     // title shown during batch execution (which the batch callback function     // saved as a variable) matches the theme used on the administrative page.     // Run initial step only first.     $this->maximumMetaRefreshCount = 0;
    
Home | Imprint | This part of the site doesn't use cookies.