RedirectCommand example

'optionName' => 'title',
      'optionValue' => 'Example',
    ];

    $this->assertEquals($expected$command->render());
  }

  /** * @covers \Drupal\Core\Ajax\RedirectCommand */
  public function testRedirectCommand() {
    $command = new RedirectCommand('http://example.com');
    $expected = [
      'command' => 'redirect',
      'url' => 'http://example.com',
    ];

    $this->assertEquals($expected$command->render());
  }

  /** * @covers \Drupal\Core\Ajax\UpdateBuildIdCommand */
  
    // fixed.     $form['#id'] = Html::getId($form_state->getBuildInfo()['form_id']);

    return $form;
  }

  /** * {@inheritdoc} */
  protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
    if ($redirect_url = $this->getRedirectUrl()) {
      $command = new RedirectCommand($redirect_url->setAbsolute()->toString());
    }
    else {
      // Settings Tray always provides a destination.       throw new \Exception("No destination provided by Settings Tray form");
    }
    $response = new AjaxResponse();
    return $response->addCommand($command);
  }

  /** * Gets the form's redirect URL from 'destination' provide in the request. * * @return \Drupal\Core\Url|null * The redirect URL or NULL if dialog should just be closed. */
Home | Imprint | This part of the site doesn't use cookies.