setProgressMessage example

return $build;
  }

  /** * Manually checks the update status without the use of cron. */
  public function updateStatusManually() {
    $this->updateManager->refreshUpdateData();
    $batch_builder = (new BatchBuilder())
      ->setTitle(t('Checking available update data'))
      ->addOperation([$this->updateManager, 'fetchDataBatch'][])
      ->setProgressMessage(t('Trying to check available update data ...'))
      ->setErrorMessage(t('Error checking available update data.'))
      ->setFinishCallback('update_fetch_data_finished');
    batch_set($batch_builder->toArray());
    return batch_process('admin/reports/updates');
  }

}
return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config['source_base_path'] = $this->store->get('source_base_path');
    $config['source_private_file_path'] = $this->store->get('source_private_file_path');
    $batch_builder = (new BatchBuilder())
      ->setTitle($this->t('Running upgrade'))
      ->setProgressMessage('')
      ->addOperation([
        MigrateUpgradeImportBatch::class,
        'run',
      ][array_keys($this->migrations)$config])
      ->setFinishCallback([MigrateUpgradeImportBatch::class, 'finished']);
    batch_set($batch_builder->toArray());
    $form_state->setRedirect('<front>');
    $this->store->set('step', 'overview');
    $this->state->set('migrate_drupal_ui.performed', REQUEST_TIME);
  }

  
$this->assertEquals(new TranslatableMarkup('New initialization message.')$batch['init_message']);
  }

  /** * Tests setProgressMessage(). * * @covers ::setProgressMessage */
  public function testSetProgressMessage() {
    $batch = (new BatchBuilder())
      ->setProgressMessage(new TranslatableMarkup('Batch in progress...'))
      ->toArray();

    $this->assertEquals(new TranslatableMarkup('Batch in progress...')$batch['progress_message']);
  }

  /** * Tests setErrorMessage(). */
  public function testSetErrorMessage() {
    $batch = (new BatchBuilder())
      ->setErrorMessage(new TranslatableMarkup('Oops. An error has occurred :('))
      
$config_importer = $form_state->get('config_importer');
    if ($config_importer->alreadyImporting()) {
      $this->messenger()->addError($this->t('Another request may be importing configuration already.'));
    }
    else {
      try {
        $sync_steps = $config_importer->initialize();
        $batch_builder = (new BatchBuilder())
          ->setTitle($this->t('Importing configuration'))
          ->setFinishCallback([ConfigImporterBatch::class, 'finish'])
          ->setInitMessage($this->t('Starting configuration import.'))
          ->setProgressMessage($this->t('Completed @current step of @total.'))
          ->setErrorMessage($this->t('Configuration import has encountered an error.'));
        foreach ($sync_steps as $sync_step) {
          $batch_builder->addOperation([ConfigImporterBatch::class, 'process'][$config_importer$sync_step]);
        }
        batch_set($batch_builder->toArray());
      }
      catch (ConfigImporterException $e) {
        // There are validation errors.         $this->messenger()->addError($this->t('The configuration import failed for the following reasons:'));
        foreach ($config_importer->getErrors() as $message) {
          $this->messenger()->addError($message);
        }

    if ($config_importer->alreadyImporting()) {
      $this->messenger()->addStatus($this->t('Another request may be synchronizing configuration already.'));
    }
    else {
      try {
        $sync_steps = $config_importer->initialize();
        $batch_builder = (new BatchBuilder())
          ->setTitle($this->t('Synchronizing configuration'))
          ->setFinishCallback([ConfigImporterBatch::class, 'finish'])
          ->setInitMessage($this->t('Starting configuration synchronization.'))
          ->setProgressMessage($this->t('Completed step @current of @total.'))
          ->setErrorMessage($this->t('Configuration synchronization has encountered an error.'));
        foreach ($sync_steps as $sync_step) {
          $batch_builder->addOperation([ConfigImporterBatch::class, 'process'][$config_importer$sync_step]);
        }

        batch_set($batch_builder->toArray());
      }
      catch (ConfigImporterException $e) {
        // There are validation errors.         $this->messenger()->addError($this->t('The configuration cannot be imported because it failed validation for the following reasons:'));
        foreach ($config_importer->getErrors() as $message) {
          


  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $entity_type_id = $form_state->getValue('entity_type_id');

    $entity_type_plural = $this->entityTypeManager->getDefinition($entity_type_id)->getPluralLabel();
    $batch_builder = (new BatchBuilder())
      ->setTitle($this->t('Deleting @entity_type_plural', ['@entity_type_plural' => $entity_type_plural]))
      ->setProgressMessage('')
      ->setFinishCallback([__CLASS__, 'moduleBatchFinished'])
      ->addOperation([__CLASS__, 'deleteContentEntities'][$entity_type_id]);
    batch_set($batch_builder->toArray());
  }

  /** * Deletes the content entities of the specified entity type. * * @param string $entity_type_id * The entity type ID from which data will be deleted. * @param array|\ArrayAccess $context * The batch context array, passed by reference. * * @internal * This batch callback is only meant to be used by this form. */
Home | Imprint | This part of the site doesn't use cookies.