dialogContents example

/** * Tests sending AJAX requests to open and manipulate off-canvas dialog. * * @dataProvider dialogPosition */
  public function testDialog($position) {
    // Ensure the elements render without notices or exceptions.     $this->drupalGet('ajax-test/dialog');

    // Set up variables for this test.     $dialog_renderable = AjaxTestController::dialogContents();
    $dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);
    $off_canvas_expected_response = [
      'command' => 'openDialog',
      'selector' => '#drupal-off-canvas',
      'settings' => NULL,
      'data' => (string) $dialog_contents,
      'dialogOptions' =>
        [
          'title' => 'AJAX Dialog & contents',
          'modal' => FALSE,
          'autoResize' => FALSE,
          
/** * Util to render dialog in ajax callback. * * @param bool $is_modal * (optional) TRUE if modal, FALSE if plain dialog. Defaults to FALSE. * * @return \Drupal\Core\Ajax\AjaxResponse * An ajax response object. */
  protected function dialog($is_modal = FALSE) {
    $content = AjaxTestController::dialogContents();
    $response = new AjaxResponse();
    $title = $this->t('AJAX Dialog & contents');

    // Attach the library necessary for using the Open(Modal)DialogCommand and     // set the attachments for this Ajax response.     $content['#attached']['library'][] = 'core/drupal.dialog.ajax';

    if ($is_modal) {
      $response->addCommand(new OpenModalDialogCommand($title$content));
    }
    else {
      
protected $defaultTheme = 'stark';

  /** * Tests sending non-JS and AJAX requests to open and manipulate modals. */
  public function testDialog() {
    $this->drupalLogin($this->drupalCreateUser(['administer contact forms']));
    // Ensure the elements render without notices or exceptions.     $this->drupalGet('ajax-test/dialog');

    // Set up variables for this test.     $dialog_renderable = AjaxTestController::dialogContents();
    $dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);

    // Check that requesting a modal dialog without JS goes to a page.     $this->drupalGet('ajax-test/dialog-contents');
    $this->assertSession()->responseContains($dialog_contents);

    // Visit the page containing the many test dialog links.     $this->drupalGet('ajax-test/dialog');

    // Tests a basic modal dialog by verifying the contents of the dialog are as     // expected.
Home | Imprint | This part of the site doesn't use cookies.