Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. OpenModalDialogWithUrl.php

class 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

  • class \Drupal\Core\Ajax\OpenModalDialogWithUrl implements \Drupal\Core\Ajax\CommandInterface

Expanded class hierarchy of OpenModalDialogWithUrl

See also

\Drupal\Core\Ajax\OpenDialogCommand

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.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal