New in Symfony: the UX initiative, a new JavaScript ecosystem for Symfony

Since its creation, JavaScript has always been focused on creating innovative User Experiences. It lets developers create the most intuitive and usable User Experience possible for a specific problem. In practice however, building great User Experiences with JavaScript is difficult. It takes time to choose reliable packages, to configure them, to integrate them in your pages, and to make your front-end code interact with the rest of your infrastructure. This problem is not new: it looks a whole lot like the state of Symfony in PHP before Symfony Flex. We need a Symfony Flex equivalent for JavaScript: a tool to build amazing User Experiences as quickly as we can now setup an HTTP client, a Mailer or an administration panel. That’s Symfony UX.

Symfony UX: building highly interactive applications by leveraging JavaScript giants¶ Symfony UX is a series of tools to create a bridge between Symfony and the JavaScript ecosystem. It stands on the shoulders of JavaScript giants: npm, Webpack Encore and Stimulus. Symfony UX is not tied to any specific JavaScript framework: you can still use React, Vue or Angular if you love them. It is also opinionated, based on standard HTML and can be progressively adopted in existing applications. Symfony UX consists of three main components:

a Symfony integration for Stimulus to provide a new organization for JavaScript code in applications updates to Symfony Flex and Symfony Webpack Encore to automatically configure JavaScript code shipped by PHP packages a series of core UX packages designed to be reliable and composable to create amazing interfaces quickly

Example: displaying charts in PHP using Symfony UX Chart.js¶ A good example of the power of Symfony UX is the new Symfony UX Chart.js component. This component relies on the Chart.js library internally. To use Symfony UX, first update your Symfony Flex and Webpack Encore dependencies: 1 2composer update symfony/flex yarn upgrade "@symfony/webpack-encore@^0.32.0"

And synchronize your recipes to the latest version: 1composer recipes:install symfony/webpack-encore-bundle --force -v

Note Synchronizing your recipes may override some code of your application. Check manually the result of the command to choose what to keep!

Once updated, Symfony Flex will react to each PHP package you install that contains JavaScript code. For instance, you can now install the Chart.js component: 1$ composer require symfony/ux-chartjs

1 2 3 4 5 6Using version ^1.0 for symfony/ux-chartjs ./composer.json has been updated

Synchronizing package.json with PHP packages Don't forget to run npm or yarn to refresh your Javascript dependencies! ...

Symfony Flex has just synchronized the package.json file of your project with the Chart.js PHP package you installed. You will now find in this file a new JavaScript module: 1 2 3 4 5 6 7// package.json { "devDependencies": { ... "@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/Resources/assets" } }

Symfony Flex also updated a new assets/controllers.json file in your project. This file references all the Stimulus controllers provided by installed Symfony UX packages to let Webpack Encore add them to your JavaScript built files: 1 2 3 4 5 6 7 8 9 10 11 12// assets/controllers.json { "controllers": { "@symfony/ux-chartjs": { "chart": { "enabled": true, "webpackMode": "eager" } } }, "entrypoints": [] }

Because of these changes, you should now install the new JavaScript dependencies and compile the new files: 1 2yarn install --force yarn encore dev

And… that’s it! By leveraging Symfony Flex, Symfony UX Chart.js was installed and configured both as a Symfony bundle in PHP, and as a JavaScript library compiled into your application’s built files. This means you can now build a chart using the bundle: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31// ... use Symfony\UX\Chartjs\Builder\ChartBuilderInterface; use Symfony\UX\Chartjs\Model\Chart;

class HomeController extends AbstractController { /**

  • @Route("/", name="homepage") */ public function index(ChartBuilderInterface $chartBuilder): Response { $chart = $chartBuilder->createChart(Chart::TYPE_LINE); $chart->setData([ 'labels' => ['January', 'February', 'March', 'April', 'May', 'June', 'July'], 'datasets' => [ [ 'label' => 'My First dataset', 'backgroundColor' => 'rgb(255, 99, 132)', 'borderColor' => 'rgb(255, 99, 132)', 'data' => [0, 10, 5, 2, 20, 30, 45], ], ], ]);

    $chart->setOptions([/* ... */]);
    
    return $this->render('home/index.html.twig', [
        'chart' => $chart,
    ]);

    } }

All options and data are provided as-is to Chart.js. You can read Chart.js documentation to discover them all. Discover all the packages of Symfony UX on github.com/symfony/ux!

Let’s build an amazing ecosystem together¶ Symfony UX is an initiative: its aim is to build an ecosystem. To achieve this, we need your help: what other packages could we create in Symfony UX? What about a library that automatically adds an input mask to the text fields of your Symfony forms? Or the ability to make the EntityType render with AJAX auto-completion? Anything you do in JavaScript could be done streamlined as a UX package. We have some ideas and we will release more packages in the coming days. The rest is on us: let’s create an amazing ecosystem together!

                Sponsor the Symfony project.

http://feedproxy.google.com/~r/symfony/blog/~3/fLKQpwmPT6o/new-in-symfony-the-ux-initiative-a-new-javascript-ecosystem-for-symfony

Létrehozva 4y | 2020. dec. 3. 11:20:11


Jelentkezéshez jelentkezzen be

EGYÉB POSTS Ebben a csoportban

SymfonyOnline June 2025: Inside a Financial App Breach: Debugging a Million-Dollar Bug

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

2025. ápr. 22. 13:50:03 | Symfony
New in Symfony 7.3: Invokable Commands and Input Attributes

This is the first article in a series showcasing the most important new features introduced by Symfony 7.3, which will be released at the end of May 2025.

2025. ápr. 22. 9:10:36 | Symfony
A Week of Symfony #955 (April 14–20, 2025)

This week, the upcoming Symfony 7.3 version improved the AsAlias attribute by adding a new argument, introduced Clock support for UriSigner, and refined the return type of the ContainerInterface::get(

2025. ápr. 20. 8:30:06 | Symfony
SymfonyOnline June 2025: Rethinking File Handling in Symfony

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

2025. ápr. 16. 16:30:02 | Symfony
SymfonyLive Paris 2025: Recap and replay!

SymfonyLive Paris 2025 took place three weeks ago — a big thank you to everyone who joined us! The conference was held entirely in French, and now you can relive the best moments: replays, hig

2025. ápr. 15. 14:50:24 | Symfony
A Week of Symfony #954 (April 7–13, 2025)

This week, Symfony 7.3 entered its "feature freeze" period in preparation for its release at the end of May 2025. Development activity focused on refining and polishing its new features, including a n

2025. ápr. 13. 9:40:02 | Symfony
SymfonyOnline June 2025: What's New in Symfony 7.3

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

2025. ápr. 10. 16:40:34 | Symfony