You are here

public function ImageStylesProvider::loadStyles in Consumer Image Styles 4.x

Same name and namespace in other branches
  1. 8.3 src/ImageStylesProvider.php \Drupal\consumer_image_styles\ImageStylesProvider::loadStyles()
  2. 8.2 src/ImageStylesProvider.php \Drupal\consumer_image_styles\ImageStylesProvider::loadStyles()

Load the image styles for a given consumer.

Parameters

\Drupal\consumers\Entity\Consumer $consumer: Consumer entity to load image styles for.

Return value

\Drupal\image\Entity\ImageStyle[] List of image styles keyed by image style id.

Overrides ImageStylesProviderInterface::loadStyles

File

src/ImageStylesProvider.php, line 47

Class

ImageStylesProvider
Class ImageStylesProvider.

Namespace

Drupal\consumer_image_styles

Code

public function loadStyles(Consumer $consumer) {
  $consumer_config = $consumer
    ->get('image_styles')
    ->getValue();
  $image_style_ids = array_map(function ($field_value) {
    return $field_value['target_id'];
  }, $consumer_config);

  // Load image style entities in bulk.
  try {
    $image_styles = $this->entityTypeManager
      ->getStorage('image_style')
      ->loadMultiple($image_style_ids);
  } catch (PluginException $e) {
    $image_styles = [];
  }
  return $image_styles;
}