Discuss your project

Topic

symfony

18 articles

Sonata Extra Bundle: application firewall

The SonataExtraBundle provides a set of enhanced features for managing firewall rules in the Sonata Admin environment. This bundle allows administrators to create and manage rules to filter requests based on different criteria such as forbidden words, IP addresses, and user agents.

SF6 / Sonata 5: Managing a OneToMany interface in a CRUD with Sonata's CollectionType

In this example, we will take the concrete case of a simple interface that includes multiple elements. We have chosen to use a "Projects" table in which we will assign documents. Therefore, for a project, we can assign several documents. And to facilitate administration, we will ensure that we can manage our nested interface directly within the edit view of our project.We need to create the schema. Firstly, we import our current schema into MysqlWorbench usi...

Symfony 4 / Sonata: Create a second interface with the same entity

Here we will see how to create a second interface while the entity is already in use in a CRUD interface.The problem with automatically generated interfaces is that they use the name of the entity to construct the routes.If we configure a second interface with an entity that is already used, we will end up with the same route as the first.To address this issue, we will use these two parameters in our admin class to override the default values.Suppose we are using the entity "model", we could...

Symfony 4 / Sonata: managing a multilingual administration interface

We will see how to set up a multilingual admin interface with a language selection button (language switcher).Installing translationBundle composer require sonata-project/translation-bundle bin/console assets:install The language switcher requires a specific twig filter.Otherwise, you will get an error like:Unknown "language_name" filter.Then, you need to install these two bundles composer require twig/intl-extra composer require twig/extra-bundle bin/console cache:clear We add the default c...

Symfony 4 / Sonata: managing a multi-server administration interface

We will see how to manage an admin interface that connects to multiple servers.In our example, we have set up a default MySQL server that manages our admin interface. Users, media, etc.And we have set up a PostgreSQL server that contains a table we wish to manage.We can add as many servers as we wish. Our MySQL Server We have traditionally set up a Symfony Sonata instance by default with a classic MySQL connection. So we can create our database, the schema, and...

Symfony 4 / Sonata: Using JSON fields

We are going to see how to exploit Jsonb field types from PostgreSQL in a generated interface of Sonata.We start with the assumption that you already master the basic concepts of Symfony, Sonata, and PostgreSQL.First, let's create a simple table in PostgreSQL that will contain a Jsonb field. CREATE SEQUENCE public.table1_id_seq; CREATE TABLE public.table1 ( id integer DEFAULT nextval('public.table1_id_seq'::regclass) NOT NULL, var1 character varying(250...

Symfony 4 / Sonata: create a custom form field type

We are going to see how we can create a custom field type. In our example, we want a field that has the same rendering as a MoneyType field but in which we can add any suffix, as the money field only accepts currencies. However, in our project we want to use kilograms, months or even kilometers. In short, a whole range of possible data types.We start by creating our Type class: <?php // src/Form/Type/NumberSuffixType.php namespace App\Form\Type; use Symfony\Component\Form\AbstractType; u...

Symfony 4 / Sonata: Create a settings interface.

One of the recurring needs of a web project is the need for global parameters for your application. Generally, these are stored in a yml file and that's all you need. But it gets complicated when the client asks to be able to have control over them.Give them FTP/SSH access to modify them? No, definitely not. Especially if it’s to delegate this task to an intern.You will need to provide them with an admin interface with a form to be able to modify these parameters.In our case, we only need a ...

Symfony 4 / Sonata: Install the Sonata Page CMS

Sonata is a suite of bundles for Symfony 4. One of which allows for content management in a WordPress-like manner.There is little documentation available on the internet, and for good reason, the installation is bugged, and the few people who have dealt with the bug tracker on GitHub, have been bluntly told to RTFM.Staying put with such failure is not really my style.Here's how to install and configure Sonata-Page-Bundle, with the official installation, and the workarounds for these F###ing ...