Skip to content

Commit 7c27097

Browse files
blazeyofubhy
authored andcommitted
#360 Fix the responsive enum when no responsive styles are present. (#361)
1 parent 0468c7f commit 7c27097

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

modules/graphql_image/src/Plugin/Deriver/ImageResponsiveDeriver.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Component\Plugin\Derivative\DeriverBase;
66
use Drupal\Core\Extension\ModuleHandlerInterface;
77
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8+
use Drupal\responsive_image\Entity\ResponsiveImageStyle;
89
use Symfony\Component\DependencyInjection\ContainerInterface;
910

1011
/**
@@ -42,8 +43,17 @@ public function __construct(ModuleHandlerInterface $moduleHandler) {
4243
* {@inheritdoc}
4344
*/
4445
public function getDerivativeDefinitions($basePluginDefinition) {
46+
/**
47+
* Add the 'responsive' field only if responsive image module is enabled
48+
* and there is at least one style defined in the system.
49+
*
50+
* @see \Drupal\graphql_image\Plugin\GraphQL\Enums\ResponsiveImageStyleId
51+
*/
4552
if ($this->moduleHandler->moduleExists('responsive_image')) {
46-
$this->derivatives['responsive_image'] = $basePluginDefinition;
53+
$imageStyles = ResponsiveImageStyle::loadMultiple();
54+
if (!empty($imageStyles)) {
55+
$this->derivatives['responsive_image'] = $basePluginDefinition;
56+
}
4757
}
4858
return parent::getDerivativeDefinitions($basePluginDefinition);
4959
}

0 commit comments

Comments
 (0)