class ImageStylesProvider in Consumer Image Styles 8.2
Same name and namespace in other branches
- 8.3 src/ImageStylesProvider.php \Drupal\consumer_image_styles\ImageStylesProvider
- 4.x src/ImageStylesProvider.php \Drupal\consumer_image_styles\ImageStylesProvider
Class ImageStylesProvider.
@package Drupal\consumer_image_styles
Hierarchy
- class \Drupal\consumer_image_styles\ImageStylesProvider implements ImageStylesProviderInterface
Expanded class hierarchy of ImageStylesProvider
1 string reference to 'ImageStylesProvider'
1 service uses ImageStylesProvider
File
- src/
ImageStylesProvider.php, line 14
Namespace
Drupal\consumer_image_stylesView source
class ImageStylesProvider implements ImageStylesProviderInterface {
private $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager) {
$this->entityTypeManager = $entityTypeManager;
}
/**
*
* @param Consumer $consumer
* Consumer entity to load image styles for.
*
* @return \Drupal\image\Entity\ImageStyle[]
* List of image styles keyed by image style id.
*/
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 (InvalidPluginDefinitionException $e) {
$image_styles = [];
}
return $image_styles;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ImageStylesProvider:: |
private | property | ||
ImageStylesProvider:: |
public | function |
Overrides ImageStylesProviderInterface:: |
|
ImageStylesProvider:: |
public | function |