diff --git a/src/CssClassBuilder/CssClassBuilderInterface.php b/src/CssBuilder/CssClassBuilderInterface.php similarity index 77% rename from src/CssClassBuilder/CssClassBuilderInterface.php rename to src/CssBuilder/CssClassBuilderInterface.php index da79f8a..af0caec 100644 --- a/src/CssClassBuilder/CssClassBuilderInterface.php +++ b/src/CssBuilder/CssClassBuilderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Setono\SyliusCalloutPlugin\CssClassBuilder; +namespace Setono\SyliusCalloutPlugin\CssBuilder; use Setono\SyliusCalloutPlugin\Model\CalloutInterface; diff --git a/src/CssBuilder/CssStyleBuilder.php b/src/CssBuilder/CssStyleBuilder.php new file mode 100644 index 0000000..6a31c33 --- /dev/null +++ b/src/CssBuilder/CssStyleBuilder.php @@ -0,0 +1,23 @@ +getColor()) { + $style .= sprintf(' color: %s;', $callout->getColor()); + } + if ($callout->getBackgroundColor()) { + $style .= sprintf(' background-color: %s;', $callout->getBackgroundColor()); + } + + return $style; + } +} diff --git a/src/CssBuilder/CssStyleBuilderInterface.php b/src/CssBuilder/CssStyleBuilderInterface.php new file mode 100644 index 0000000..a205fe8 --- /dev/null +++ b/src/CssBuilder/CssStyleBuilderInterface.php @@ -0,0 +1,12 @@ + + diff --git a/src/Resources/config/services/css_class_builder.xml b/src/Resources/config/services/css_class_builder.xml index 5fa4b5d..e5a8103 100644 --- a/src/Resources/config/services/css_class_builder.xml +++ b/src/Resources/config/services/css_class_builder.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> + class="Setono\SyliusCalloutPlugin\CssBuilder\SemanticUiCssClassBuilder"> + + + + + + + + diff --git a/src/Resources/config/services/twig.xml b/src/Resources/config/services/twig.xml index 3b54270..1293dca 100644 --- a/src/Resources/config/services/twig.xml +++ b/src/Resources/config/services/twig.xml @@ -17,6 +17,7 @@ + diff --git a/src/Resources/views/Shop/Product/Callout/_callout.html.twig b/src/Resources/views/Shop/Product/Callout/_callout.html.twig index 0e00879..ec3d825 100755 --- a/src/Resources/views/Shop/Product/Callout/_callout.html.twig +++ b/src/Resources/views/Shop/Product/Callout/_callout.html.twig @@ -1,2 +1,2 @@ {# @var \Setono\SyliusCalloutPlugin\Model\CalloutInterface callout #} -
{{ render_callout(callout) }}
+
{{ render_callout(callout) }}
diff --git a/src/Twig/CalloutExtension.php b/src/Twig/CalloutExtension.php index 14e9511..f56f71d 100644 --- a/src/Twig/CalloutExtension.php +++ b/src/Twig/CalloutExtension.php @@ -20,6 +20,7 @@ public function getFunctions(): array new TwigFunction('get_callout_assignment_delay', $this->getDelay(...)), new TwigFunction('render_callout_class_attribute', [CalloutRuntime::class, 'renderCalloutClassAttribute']), new TwigFunction('render_callout', [CalloutRuntime::class, 'renderCallout'], ['is_safe' => ['html']]), + new TwigFunction('render_callout_style', [CalloutRuntime::class, 'renderCalloutStyle']), ]; } diff --git a/src/Twig/CalloutRuntime.php b/src/Twig/CalloutRuntime.php index dc03002..19b6c97 100644 --- a/src/Twig/CalloutRuntime.php +++ b/src/Twig/CalloutRuntime.php @@ -6,7 +6,8 @@ use Setono\SyliusCalloutPlugin\Checker\Eligibility\CalloutEligibilityCheckerInterface; use Setono\SyliusCalloutPlugin\Checker\RenderingEligibility\CalloutRenderingEligibilityCheckerInterface; -use Setono\SyliusCalloutPlugin\CssClassBuilder\CssClassBuilderInterface; +use Setono\SyliusCalloutPlugin\CssBuilder\CssClassBuilderInterface; +use Setono\SyliusCalloutPlugin\CssBuilder\CssStyleBuilderInterface; use Setono\SyliusCalloutPlugin\Model\CalloutInterface; use Setono\SyliusCalloutPlugin\Model\ProductInterface; use Setono\SyliusCalloutPlugin\Provider\RenderingCalloutProviderInterface; @@ -21,6 +22,7 @@ public function __construct( private readonly CssClassBuilderInterface $cssClassBuilder, private readonly RenderingCalloutProviderInterface $renderingCalloutProvider, private readonly CalloutRendererInterface $calloutRenderer, + private readonly CssStyleBuilderInterface $cssStyleBuilder, ) { } @@ -76,4 +78,9 @@ public function renderCallout(CalloutInterface $callout): string { return (string) $this->calloutRenderer->render($callout); } + + public function renderCalloutStyle(CalloutInterface $callout): string + { + return $this->cssStyleBuilder->build($callout); + } } diff --git a/tests/Twig/CalloutRuntimeTest.php b/tests/Twig/CalloutRuntimeTest.php index ee38eb5..cb2bf56 100644 --- a/tests/Twig/CalloutRuntimeTest.php +++ b/tests/Twig/CalloutRuntimeTest.php @@ -9,7 +9,8 @@ use Prophecy\PhpUnit\ProphecyTrait; use Setono\SyliusCalloutPlugin\Checker\Eligibility\CalloutEligibilityCheckerInterface; use Setono\SyliusCalloutPlugin\Checker\RenderingEligibility\CalloutRenderingEligibilityCheckerInterface; -use Setono\SyliusCalloutPlugin\CssClassBuilder\CssClassBuilderInterface; +use Setono\SyliusCalloutPlugin\CssBuilder\CssClassBuilderInterface; +use Setono\SyliusCalloutPlugin\CssBuilder\CssStyleBuilderInterface; use Setono\SyliusCalloutPlugin\Model\Callout; use Setono\SyliusCalloutPlugin\Model\CalloutInterface; use Setono\SyliusCalloutPlugin\Model\ProductInterface; @@ -76,6 +77,7 @@ private function getCalloutRuntime(): CalloutRuntime ; $calloutRenderer = $this->prophesize(CalloutRendererInterface::class); + $cssStyleBuilder = $this->prophesize(CssStyleBuilderInterface::class); return new CalloutRuntime( $calloutRenderingEligibilityChecker->reveal(), @@ -83,6 +85,7 @@ private function getCalloutRuntime(): CalloutRuntime $cssClassBuilder->reveal(), $renderCalloutProvider->reveal(), $calloutRenderer->reveal(), + $cssStyleBuilder->reveal(), ); }