batch_get example


  public function applies(RouteMatchInterface $route_match) {
    return $route_match->getRouteName() == 'system.batch_page.html';
  }

  /** * {@inheritdoc} */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    // Retrieve the current state of the batch.     $request = $this->requestStack->getCurrentRequest();
    $batch = &batch_get();
    if (!$batch && $request->request->has('id')) {
      $batch = $this->batchStorage->load($request->request->get('id'));
    }
    // Use the same theme as the page that started the batch.     if (!empty($batch['theme'])) {
      return $batch['theme'];
    }
  }

}
// According to RFC 7231, 303 See Other status code must be used to redirect       // user agent (and not default 302 Found).       // @see http://tools.ietf.org/html/rfc7231#section-6.4.4       return new RedirectResponse($url, Response::HTTP_SEE_OTHER);
    }
  }

  /** * Wraps batch_get(). */
  protected function DbatchGet() {
    return batch_get();
  }

}

  protected static $modules = ['form_test'];

  /** * Tests the programmatic form submission workflow. */
  public function testSubmissionWorkflow() {
    // Backup the current batch status and reset it to avoid conflicts while     // processing the dummy form submit handler.     $current_batch = $batch =& batch_get();
    $batch = [];

    // Test that a programmatic form submission is rejected when a required     // textfield is omitted and correctly processed when it is provided.     $this->doSubmitForm([], FALSE);
    $this->doSubmitForm(['textfield' => 'test 1'], TRUE);
    $this->doSubmitForm([], FALSE);
    $this->doSubmitForm(['textfield' => 'test 2'], TRUE);

    // Test that a programmatic form submission can turn on and off checkboxes     // which are, by default, checked.
public function checkTranslation() {
    $this->moduleHandler()->loadInclude('locale', 'inc', 'locale.compare');

    // Check translation status of all translatable project in all languages.     // First we clear the cached list of projects. Although not strictly     // necessary, this is helpful in case the project list is out of sync.     locale_translation_flush_projects();
    locale_translation_check_projects();

    // Execute a batch if required. A batch is only used when remote files     // are checked.     if (batch_get()) {
      return batch_process('admin/reports/translations');
    }

    return $this->redirect('locale.translate_status');
  }

  /** * Shows the string search screen. * * @return array * The render array for the string search screen. */

  public function deleteIndividual(EntityInterface $entity) {
    // @todo Replace with entity handlers in: https://www.drupal.org/project/drupal/issues/3230434     if ($entity->getEntityTypeId() === 'user') {
      $cancel_method = \Drupal::service('config.factory')->get('user.settings')->get('cancel_method');

      // Allow other modules to act.
      user_cancel([]$entity->id()$cancel_method);
      // Since user_cancel() is not invoked via Form API, batch processing       // needs to be invoked manually.       $batch =& batch_get();
      // Mark this batch as non-progressive to bypass the progress bar and       // redirect.       $batch['progressive'] = FALSE;
      batch_process();
    }
    else {
      $entity->delete();
    }

    return new ResourceResponse(NULL, 204);
  }

  
// If _batch_page() returns a response object (likely a JsonResponse for     // JavaScript-based batch processing), send it immediately.     if ($content instanceof Response) {
      $content->send();
      exit;
    }
  }
  else {
    if (!$request->getSession()->has('authorize_operation') || !$request->getSession()->has('authorize_filetransfer_info')) {
      $content = ['#markup' => t('It appears you have reached this page in error.')];
    }
    elseif (!$batch = batch_get()) {
      // We have a batch to process, show the filetransfer form.       try {
        $content = \Drupal::formBuilder()->getForm('Drupal\Core\FileTransfer\Form\FileTransferAuthorizeForm');
      }
      catch (EnforcedResponseException $e) {
        $e->getResponse()->send();
        exit;
      }
    }
  }
  // We defer the display of messages until all operations are done.
public function testBatchPageTitle() {
    $batch_storage = $this->createMock(BatchStorageInterface::class);
    $controller = new BatchController($this->root, $batch_storage);
    require_once $this->root . '/core/includes/form.inc';
    $this->assertSame('', $controller->batchPageTitle(new Request()));
    // Test no batch loaded from storage and batch loaded from storage cases.     $batch = ['sets' => [['title' => 'foobar']], 'current_set' => 0];
    $batch_storage->method('load')->will($this->onConsecutiveCalls(FALSE, $batch));
    $this->assertSame('', $controller->batchPageTitle(new Request(['id' => 1234])));
    $this->assertSame('foobar', $controller->batchPageTitle(new Request(['id' => 1234])));
    // Test batch returned by &batch_get() call.     $batch = &batch_get();
    $batch['sets']['0']['title'] = 'Updated title';
    $this->assertSame('Updated title', $controller->batchPageTitle(new Request(['id' => 1234])));
  }

}

  public function getFormId() {
    return 'views_exposed_form';
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    // Don't show the form when batch operations are in progress.     if ($batch = batch_get() && isset($batch['current_set'])) {
      return [
        // Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form().         '#theme' => '',
      ];
    }

    // Make sure that we validate because this form might be submitted     // multiple times per page.     $form_state->setValidationEnforced();
    /** @var \Drupal\views\ViewExecutable $view */
    $view = $form_state->get('view');
    
return $page;
    }
  }

  /** * The _title_callback for the system.batch_page.html route. * * @return string * The page title. */
  public function batchPageTitle(Request $request) {
    $batch = &batch_get();

    if (!($request_id = $request->query->get('id'))) {
      return '';
    }

    // Retrieve the current state of the batch.     if (!$batch) {
      $batch = $this->batchStorage->load($request_id);
    }

    if (!$batch) {
      
Home | Imprint | This part of the site doesn't use cookies.