Drupal 8: Cómo redirigir a la forma del lote después de someterse a URL personalizada (api lotes)

He estado luchando con esto durante mucho tiempo, pero luego me encontré solución simple.

Necesitaba volver a dirigir a la nueva página de procesamiento por lotes inmediatamente después de pulsar el botón Enviar asi que aquí hay una solución

public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setRedirectUrl(Url::fromUri())
    $identity = isset($form_state->getTriggeringElement()['#identity']) ? $form_state->getTriggeringElement()['#identity'] : 'unknown';
    switch ($identity) {
      case static::BTN_UPDATE;
        $batch = [
          'title' => t('Updating'),
          'operations' => [
            array('sfo_common_batch_callbacks__taxonomy_update_cache_process', [[]]),
          ],
          'finished' => 'sfo_common_batch_callbacks__taxonomy_update_cache_finished',
          'file' => drupal_get_path('module', 'sfo_common') . '/include/batch/sfo_common.taxonomy_cache.inc',
        ];

        batch_set($batch);
        $request =  batch_process(static::URL_REDIRECT);
        return $request->send();
        break;
      default:
        drupal_set_message(t('Incorrect operation'));
        break;
    }
  }

Este es el caso de uso que encontré. Pero esto es sólo funciona muy bien para lotes. Si necesita volver a dirigir después de presentar la forma también es posible utilizar

public function submitForm(array &$form, FormStateInterface $form_state) {
  $form_state->setRedirect(taxonomy.vocabulary.collection); // Here need to pass route name from *.routes.yml file

  //But if you need to redirect to custom url
  $form_state->setRedirectUrl(Url::fromUri('http://google.com')); // Need to pass Drupal\Core\Url object here
}

Otras formas de redirigir https://www.drupal.org/node/2023537

Cargando

Esta entrada fue publicada en Nets, PHP, WEB, Internet, Computadoras, software, Programación y etiquetado , , , . Marcar el permalink. | Enlace corto:  http://p1rat.ru/lezzz/5KbGG

Deja una respuesta