Skip to content

Commit c3baf46

Browse files
bocharsky-bwweaverryan
authored andcommitted
Fix/improve code blocks with Symfony's code-block-checker
1 parent d8fe5c7 commit c3baf46

File tree

5 files changed

+90
-46
lines changed

5 files changed

+90
-46
lines changed

src/Autocomplete/doc/index.rst

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,27 @@ to the options above, you can also pass:
229229

230230
use Symfony\Component\Security\Core\Security;
231231

232-
'security' => function(Security $security): bool {
233-
return $security->isGranted('ROLE_FOO');
234-
}
232+
[
233+
'security' => function(Security $security): bool {
234+
return $security->isGranted('ROLE_FOO');
235+
},
236+
];
235237

236238
``filter_query`` (default: ``null``)
237239
If you want to completely control the query made for the "search results",
238240
use this option. This is incompatible with ``searchable_fields``::
239241

240-
'filter_query' => function(QueryBuilder $qb, string $query, EntityRepository $repository) {
241-
if (!$query) {
242-
return;
243-
}
242+
[
243+
'filter_query' => function(QueryBuilder $qb, string $query, EntityRepository $repository) {
244+
if (!$query) {
245+
return;
246+
}
247+
248+
$qb->andWhere('entity.name LIKE :filter OR entity.description LIKE :filter')
249+
->setParameter('filter', '%'.$query.'%');
250+
},
251+
];
244252

245-
$qb->andWhere('entity.name LIKE :filter OR entity.description LIKE :filter')
246-
->setParameter('filter', '%'.$query.'%');
247-
}
248253
``max_results`` (default: 10)
249254
Allow you to control the max number of results returned by the automatic autocomplete endpoint.
250255

@@ -306,7 +311,9 @@ Then specify this new route on the attribute::
306311

307312
#[AsEntityAutocompleteField(route: 'ux_entity_autocomplete_admin')]
308313
class FoodAutocompleteField
309-
// ...
314+
{
315+
// ...
316+
}
310317

311318
Extending Tom Select
312319
--------------------

src/LiveComponent/doc/index.rst

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ By default, the user can't change the *properties* of an object ``LiveProp``
449449
public Post $post;
450450

451451
#[LiveProp(writable: ['allow_markdown'])]
452-
public array $options = ['allow_markdown' => true, 'allow_html' => false]
452+
public array $options = ['allow_markdown' => true, 'allow_html' => false];
453453
}
454454

455455
Now ``post.title``, ``post.content`` or ``options.allow_markdown`` can be used like
@@ -476,11 +476,17 @@ Any other properties on the object (or keys on the array) will be read-only.
476476
For arrays, you can set ``writable: true`` to allow *any* key in the array to be
477477
changed, added or removed::
478478

479-
#[LiveProp(writable: true)]
480-
public array $options = ['allow_markdown' => true, 'allow_html' => false];
479+
#[AsLiveComponent('edit_post')]
480+
class EditPostComponent
481+
{
482+
// ...
481483

482-
#[LiveProp(writable: true)]
483-
public array $todoItems = ['Train tiger', 'Feed tiger', 'Pet tiger'];
484+
#[LiveProp(writable: true)]
485+
public array $options = ['allow_markdown' => true, 'allow_html' => false];
486+
487+
#[LiveProp(writable: true)]
488+
public array $todoItems = ['Train tiger', 'Feed tiger', 'Pet tiger'];
489+
}
484490

485491
.. note::
486492

@@ -496,11 +502,15 @@ Checkboxes, Select Elements Radios & Arrays
496502

497503
Checkboxes can be used to set a boolean or an array of strings::
498504

499-
#[LiveProp(writable: true)]
500-
public bool $agreeToTerms = false;
505+
#[AsLiveComponent('edit_post')]
506+
class EditPostComponent
507+
{
508+
#[LiveProp(writable: true)]
509+
public bool $agreeToTerms = false;
501510

502-
#[LiveProp(writable: true)]
503-
public array $foods = ['pizza', 'tacos'];
511+
#[LiveProp(writable: true)]
512+
public array $foods = ['pizza', 'tacos'];
513+
}
504514

505515
In the template, setting a ``value`` attribute on the checkbox will set that
506516
value on checked. If no ``value`` is set, the checkbox will set a boolean value:
@@ -516,11 +526,17 @@ value on checked. If no ``value`` is set, the checkbox will set a boolean value:
516526
``select`` and ``radio`` elements are a bit easier: use these to either set a
517527
single value or an array of values::
518528

