transformRootRelativeUrlsToAbsolute example

public function testSerialize() {
    $document = new \DOMDocument();
    $result = Html::serialize($document);
    $this->assertSame('', $result);
  }

  /** * @covers ::transformRootRelativeUrlsToAbsolute * @dataProvider providerTestTransformRootRelativeUrlsToAbsolute */
  public function testTransformRootRelativeUrlsToAbsolute($html$scheme_and_host$expected_html) {
    $this->assertSame($expected_html ?: $html, Html::transformRootRelativeUrlsToAbsolute($html$scheme_and_host));
  }

  /** * @covers ::transformRootRelativeUrlsToAbsolute * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion */
  public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) {
    $this->expectException(\AssertionError::class);
    Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host);
  }

  

  public function onResponse(ResponseEvent $event) {
    // Only care about RSS responses.     if (stripos($event->getResponse()->headers->get('Content-Type', ''), 'application/rss+xml') === FALSE) {
      return;
    }

    $response = $event->getResponse();
    $response->setContent($this->transformRootRelativeUrlsToAbsolute($response->getContent()$event->getRequest()));
  }

  /** * Converts all root-relative URLs to absolute URLs in RSS markup. * * Does not change any existing protocol-relative or absolute URLs. * * @param string $rss_markup * The RSS markup to update. * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @return string * The updated RSS markup. */
// Invoke hook_mail_alter() to allow all modules to alter the resulting     // email.     $this->moduleHandler->alter('mail', $message);

    // Retrieve the responsible implementation for this message.     $system = $this->getInstance(['module' => $module, 'key' => $key]);

    // Attempt to convert relative URLs to absolute.     foreach ($message['body'] as &$body_part) {
      if ($body_part instanceof MarkupInterface) {
        $body_part = Markup::create(Html::transformRootRelativeUrlsToAbsolute((string) $body_part, \Drupal::request()->getSchemeAndHttpHost()));
      }
    }

    // Format the message body.     $message = $system->format($message);

    // Optionally send email.     if ($send) {
      // The original caller requested sending. Sending was canceled by one or       // more hook_mail_alter() implementations. We set 'result' to NULL,       // because FALSE indicates an error in sending.
Home | Imprint | This part of the site doesn't use cookies.