Skip to content
Snippets Groups Projects
Commit ce31d453 authored by Leon Kessler's avatar Leon Kessler Committed by Christopher C. Wells
Browse files

Issue #3232157 by Leon Kessler: Image styles are generated for other types of file entites

parent 3af64efd
No related branches found
No related tags found
No related merge requests found
......@@ -21,24 +21,26 @@ protected function computeValue() {
$config = \Drupal::config('jsonapi_image_styles.settings');
$styles = [];
$entity = $this->getEntity();
$uri = ($entity instanceof File) ? $entity->getFileUri() : FALSE;
$defined_styles = ($config->get('image_styles')) ? $config->get('image_styles') : [];
if (!empty(array_filter($defined_styles))) {
foreach ($defined_styles as $key) {
$styles[$key] = ImageStyle::load($key);
$uri = ($entity instanceof File && substr($entity->getMimeType(), 0, 5) === 'image') ? $entity->getFileUri() : FALSE;
if ($uri) {
$defined_styles = $config->get('image_styles') ?? [];
if (!empty(array_filter($defined_styles))) {
foreach ($defined_styles as $key) {
$styles[$key] = ImageStyle::load($key);
}
}
else {
$styles = ImageStyle::loadMultiple();
}
}
else {
$styles = ImageStyle::loadMultiple();
}
$offset = 0;
foreach ($styles as $name => $style) {
if ($style instanceof ImageStyle) {
$this->list[] = $this->createItem($offset, ['url' => [$name => $style->buildUrl($uri)]]);
$offset = 0;
foreach ($styles as $name => $style) {
if ($style instanceof ImageStyle) {
$this->list[] = $this->createItem($offset, ['url' => [$name => $style->buildUrl($uri)]]);
}
$offset++;
}
$offset++;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment