class IFrameUrlHelper
Same name in other branches
- 8.9.x core/modules/media/src/IFrameUrlHelper.php \Drupal\media\IFrameUrlHelper
- 10 core/modules/media/src/IFrameUrlHelper.php \Drupal\media\IFrameUrlHelper
- 11.x core/modules/media/src/IFrameUrlHelper.php \Drupal\media\IFrameUrlHelper
Providers helper functions for displaying oEmbed resources in an iFrame.
@internal This is an internal part of the oEmbed system and should only be used by oEmbed-related code in Drupal core.
Hierarchy
- class \Drupal\media\IFrameUrlHelper
Expanded class hierarchy of IFrameUrlHelper
5 files declare their use of IFrameUrlHelper
- IFrameUrlHelperTest.php in core/
modules/ media/ tests/ src/ Unit/ IFrameUrlHelperTest.php - MediaSettingsForm.php in core/
modules/ media/ src/ Form/ MediaSettingsForm.php - OEmbed.php in core/
modules/ media/ src/ Plugin/ media/ Source/ OEmbed.php - OEmbedFormatter.php in core/
modules/ media/ src/ Plugin/ Field/ FieldFormatter/ OEmbedFormatter.php - OEmbedIframeController.php in core/
modules/ media/ src/ Controller/ OEmbedIframeController.php
1 string reference to 'IFrameUrlHelper'
- media.services.yml in core/
modules/ media/ media.services.yml - core/modules/media/media.services.yml
1 service uses IFrameUrlHelper
- media.oembed.iframe_url_helper in core/
modules/ media/ media.services.yml - Drupal\media\IFrameUrlHelper
File
-
core/
modules/ media/ src/ IFrameUrlHelper.php, line 17
Namespace
Drupal\mediaView source
class IFrameUrlHelper {
/**
* The request context service.
*
* @var \Drupal\Core\Routing\RequestContext
*/
protected $requestContext;
/**
* The private key service.
*
* @var \Drupal\Core\PrivateKey
*/
protected $privateKey;
/**
* IFrameUrlHelper constructor.
*
* @param \Drupal\Core\Routing\RequestContext $request_context
* The request context service.
* @param \Drupal\Core\PrivateKey $private_key
* The private key service.
*/
public function __construct(RequestContext $request_context, PrivateKey $private_key) {
$this->requestContext = $request_context;
$this->privateKey = $private_key;
}
/**
* Hashes an oEmbed resource URL.
*
* @param string $url
* The resource URL.
* @param int $max_width
* (optional) The maximum width of the resource.
* @param int $max_height
* (optional) The maximum height of the resource.
*
* @return string
* The hashed URL.
*/
public function getHash($url, $max_width = NULL, $max_height = NULL) {
return Crypt::hmacBase64("{$url}:{$max_width}:{$max_height}", $this->privateKey
->get() . Settings::getHashSalt());
}
/**
* Checks if an oEmbed URL can be securely displayed in an frame.
*
* @param string $url
* The URL to check.
*
* @return bool
* TRUE if the URL is considered secure, otherwise FALSE.
*/
public function isSecure($url) {
if (!$url) {
return FALSE;
}
$url_host = parse_url($url, PHP_URL_HOST);
$system_host = parse_url($this->requestContext
->getCompleteBaseUrl(), PHP_URL_HOST);
// The URL is secure if its domain is not the same as the domain of the base
// URL of the current request.
return $url_host && $system_host && $url_host !== $system_host;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
IFrameUrlHelper::$privateKey | protected | property | The private key service. |
IFrameUrlHelper::$requestContext | protected | property | The request context service. |
IFrameUrlHelper::getHash | public | function | Hashes an oEmbed resource URL. |
IFrameUrlHelper::isSecure | public | function | Checks if an oEmbed URL can be securely displayed in an frame. |
IFrameUrlHelper::__construct | public | function | IFrameUrlHelper constructor. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.