-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TwigHooks] Allow discarding hookable's context
- Loading branch information
1 parent
c4fb80f
commit c502cf6
Showing
9 changed files
with
110 additions
and
9 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
3 changes: 3 additions & 0 deletions
3
...igHooks/tests/Functional/.application/templates/restricting_context_scope/index.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,3 @@ | ||
{% hook 'restricting_context_scope.index' with { | ||
some: 'data', | ||
} %} |
6 changes: 6 additions & 0 deletions
6
...ts/Functional/.application/templates/restricting_context_scope/index/block/some.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,6 @@ | ||
{% set hookable_context = get_hookable_context() %} | ||
|
||
{{ hookable_context.get('title') }} | ||
|
||
is "some" defined: {{ hookable_context.has('some') ? 'Yes' : 'No' }} | ||
is "other" defined: {{ hookable_context.has('other') ? 'Yes' : 'No' }} |
3 changes: 3 additions & 0 deletions
3
...sts/Functional/.application/templates/restricting_context_scope/index/with_only.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,3 @@ | ||
{% hook 'with_only' with { | ||
title: 'Only', | ||
} only %} |
3 changes: 3 additions & 0 deletions
3
.../Functional/.application/templates/restricting_context_scope/index/without_only.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,3 @@ | ||
{% hook 'without_only' with { | ||
title: 'Without only', | ||
} %} |
53 changes: 53 additions & 0 deletions
53
src/TwigHooks/tests/Functional/Twig/RestrictingContextScopeTest.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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Functional\Twig; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Twig\Environment as Twig; | ||
|
||
/** | ||
* @group kernel-required | ||
*/ | ||
final class RestrictingContextScopeTest extends KernelTestCase | ||
{ | ||
public function testItRendersSingleHookName(): void | ||
{ | ||
$this->assertSame( | ||
<<<EXPECTED | ||
<!-- BEGIN HOOK | name: "restricting_context_scope.index" --> | ||
<!-- BEGIN HOOKABLE | hook: "restricting_context_scope.index", type: "template", name: "with_only", target: "restricting_context_scope/index/with_only.html.twig", priority: 0 --> | ||
<!-- BEGIN HOOK | name: "restricting_context_scope.index.with_only" --> | ||
<!-- BEGIN HOOKABLE | hook: "restricting_context_scope.index.with_only", type: "template", name: "some", target: "restricting_context_scope/index/block/some.html.twig", priority: 0 --> | ||
Only | ||
is "some" defined: No | ||
is "other" defined: No | ||
<!-- END HOOKABLE | hook: "restricting_context_scope.index.with_only", type: "template", name: "some", target: "restricting_context_scope/index/block/some.html.twig", priority: 0 --> | ||
<!-- END HOOK | name: "restricting_context_scope.index.with_only" --> | ||
<!-- END HOOKABLE | hook: "restricting_context_scope.index", type: "template", name: "with_only", target: "restricting_context_scope/index/with_only.html.twig", priority: 0 --> | ||
<!-- BEGIN HOOKABLE | hook: "restricting_context_scope.index", type: "template", name: "without_only", target: "restricting_context_scope/index/without_only.html.twig", priority: 0 --> | ||
<!-- BEGIN HOOK | name: "restricting_context_scope.index.without_only" --> | ||
<!-- BEGIN HOOKABLE | hook: "restricting_context_scope.index.without_only", type: "template", name: "some", target: "restricting_context_scope/index/block/some.html.twig", priority: 0 --> | ||
Without only | ||
is "some" defined: Yes | ||
is "other" defined: Yes | ||
<!-- END HOOKABLE | hook: "restricting_context_scope.index.without_only", type: "template", name: "some", target: "restricting_context_scope/index/block/some.html.twig", priority: 0 --> | ||
<!-- END HOOK | name: "restricting_context_scope.index.without_only" --> | ||
<!-- END HOOKABLE | hook: "restricting_context_scope.index", type: "template", name: "without_only", target: "restricting_context_scope/index/without_only.html.twig", priority: 0 --> | ||
<!-- END HOOK | name: "restricting_context_scope.index" --> | ||
EXPECTED, | ||
$this->render('restricting_context_scope/index.html.twig'), | ||
); | ||
} | ||
|
||
private function render(string $path): string | ||
{ | ||
/** @var Twig $twig */ | ||
$twig = $this->getContainer()->get('twig'); | ||
|
||
return $twig->render($path); | ||
} | ||
} |