519-
#[LiveProp(writable: true)]
520-
public string $meal = 'lunch';
529+
#[AsLiveComponent('edit_post')]
530+
class EditPostComponent
531+
{
532+
// ...
533+
534+
#[LiveProp(writable: true)]
535+
public string $meal = 'lunch';
521536

522-
#[LiveProp(writable: true)]
523-
public array $foods = ['pizza', 'tacos'];
537+
#[LiveProp(writable: true)]
538+
public array $foods = ['pizza', 'tacos'];
539+
}
524540

525541
.. code-block:: twig
526542
@@ -550,8 +566,14 @@ the user to switch the *entity* to another? For example:
550566
551567
To make the ``post`` property itself writable, use ``writable: true``::
552568

553-
#[LiveProp(writable: true)]
554-
public Post $post;
569+
use App\Entity\Post;
570+
571+
#[AsLiveComponent('edit_post')]
572+
class EditPostComponent
573+
{
574+
#[LiveProp(writable: true)]
575+
public Post $post;
576+
}
555577

556578
.. caution::
557579

@@ -562,8 +584,14 @@ To make the ``post`` property itself writable, use ``writable: true``::
562584
If you want the user to be able to change the ``Post`` *and* certain
563585
properties, use the special ``LiveProp::IDENTITY`` constant::
564586

565-
#[LiveProp(writable: [LiveProp::IDENTITY, 'title', 'content'])]
566-
public Post $post;
587+
use App\Entity\Post;
588+
589+
#[AsLiveComponent('edit_post')]
590+
class EditPostComponent
591+
{
592+
#[LiveProp(writable: [LiveProp::IDENTITY, 'title', 'content'])]
593+
public Post $post;
594+
}
567595

568596
Note that being able to change the "identity" of an object is something
569597
that works only for objects that are dehydrated to a scalar value (like
@@ -579,9 +607,15 @@ when they are sent back to the backend.
579607
If needed, you can control the normalization or denormalization context using
580608
the ``Context`` attribute from Symfony's serializer::
581609

582-
#[LiveProp]
583-
#[Context(groups: ['my_group'])]
584-
public Post $post;
610+
use App\Entity\Post;
611+
612+
#[AsLiveComponent('edit_post')]
613+
class EditPostComponent
614+
{
615+
#[LiveProp]
616+
#[Context(groups: ['my_group'])]
617+
public Post $post;
618+
}
585619

586620
.. note::
587621

@@ -1644,17 +1678,19 @@ Here are some examples of these techniques.
16441678
If you only want to customize some attributes, the simplest to use the options in the form type::
16451679

16461680
// ...
1647-
->add('comments', LiveCollectionType::class, [
1648-
'entry_type' => CommentFormType::class,
1649-
'label' => false,
1650-
'button_delete_options' => [
1651-
'label' => 'X',
1652-
'attr' => [
1653-
'class' => 'btn btn-outline-danger',
1654-
],
1655-
]
1656-
])
1657-
// ...
1681+
$builder
1682+
// ...
1683+
->add('comments', LiveCollectionType::class, [
1684+
'entry_type' => CommentFormType::class,
1685+
'label' => false,
1686+
'button_delete_options' => [
1687+
'label' => 'X',
1688+
'attr' => [
1689+
'class' => 'btn btn-outline-danger',
1690+
],
1691+
]
1692+
])
1693+
;
16581694

16591695
Inline rendering:
16601696

@@ -2014,7 +2050,7 @@ There are three ways to emit an event:
20142050

20152051
class MyComponent
20162052
{
2017-
use ComponentEmitsTrait
2053+
use ComponentEmitsTrait;
20182054

20192055
#[LiveAction]
20202056
public function saveProduct()

src/Notify/doc/index.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ properly configured notifier transport:
3434

3535
.. code-block:: yaml
3636
37-
// config/packages/notifier.yaml
38-
37+
# config/packages/notifier.yaml
3938
framework:
4039
notifier:
4140
chatter_transports:

src/Turbo/doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ updates and deletions of entities::
591591
#[Broadcast] // 🔥 The magic happens here
592592
class Book
593593
{
594-
#[ORM\Column, ORM\Id, ORM\GeneratedValue(strategy="AUTO")]
594+
#[ORM\Column, ORM\Id, ORM\GeneratedValue(strategy: "AUTO")]
595595
public ?int $id = null;
596596

597597
#[ORM\Column]

src/TwigComponent/doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ i.e. because they don't correspond to any property. You can handle and remove th
310310
here. For example, imagine an extra ``autoChooseType`` prop were passed when
311311
creating the ``alert`` component::
312312

313+
.. code-block:: twig
314+
313315
{{ component('alert', {
314316
message: 'Danger Will Robinson!',
315317
autoChooseType: true,

0 commit comments

Comments
 (0)