-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Twig Hooks] Nullable
HookableMetadata
Property in `HookableLiveCom…
…ponentTrait` (#10) If we attempt to render a component that directly utilizes `HookableLiveComponentTrait` without involving the `hooks` system, we will encounter an error. This component is directly rendered from the grid configuration: <img width="701" alt="image" src="https://github.com/Sylius/Stack/assets/40125720/5ab36df8-c116-454d-9dfc-5908fda7ba84"> We encountered with the following error: <img width="1056" alt="image" src="https://github.com/Sylius/Stack/assets/40125720/c619e648-d46b-43c3-b0f0-d75dad965c09"> Making the `HookableMetadata` property nullable allows to render the component without any problems.
- Loading branch information
Showing
16 changed files
with
163 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/TwigHooks/tests/Functional/.application/config/routes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
#index: | ||
# path: / | ||
# controller: App\Controller\DefaultController::index | ||
|
||
live_component: | ||
resource: '@LiveComponentBundle/config/routes.php' | ||
prefix: '/_components' |
16 changes: 16 additions & 0 deletions
16
src/TwigHooks/tests/Functional/.application/src/Component/DummyComponent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TestApplication\Sylius\TwigHooks\Component; | ||
|
||
use Sylius\TwigHooks\Twig\Component\HookableComponentTrait; | ||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
|
||
#[AsLiveComponent('app:dummy', template: '_component/dummy.html.twig')] | ||
final class DummyComponent | ||
{ | ||
use DefaultActionTrait; | ||
use HookableComponentTrait; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/TwigHooks/tests/Functional/.application/src/Component/DummyLiveComponent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TestApplication\Sylius\TwigHooks\Component; | ||
|
||
use Sylius\TwigHooks\LiveComponent\HookableLiveComponentTrait; | ||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; | ||
use Symfony\UX\LiveComponent\DefaultActionTrait; | ||
|
||
#[AsLiveComponent('app:dummy_live', template: '_component/dummy.html.twig')] | ||
final class DummyLiveComponent | ||
{ | ||
use DefaultActionTrait; | ||
use HookableLiveComponentTrait; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/TwigHooks/tests/Functional/.application/templates/_component/dummy.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% if is_hookable() %} | ||
I'm a hookable! | ||
{% else %} | ||
I'm not a hookable :( | ||
{% endif %} |
1 change: 1 addition & 0 deletions
1
...lates/hookable_live_component/hookable_component_rendered_with_using_twig_hooks.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% hook 'hookable_live_component' %} |
1 change: 1 addition & 0 deletions
1
...es/hookable_live_component/hookable_component_rendered_without_using_twig_hooks.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<twig:app:dummy_live /> |
1 change: 1 addition & 0 deletions
1
...lates/hookable_twig_component/hookable_component_rendered_with_using_twig_hooks.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% hook 'hookable_twig_component' %} |
1 change: 1 addition & 0 deletions
1
...es/hookable_twig_component/hookable_component_rendered_without_using_twig_hooks.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<twig:app:dummy /> |
44 changes: 44 additions & 0 deletions
44
src/TwigHooks/tests/Functional/Twig/HookableLiveComponentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\TwigHooks\Functional\Twig; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Twig\Environment as Twig; | ||
|
||
/** | ||
* @group kernel-required | ||
*/ | ||
final class HookableLiveComponentTest extends KernelTestCase | ||
{ | ||
public function testItRendersHookableLiveComponentWithUsingTwigHooks(): void | ||
{ | ||
$this->assertSame( | ||
<<<EXPECTED | ||
<!-- BEGIN HOOK | name: "hookable_live_component" --> | ||
<!-- BEGIN HOOKABLE | hook: "hookable_live_component", name: "dummy", component: "app:dummy_live", priority: 0 --> | ||
I'm a hookable! | ||
<!-- END HOOKABLE | hook: "hookable_live_component", name: "dummy", component: "app:dummy_live", priority: 0 --> | ||
<!-- END HOOK | name: "hookable_live_component" --> | ||
EXPECTED, | ||
$this->render('hookable_live_component/hookable_component_rendered_with_using_twig_hooks.html.twig'), | ||
); | ||
} | ||
|
||
public function testItRendersHookableLiveComponentWithoutUsingTwigHooks(): void | ||
{ | ||
$this->assertStringContainsString( | ||
"I'm not a hookable :(", | ||
$this->render('hookable_live_component/hookable_component_rendered_without_using_twig_hooks.html.twig'), | ||
); | ||
} | ||
|
||
private function render(string $path): string | ||
{ | ||
/** @var Twig $twig */ | ||
$twig = $this->getContainer()->get('twig'); | ||
|
||
return $twig->render($path); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/TwigHooks/tests/Functional/Twig/HookableTwigComponentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Sylius\TwigHooks\Functional\Twig; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Twig\Environment as Twig; | ||
|
||
/** | ||
* @group kernel-required | ||
*/ | ||
final class HookableTwigComponentTest extends KernelTestCase | ||
{ | ||
public function testItRendersHookableLiveComponentWithUsingTwigHooks(): void | ||
{ | ||
$this->assertSame( | ||
<<<EXPECTED | ||
<!-- BEGIN HOOK | name: "hookable_twig_component" --> | ||
<!-- BEGIN HOOKABLE | hook: "hookable_twig_component", name: "dummy", component: "app:dummy", priority: 0 --> | ||
I'm a hookable! | ||
<!-- END HOOKABLE | hook: "hookable_twig_component", name: "dummy", component: "app:dummy", priority: 0 --> | ||
<!-- END HOOK | name: "hookable_twig_component" --> | ||
EXPECTED, | ||
$this->render('hookable_twig_component/hookable_component_rendered_with_using_twig_hooks.html.twig'), | ||
); | ||
} | ||
|
||
public function testItRendersHookableLiveComponentWithoutUsingTwigHooks(): void | ||
{ | ||
$this->assertStringContainsString( | ||
"I'm not a hookable :(", | ||
$this->render('hookable_twig_component/hookable_component_rendered_without_using_twig_hooks.html.twig'), | ||
); | ||
} | ||
|
||
private function render(string $path): string | ||
{ | ||
/** @var Twig $twig */ | ||
$twig = $this->getContainer()->get('twig'); | ||
|
||
return $twig->render($path); | ||
} | ||
} |