Resource
class Resource implements CacheableDependencyInterface (View source)
| internal | This class is an internal part of the oEmbed system and should only be instantiated by \Drupal\media\OEmbed\ResourceFetcherInterface::fetchResource(). |
Value object representing an oEmbed resource.
Data received from an oEmbed provider could be insecure. For example, resources of the 'rich' type provide an HTML representation which is not sanitized by this object in any way. Any values you retrieve from this object should be treated as potentially dangerous user input and carefully validated and sanitized before being displayed or otherwise manipulated by your code.
Valid resource types are defined in the oEmbed specification and represented by the TYPE_* constants in this class.
Traits
Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
Constants
| TYPE_LINK |
The resource type for link resources. |
| TYPE_PHOTO |
The resource type for photo resources. |
| TYPE_RICH |
The resource type for rich resources. |
| TYPE_VIDEO |
The resource type for video resources. |
Properties
| protected string[] | $cacheContexts | Cache contexts. |
from CacheableDependencyTrait |
| protected string[] | $cacheTags | Cache tags. |
from CacheableDependencyTrait |
| protected int | $cacheMaxAge | Cache max-age. |
from CacheableDependencyTrait |
| protected string | $type | The resource type. Can be one of the static::TYPE_* constants. |
|
| protected Provider | $provider | The resource provider. |
|
| protected string | $title | A text title, describing the resource. |
|
| protected string | $authorName | The name of the author/owner of the resource. |
|
| protected string | $authorUrl | A URL for the author/owner of the resource. |
|
| protected string | $thumbnailUrl | A URL to a thumbnail image representing the resource. |
|
| protected int | $thumbnailWidth | The width of the thumbnail, in pixels. |
|
| protected int | $thumbnailHeight | The height of the thumbnail, in pixels. |
|
| protected int | $width | The width of the resource, in pixels. |
|
| protected int | $height | The height of the resource, in pixels. |
|
| protected string | $url | The resource URL. Only applies to 'photo' and 'link' resources. |
|
| protected string | $html | The HTML representation of the resource. |
Methods
Sets cacheability; useful for value object constructors.
Resource constructor.
Returns the resource type.
Returns the title of the resource.
Returns the name of the resource author.
Returns the URL of the resource author.
Returns the resource provider, if known.
Returns the URL of the resource's thumbnail image.
Returns the width of the resource's thumbnail image.
Returns the height of the resource's thumbnail image.
Returns the width of the resource.
Returns the height of the resource.
Returns the HTML representation of the resource.
Sets the thumbnail dimensions.
Sets the dimensions.
Details
protected $this
setCacheability(CacheableDependencyInterface $cacheability)
Sets cacheability; useful for value object constructors.
getCacheTags()
{@inheritdoc}
getCacheContexts()
{@inheritdoc}
getCacheMaxAge()
{@inheritdoc}
protected
__construct(Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)
Resource constructor.
static Resource
link(string $url = NULL, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)
Creates a link resource.
static Resource
photo(string $url, int $width, int $height, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)
Creates a photo resource.
static Resource
rich(string $html, int $width, int $height, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)
Creates a rich resource.
static Resource
video(string $html, int $width, int $height, Provider $provider = NULL, string $title = NULL, string $author_name = NULL, string $author_url = NULL, int $cache_age = NULL, string $thumbnail_url = NULL, int $thumbnail_width = NULL, int $thumbnail_height = NULL)
Creates a video resource.
string
getType()
Returns the resource type.
string|null
getTitle()
Returns the title of the resource.
string|null
getAuthorName()
Returns the name of the resource author.
Url|null
getAuthorUrl()
Returns the URL of the resource author.
Provider|null
getProvider()
Returns the resource provider, if known.
Url|null
getThumbnailUrl()
Returns the URL of the resource's thumbnail image.
int|null
getThumbnailWidth()
Returns the width of the resource's thumbnail image.
int|null
getThumbnailHeight()
Returns the height of the resource's thumbnail image.
int|null
getWidth()
Returns the width of the resource.
int|null
getHeight()
Returns the height of the resource.
Url|null
getUrl()
Returns the URL of the resource. Only applies to 'photo' resources.
string|null
getHtml()
Returns the HTML representation of the resource.
Only applies to 'rich' and 'video' resources.
protected
setThumbnailDimensions(int $width, int $height)
Sets the thumbnail dimensions.
protected
setDimensions(int|null $width, int|null $height)
Sets the dimensions.