Skip to content

Commit cc76ff0

Browse files
committed
minor #916 [LiveComponent] Updating docs to use .defaults() method (weaverryan)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [LiveComponent] Updating docs to use .defaults() method | Q | A | ------------- | --- | Bug fix? | yes (to docs) | New feature? | no | Tickets | None - reported on Slack | License | MIT The TwigComponent docs were updated previously, but not LiveComponent. Cheers! Commits ------- 607e6b5 [LiveComponent] Updating docs to use .defaults() method
2 parents e74d82b + 607e6b5 commit cc76ff0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,15 +839,17 @@ The following hooks are available (along with the arguments that are passed):
839839
Adding a Stimulus Controller to your Component Root Element
840840
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
841841

842-
.. versionadded:: 2.7
842+
.. versionadded:: 2.9
843843

844-
The ``add()`` method was introduced in TwigComponents 2.7.
844+
The ability to use the ``defaults()`` method with ``stimulus_controller()``
845+
was added in TwigComponents 2.9 and requires ``symfony/stimulus-bundle``.
846+
Previously, ``stimulus_controller()`` was passed to ``attributes.add()``.
845847

846848
To add a custom Stimulus controller to your root component element:
847849

848850
.. code-block:: html+twig
849851

850-
<div {{ attributes.add(stimulus_controller('my-controller', { someValue: 'foo' })) }}>
852+
<div {{ attributes.defaults(stimulus_controller('my-controller', { someValue: 'foo' })) }}>
851853

852854
Loading States
853855
--------------

src/LiveComponent/tests/Integration/LiveComponentHydratorTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -899,28 +899,29 @@ public function dehydrateDate()
899899
return [
900900
'year' => $this->createdAt->format('Y'),
901901
'month' => $this->createdAt->format('m'),
902+
'day' => $this->createdAt->format('d'),
902903
];
903904
}
904905

905906
public function hydrateDate($data)
906907
{
907908
return \DateTime::createFromFormat(
908-
'Y-m',
909-
sprintf('%s-%s', $data['year'], $data['month'])
909+
'Y-m-d',
910+
sprintf('%s-%s-%s', $data['year'], $data['month'], $data['day'])
910911
);
911912
}
912913
})
913914
->mountWith([
914915
'createdAt' => new \DateTime('2023-03-05 9:23', new \DateTimeZone('America/New_York')),
915916
])
916917
->assertDehydratesTo([
917-
'createdAt' => ['year' => 2023, 'month' => 3],
918+
'createdAt' => ['year' => 2023, 'month' => 3, 'day' => 5],
918919
])
919920
->userUpdatesProps([
920-
'createdAt' => ['year' => 2024, 'month' => 4],
921+
'createdAt' => ['year' => 2024, 'month' => 4, 'day' => 5],
921922
])
922923
->assertObjectAfterHydration(function (object $object) {
923-
$this->assertSame('2024-04', $object->createdAt->format('Y-m'));
924+
$this->assertSame('2024-04-05', $object->createdAt->format('Y-m-d'));
924925
})
925926
;
926927
}];

0 commit comments

Comments
 (0)