OpenDialogCommand example

'settings' => ['key' => 'value'],
      'merge' => TRUE,
    ];

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

  /** * @covers \Drupal\Core\Ajax\OpenDialogCommand */
  public function testOpenDialogCommand() {
    $command = new OpenDialogCommand('#some-dialog', 'Title', '<p>Text!</p>', [
      'url' => FALSE,
      'width' => 500,
    ]);

    $expected = [
      'command' => 'openDialog',
      'selector' => '#some-dialog',
      'settings' => NULL,
      'data' => '<p>Text!</p>',
      'dialogOptions' => [
        'url' => FALSE,
        
    $main_content['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $response->setAttachments($main_content['#attached']);

    // Determine the title: use the title provided by the main content if any,     // otherwise get it from the routing information.     $title = $main_content['#title'] ?? $this->titleResolver->getTitle($request$route_match->getRouteObject());

    // Determine the dialog options and the target for the OpenDialogCommand.     $options = $request->request->all('dialogOptions');
    $target = $this->determineTargetSelector($options$route_match);

    $response->addCommand(new OpenDialogCommand($target$title$content$options));
    return $response;
  }

  /** * Determine the target selector for the OpenDialogCommand. * * @param array &$options * The 'target' option, if set, is used, and then removed from $options. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * When no 'target' option is set in $options, $route_match is used instead * to determine the target. * * @return string * The target selector. */
$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 {
      $selector = '#ajax-test-dialog-wrapper-1';
      $response->addCommand(new OpenDialogCommand($selector$title$content));
    }
    return $response;
  }

}
Home | Imprint | This part of the site doesn't use cookies.