Skip to content

Commit

Permalink
feature #2073 [Map] Rename render_map Twig function ux_map (smnan…
Browse files Browse the repository at this point in the history
…dre)

This PR was merged into the 2.x branch.

Discussion
----------

[Map] Rename `render_map` Twig function `ux_map`

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| Issues        | Fix #...
| License       | MIT

### Context

As we recently saw with the `cva` function and forgot to do here: we should prefix every new component / package / Twig function or filter with `ux` to avoid conflict with existing codebases... and with future symfony or twig new methods.

### This PR

This PR renames `render_map` (inspired by charts hjs "render_chart") into `ux_map` (in line with what we did for UX Icons)

```diff
<div>
-    {{ render_map(map) }}
+    {{ ux_map(map) }}
</div>
```

### Next

We can keep the render_map for _some_ time, but it's marked as deprecated right now, and i think this is the good moment to update documentation, to limit future BC break / changes for users (even if we are in experimental)

### Website

Once this once is merged, the website page will need to be updated

Commits
-------

b539c1a Rename `render_map` Twig function `ux_map`
  • Loading branch information
kbond committed Aug 20, 2024
2 parents 2ded754 + b539c1a commit 4bb9ee7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/Map/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

## Unreleased

- Rename `render_map` Twig function `ux_map`
- Deprecate `render_map` Twig function

## 2.19

- Component added
8 changes: 4 additions & 4 deletions src/Map/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ A map is created by calling ``new Map()``. You can configure the center, zoom, a
}
}

To render a map in your Twig template, use the ``render_map`` Twig function, e.g.:
To render a map in your Twig template, use the ``ux_map`` Twig function, e.g.:

.. code-block:: twig
{{ render_map(my_map) }}
{{ ux_map(my_map) }}
{# or with custom attributes #}
{{ render_map(my_map, { style: 'height: 300px' }) }}
{{ ux_map(my_map, { style: 'height: 300px' }) }}
Extend the default behavior
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -207,7 +207,7 @@ Then, you can use this controller in your template:

.. code-block:: twig
{{ render_map(my_map, { 'data-controller': 'mymap', style: 'height: 300px' }) }}
{{ ux_map(my_map, { 'data-controller': 'mymap', style: 'height: 300px' }) }}
Backward Compatibility promise
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Map/src/Bridge/Google/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ A common use case is to customize the marker. You can listen to the `ux:map:mark

Assuming you have a map with a custom controller:
```twig
{{ render_map(map, {'data-controller': 'my-map' }) }}
{{ ux_map(map, {'data-controller': 'my-map' }) }}
```

You can create a Stimulus controller to customize the markers before they are created:
Expand Down
2 changes: 1 addition & 1 deletion src/Map/src/Bridge/Leaflet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ A common use case is to customize the marker. You can listen to the `ux:map:mark

Assuming you have a map with a custom controller:
```twig
{{ render_map(map, {'data-controller': 'my-map' }) }}
{{ ux_map(map, {'data-controller': 'my-map' }) }}
```

You can create a Stimulus controller to customize the markers before they are created:
Expand Down
8 changes: 7 additions & 1 deletion src/Map/src/Twig/MapExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ final class MapExtension extends AbstractExtension
{
public function getFunctions(): iterable
{
yield new TwigFunction('render_map', [Renderers::class, 'renderMap'], ['is_safe' => ['html']]);
yield new TwigFunction('render_map', [Renderers::class, 'renderMap'], [
'is_safe' => ['html'],
'deprecated' => '2.20',
'deprecating_package' => 'symfony/ux-map',
'alternative' => 'ux_map',
]);
yield new TwigFunction('ux_map', [Renderers::class, 'renderMap'], ['is_safe' => ['html']]);
}
}
2 changes: 1 addition & 1 deletion src/Map/tests/TwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testRenderMap(): void
$twig = self::getContainer()->get('twig');
$twig->setLoader(new ChainLoader([
new ArrayLoader([
'test' => '{{ render_map(map, attributes) }}',
'test' => '{{ ux_map(map, attributes) }}',
]),
$twig->getLoader(),
]));
Expand Down

0 comments on commit 4bb9ee7

Please sign in to comment.