Skip to content
Snippets Groups Projects

Issue #3190799: ProductVariationContext causes to generate sample images even if "Show content preview" is disabled in the LayoutBuider

Merged Issue #3190799: ProductVariationContext causes to generate sample images even if "Show content preview" is disabled in the LayoutBuider
Files
3
@@ -14,6 +14,7 @@ use Drupal\Core\Routing\RouteMatchInterface;
@@ -14,6 +14,7 @@ use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\layout_builder\DefaultsSectionStorageInterface;
use Drupal\layout_builder\DefaultsSectionStorageInterface;
 
use Drupal\layout_builder\Entity\SampleEntityGeneratorInterface;
use Drupal\layout_builder\OverridesSectionStorageInterface;
use Drupal\layout_builder\OverridesSectionStorageInterface;
/**
/**
@@ -37,6 +38,13 @@ class ProductVariationContext implements ContextProviderInterface {
@@ -37,6 +38,13 @@ class ProductVariationContext implements ContextProviderInterface {
*/
*/
protected $entityTypeManager;
protected $entityTypeManager;
 
/**
 
* The sample entity generator.
 
*
 
* @var \Drupal\layout_builder\Entity\SampleEntityGeneratorInterface|null
 
*/
 
protected $sampleEntityGenerator;
 
/**
/**
* Constructs a new ProductVariationContext object.
* Constructs a new ProductVariationContext object.
*
*
@@ -50,6 +58,16 @@ class ProductVariationContext implements ContextProviderInterface {
@@ -50,6 +58,16 @@ class ProductVariationContext implements ContextProviderInterface {
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeManager = $entity_type_manager;
}
}
 
/**
 
* Set the sample entity generator.
 
*
 
* @param \Drupal\layout_builder\Entity\SampleEntityGeneratorInterface $sample_entity_generator
 
* The sample entity generator.
 
*/
 
public function setSampleEntityGenerator(SampleEntityGeneratorInterface $sample_entity_generator) {
 
$this->sampleEntityGenerator = $sample_entity_generator;
 
}
 
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
@@ -82,13 +100,6 @@ class ProductVariationContext implements ContextProviderInterface {
@@ -82,13 +100,6 @@ class ProductVariationContext implements ContextProviderInterface {
}
}
}
}
}
}
/** @var \Drupal\commerce_product\Entity\ProductTypeInterface $product_type */
elseif ($product_type = $this->routeMatch->getParameter('commerce_product_type')) {
if (is_string($product_type)) {
$product_type = ProductType::load($product_type);
}
$value = $product_variation_storage->createWithSampleValues($product_type->getVariationTypeId());
}
// @todo Simplify this logic once EntityTargetInterface is available
// @todo Simplify this logic once EntityTargetInterface is available
// @see https://www.drupal.org/project/drupal/issues/3054490
// @see https://www.drupal.org/project/drupal/issues/3054490
elseif (strpos($this->routeMatch->getRouteName(), 'layout_builder') !== FALSE) {
elseif (strpos($this->routeMatch->getRouteName(), 'layout_builder') !== FALSE) {
@@ -99,7 +110,7 @@ class ProductVariationContext implements ContextProviderInterface {
@@ -99,7 +110,7 @@ class ProductVariationContext implements ContextProviderInterface {
assert($context instanceof EntityDisplayInterface);
assert($context instanceof EntityDisplayInterface);
if ($context->getTargetEntityTypeId() === 'commerce_product') {
if ($context->getTargetEntityTypeId() === 'commerce_product') {
$product_type = ProductType::load($context->getTargetBundle());
$product_type = ProductType::load($context->getTargetBundle());
$value = $product_variation_storage->createWithSampleValues($product_type->getVariationTypeId());
$value = $this->sampleEntityGenerator->get('commerce_product_variation', $product_type->getVariationTypeId());
}
}
}
}
elseif ($section_storage instanceof OverridesSectionStorageInterface) {
elseif ($section_storage instanceof OverridesSectionStorageInterface) {
@@ -108,7 +119,7 @@ class ProductVariationContext implements ContextProviderInterface {
@@ -108,7 +119,7 @@ class ProductVariationContext implements ContextProviderInterface {
$value = $context->getDefaultVariation();
$value = $context->getDefaultVariation();
if ($value === NULL) {
if ($value === NULL) {
$product_type = ProductType::load($context->bundle());
$product_type = ProductType::load($context->bundle());
$value = $product_variation_storage->createWithSampleValues($product_type->getVariationTypeId());
$value = $this->sampleEntityGenerator->get('commerce_product_variation', $product_type->getVariationTypeId());
}
}
}
}
}
}
Loading