Skip to content

Commit 2dc1486

Browse files
minor #777 Fix/improve code blocks with Symfony's code-block-checker (bocharsky-bw)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Fix/improve code blocks with Symfony's code-block-checker | Q | A | ------------- | --- | Bug fix? | yes | New feature? | yes | Tickets | <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Fix/improve code blocks with https://github.com/symfony-tools/code-block-checker Commits ------- c3baf467 Fix/improve code blocks with Symfony's code-block-checker
2 parents 6e1b2fb + 17424d8 commit 2dc1486

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

@@ -305,7 +310,9 @@ Then specify this new route on the attribute::
305310
// src/Form/FoodAutocompleteField.php
306311
#[AsEntityAutocompleteField(route: 'ux_entity_autocomplete_admin')]
307312
class FoodAutocompleteField
308-
// ...
313+
{
314+
// ...
315+
}
309316

310317
Extending Tom Select
311318
--------------------

src/LiveComponent/doc/index.rst

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

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

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

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

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

484490
.. note::
485491

@@ -495,11 +501,15 @@ Checkboxes, Select Elements Radios & Arrays
495501

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

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

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

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

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

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

524540
.. code-block:: html+twig
525541

@@ -549,8 +565,14 @@ the user to switch the *entity* to another? For example:
549565

550566
To make the ``post`` property itself writable, use ``writable: true``::
551567

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

555577
.. caution::
556578

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

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

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

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

585619
.. note::
586620

@@ -1641,17 +1675,19 @@ Here are some examples of these techniques.
16411675
If you only want to customize some attributes, the simplest to use the options in the form type::
16421676

16431677
// ...
1644-
->add('comments', LiveCollectionType::class, [
1645-
'entry_type' => CommentFormType::class,
1646-
'label' => false,
1647-
'button_delete_options' => [
1648-
'label' => 'X',
1649-
'attr' => [
1650-
'class' => 'btn btn-outline-danger',
1651-
],
1652-
]
1653-
])
1654-
// ...
1678+
$builder
1679+
// ...
1680+
->add('comments', LiveCollectionType::class, [
1681+
'entry_type' => CommentFormType::class,
1682+
'label' => false,
1683+
'button_delete_options' => [
1684+
'label' => 'X',
1685+
'attr' => [
1686+
'class' => 'btn btn-outline-danger',
1687+
],
1688+
]
1689+
])
1690+
;
16551691

16561692
Inline rendering:
16571693

@@ -2011,7 +2047,7 @@ There are three ways to emit an event:
20112047

20122048
class MyComponent
20132049
{
2014-
use ComponentEmitsTrait
2050+
use ComponentEmitsTrait;
20152051

20162052
#[LiveAction]
20172053
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
@@ -589,7 +589,7 @@ updates and deletions of entities::
589589
#[Broadcast] // 🔥 The magic happens here
590590
class Book
591591
{
592-
#[ORM\Column, ORM\Id, ORM\GeneratedValue(strategy="AUTO")]
592+
#[ORM\Column, ORM\Id, ORM\GeneratedValue(strategy: "AUTO")]
593593
public ?int $id = null;
594594

595595
#[ORM\Column]

src/TwigComponent/doc/index.rst

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

311+
.. code-block:: twig
312+
311313
{{ component('alert', {
312314
message: 'Danger Will Robinson!',
313315
autoChooseType: true,

0 commit comments

Comments
 (0)