function Resource::setDimensions

Same name and namespace in other branches
  1. 9 core/modules/media/src/OEmbed/Resource.php \Drupal\media\OEmbed\Resource::setDimensions()
  2. 8.9.x core/modules/media/src/OEmbed/Resource.php \Drupal\media\OEmbed\Resource::setDimensions()
  3. 10 core/modules/media/src/OEmbed/Resource.php \Drupal\media\OEmbed\Resource::setDimensions()

Sets the dimensions.

Parameters

int|null $width: The width of the resource.

int|null $height: The height of the resource.

Throws

\InvalidArgumentException If either $width or $height are not numbers greater than zero.

File

core/modules/media/src/OEmbed/Resource.php, line 521

Class

Resource
Value object representing an oEmbed resource.

Namespace

Drupal\media\OEmbed

Code

protected function setDimensions($width, $height) {
    if (isset($width) && $width <= 0 || isset($height) && $height <= 0) {
        throw new \InvalidArgumentException('The dimensions must be NULL or numbers greater than zero.');
    }
    $this->width = isset($width) ? (int) $width : NULL;
    $this->height = isset($height) ? (int) $height : NULL;
}

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