You are here

protected function BaseDataProvider::getSizes in Gutenberg 8.2

Same name and namespace in other branches
  1. 8 src/DataProvider/BaseDataProvider.php \Drupal\gutenberg\DataProvider\BaseDataProvider::getSizes()

Get sizes of image styles for the source.

Parameters

\Drupal\gutenberg\DataProvider\string $source_url: The source URL.

\Drupal\gutenberg\DataProvider\string $uri: The URI.

Return value

array The sizes of the image styles.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

2 calls to BaseDataProvider::getSizes()
FileEntityDataProvider::getData in src/DataProvider/FileEntityDataProvider.php
MediaEntityDataProvider::getData in src/DataProvider/MediaEntityDataProvider.php
Returns array data.

File

src/DataProvider/BaseDataProvider.php, line 84

Class

BaseDataProvider
Provides base abstraction for entity data providers.

Namespace

Drupal\gutenberg\DataProvider

Code

protected function getSizes(string $source_url, string $uri) {

  // SVG's don't have image styles.
  if (strtolower(pathinfo($source_url, PATHINFO_EXTENSION)) === 'svg') {
    return [];
  }
  $styles = $this->entityTypeManager
    ->getStorage('image_style')
    ->loadMultiple();
  $sizes = [
    'full' => [
      'source_url' => $source_url,
    ],
  ];
  foreach ($styles as $style) {

    /** @var \Drupal\image\Entity\ImageStyle $style */
    $sizes[$style
      ->getName()] = [
      'source_url' => file_url_transform_relative($style
        ->buildUrl($uri)),
    ];
  }
  return $sizes;
}