class OpenModalDialogWithUrl

Same name in other branches
  1. 10 core/lib/Drupal/Core/Ajax/OpenModalDialogWithUrl.php \Drupal\Core\Ajax\OpenModalDialogWithUrl

Provides an AJAX command for opening a modal with URL.

OpenDialogCommand is a similar class which opens modals but works differently as it needs all data to be passed through dialogOptions while OpenModalDialogWithUrl fetches the data from routing info of the URL.

Hierarchy

Expanded class hierarchy of OpenModalDialogWithUrl

See also

\Drupal\Core\Ajax\OpenDialogCommand

2 files declare their use of OpenModalDialogWithUrl
AjaxTestDialogForm.php in core/modules/system/tests/modules/ajax_test/src/Form/AjaxTestDialogForm.php
DialogTest.php in core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php
1 string reference to 'OpenModalDialogWithUrl'
OpenModalDialogWithUrl::render in core/lib/Drupal/Core/Ajax/OpenModalDialogWithUrl.php
Return an array to be run through json_encode and sent to the client.

File

core/lib/Drupal/Core/Ajax/OpenModalDialogWithUrl.php, line 18

Namespace

Drupal\Core\Ajax
View source
class OpenModalDialogWithUrl implements CommandInterface {
    
    /**
     * Constructs a OpenModalDialogWithUrl object.
     *
     * @param string $url
     *   Only Internal URLs or URLs with the same domain and base path are
     *   allowed.
     * @param array $settings
     *   The dialog settings.
     */
    public function __construct(string $url, array $settings) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function render() {
        // @see \Drupal\Core\Routing\LocalAwareRedirectResponseTrait::isLocal()
        if (!UrlHelper::isExternal($this->url) || UrlHelper::externalIsLocal($this->url, $this->getBaseURL())) {
            return [
                'command' => 'openModalDialogWithUrl',
                'url' => $this->url,
                'dialogOptions' => $this->settings,
            ];
        }
        throw new \LogicException('External URLs are not allowed.');
    }
    
    /**
     * Gets the complete base URL.
     */
    private function getBaseUrl() {
        $requestContext = \Drupal::service('router.request_context');
        return $requestContext->getCompleteBaseUrl();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
OpenModalDialogWithUrl::getBaseUrl private function Gets the complete base URL.
OpenModalDialogWithUrl::render public function Return an array to be run through json_encode and sent to the client. Overrides CommandInterface::render
OpenModalDialogWithUrl::__construct public function Constructs a OpenModalDialogWithUrl object.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.