diff --git a/php-transformer/src/HtmlToBlocks/Elements/FlowContainerElementContext.php b/php-transformer/src/HtmlToBlocks/Elements/FlowContainerElementContext.php
index 98224647..9c3a6cfb 100644
--- a/php-transformer/src/HtmlToBlocks/Elements/FlowContainerElementContext.php
+++ b/php-transformer/src/HtmlToBlocks/Elements/FlowContainerElementContext.php
@@ -3,6 +3,7 @@
namespace Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Elements;
+use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Classification\SourceElementClassifier;
use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Patterns\PatternContext;
use Closure;
use DOMElement;
@@ -17,8 +18,7 @@ public function __construct(
private readonly Closure $recognizePatterns,
private readonly Closure $flankedSeparatorBlock,
private readonly Closure $capturedMediaLayoutBlock,
- private readonly Closure $hasResponsiveImageSources,
- private readonly Closure $hasGalleryMediaItems,
+ private readonly SourceElementClassifier $sourceElementClassifier,
private readonly Closure $responsiveMediaBlock,
private readonly Closure $isDirectChildOfAuthorOwnedLayout,
private readonly Closure $authorLayoutBlock,
@@ -45,7 +45,6 @@ public function __construct(
private readonly Closure $generatedComponentBlock,
private readonly Closure $textFlowBlock,
private readonly Closure $convertChildren,
- private readonly Closure $hasDirectMediaChild,
private readonly Closure $backgroundImageBlock,
private readonly Closure $coalescedSingleGroupWrapper,
private readonly Closure $shouldPreserveWrapper,
@@ -65,8 +64,8 @@ public function recognizePatterns(DOMElement $element, array &$fallbacks, array
public function flankedSeparatorBlock(DOMElement $element): ?array { return ($this->flankedSeparatorBlock)($element); }
/** @return array|null */
public function capturedMediaLayoutBlock(DOMElement $element): ?array { return ($this->capturedMediaLayoutBlock)($element); }
- public function hasResponsiveImageSources(DOMElement $element): bool { return ($this->hasResponsiveImageSources)($element); }
- public function hasGalleryMediaItems(DOMElement $element): bool { return ($this->hasGalleryMediaItems)($element); }
+ public function hasResponsiveImageSources(DOMElement $element): bool { return $this->sourceElementClassifier->hasResponsiveImageSources($element); }
+ public function hasGalleryMediaItems(DOMElement $element): bool { return $this->sourceElementClassifier->hasGalleryMediaItems($element); }
/** @return array */
public function responsiveMediaBlock(DOMElement $element): array { return ($this->responsiveMediaBlock)($element); }
public function isDirectChildOfAuthorOwnedLayout(DOMElement $element): bool { return ($this->isDirectChildOfAuthorOwnedLayout)($element); }
@@ -111,7 +110,7 @@ public function generatedComponentBlock(DOMElement $element): ?array { return ($
public function textFlowBlock(DOMElement $element): ?array { return ($this->textFlowBlock)($element); }
/** @param array> $fallbacks @return array> */
public function convertChildren(DOMElement $element, array &$fallbacks): array { return ($this->convertChildren)($element, $fallbacks); }
- public function hasDirectMediaChild(DOMElement $element): bool { return ($this->hasDirectMediaChild)($element); }
+ public function hasDirectMediaChild(DOMElement $element): bool { return $this->sourceElementClassifier->hasDirectMediaChild($element); }
/** @return array|null */
public function backgroundImageBlock(DOMElement $element): ?array { return ($this->backgroundImageBlock)($element); }
/** @param array $child @return array|null */
diff --git a/php-transformer/src/HtmlToBlocks/HtmlTransformer.php b/php-transformer/src/HtmlToBlocks/HtmlTransformer.php
index 1fbf8854..ec2c324a 100644
--- a/php-transformer/src/HtmlToBlocks/HtmlTransformer.php
+++ b/php-transformer/src/HtmlToBlocks/HtmlTransformer.php
@@ -788,8 +788,7 @@ function (DOMElement $element, array &$fallbacks, bool $captureUnsupported): arr
recognizePatterns: fn (DOMElement $element, array &$fallbacks, array $patterns): ?array => $this->recognizePatterns($element, $fallbacks, $patterns),
flankedSeparatorBlock: fn (DOMElement $element): ?array => $this->flankedSeparatorBlockFromElement($element),
capturedMediaLayoutBlock: fn (DOMElement $element): ?array => $this->capturedMediaLayoutBoundaryBlock($element),
- hasResponsiveImageSources: fn (DOMElement $element): bool => $this->sourceElementClassifier->hasResponsiveImageSources($element),
- hasGalleryMediaItems: fn (DOMElement $element): bool => $this->sourceElementClassifier->hasGalleryMediaItems($element),
+ sourceElementClassifier: $this->sourceElementClassifier,
responsiveMediaBlock: fn (DOMElement $element): array => $this->responsiveMediaBlock($element),
isDirectChildOfAuthorOwnedLayout: fn (DOMElement $element): bool => $this->isDirectChildOfAuthorOwnedLayout($element),
authorLayoutBlock: fn (DOMElement $element, array &$fallbacks): array => $this->authorLayoutBlockFromElement($element, $fallbacks),
@@ -819,7 +818,6 @@ function (DOMElement $element, array &$fallbacks, bool $captureUnsupported): arr
},
textFlowBlock: fn (DOMElement $element): ?array => $this->textFlowBlockFromElement($element),
convertChildren: fn (DOMElement $element, array &$fallbacks): array => $this->convertChildren($element, $fallbacks, true),
- hasDirectMediaChild: fn (DOMElement $element): bool => $this->sourceElementClassifier->hasDirectMediaChild($element),
backgroundImageBlock: fn (DOMElement $element): ?array => $this->backgroundImageBlockFromElement($element),
coalescedSingleGroupWrapper: fn (DOMElement $element, array $child): ?array => $this->coalescedSingleGroupWrapper($element, $child),
shouldPreserveWrapper: fn (DOMElement $element): bool => $this->shouldPreserveWrapper($element),
diff --git a/php-transformer/tests/unit/flow-container-element-converter.php b/php-transformer/tests/unit/flow-container-element-converter.php
index ec94ce3d..8b7cc073 100644
--- a/php-transformer/tests/unit/flow-container-element-converter.php
+++ b/php-transformer/tests/unit/flow-container-element-converter.php
@@ -3,6 +3,7 @@
require __DIR__ . '/../../vendor/autoload.php';
+use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Classification\SourceElementClassifier;
use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Elements\FlowContainerElementContext;
use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Elements\FlowContainerElementConverter;
use Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\Patterns\PatternContext;
@@ -39,8 +40,7 @@
},
'flankedSeparatorBlock' => $null,
'capturedMediaLayoutBlock' => $null,
- 'hasResponsiveImageSources' => $false,
- 'hasGalleryMediaItems' => $false,
+ 'sourceElementClassifier' => new SourceElementClassifier(),
'responsiveMediaBlock' => static fn (): array => array( 'blockName' => 'responsive-media' ),
'isDirectChildOfAuthorOwnedLayout' => $false,
'authorLayoutBlock' => static fn (): array => array( 'blockName' => 'author-layout' ),
@@ -80,7 +80,6 @@
}
return array();
},
- 'hasDirectMediaChild' => $false,
'backgroundImageBlock' => $null,
'coalescedSingleGroupWrapper' => $null,
'shouldPreserveWrapper' => $false,