Section en-sonata

Sonata Page 5: Adding Open Graph Tags with SonataPage and SonataMediaSonata

Written by admin on 02/10/2023
Category:   Sonata
Tags:  
If you have already used SonataPage and SonataMedia, you know how powerful they are for managing content and media on your site. In this article, I am going to show you how to extend these tools to easily add Open Graph tags to your pages to enhance their sharing on social networks. Why Open Graph tags? Open Graph (OG) tags are meta-tags that you can add to your pages to define titles, descriptions, images, and other information that will be used when the page ...

Sonata: Add an Admin Panel without an Entity with Sonata Admin 5 and Symfony 6.2

Written by admin on 06/06/2023
Category:   Sonata
Tags:  
In this article, we will learn how to add an admin panel without entities in a Symfony 6.2 project using Sonata Admin 5. Our project base will be to create a simple file upload interface. But you could make any application. Including adding simple text. 1. Installing Sonata Admin Bundle If you haven't already installed Sonata Admin, you can do so with composer: composer require sonata-project/admin-bundle We invite you to browse our site to install Son...

Sonata Custom Actions

Written by admin on 19/01/2023
Category:   PHP, Sonata
Tags:  
Following the article written by Thomas Bourdin SYMFONY / SONATA: ADDING A CLONE FUNCTION TO A CRUD, we are going to show how, in a very simple way, we can add custom actions to an interface. On the Dashboard: But we are also going to see how to simply and generically customize the custom actions of the listing, your CRUD’s header and finally how to add actions for batch processing. For my example, I started with a very simple table called ...

Sonata DataMapper and Autowiring

Written by on 08/12/2022
Category:   PHP, Sonata
Tags:  
If you have a specific need to transform data between the form and the recording of your entity and think that this transformation code should be located in a service because it makes more sense, you can use the dataMapper by utilizing the dependency injection provided by Symfony. But how to implement it? A small reminder about the DataMapper. If we agree with the official Symfony documentation regarding DataMapper and DataTransformer, a dataMapper has the responsibility to read and write an ...

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

Written by admin on 27/11/2022
Category:   PHP, Sonata
Tags:   sonata, symfony, admin
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 6 / Sonata 5: Installing SonataClassification.

Written by on 14/03/2022
Category:   PHP, Sonata
Tags:  
We have seen in previous articles how to initialize a Symfony 6 + Sonata 5 project with media and users in a secure admin. We then looked at how to manage user localizations.Now we will see how to install and manage classifications. We proceed with the installation of the latest version to date. php8.1 composer.phar require sonata-project/classification-bundle:5.x-dev Apparently, we have a configuration error. Unrecognized option "media" under "sonata_classification.class". Availabl...

Symfony 6 / Sonata 5: Link locales and timezone to user preferences.

Written by admin on 10/03/2022
Category:   PHP, Sonata
Tags:  
We saw in a previous article how to install Symfony 6 + Sonata Admin 5 with user and media management. We will continue this installation with the configuration of languages and time zones. We will install intlBundle which allows to manage localized display. php8.1 composer.phar require sonata-project/intl-bundle We take this opportunity to add a timezone and locale field to the user.To do this, we will extend userBundle and add a field in the admin...

Symfony 6 / Sonata 5: Initialize a Symfony 6 + Sonata Admin 5 + UserBundle + MediaBundle project

Written by admin on 10/03/2022
Category:   PHP, Sonata
Tags:  
Here are the commands to initialize a Symfony project with a secure admin. To run Symfony 6 we will need to install php8.0 or php8.1 For php8.0 sudo apt-get install php8.0-cli libapache2-mod-php8.0 php8.0-common php8.0-opcache php8.0-igbinary php8.0-imagick php8.0-msgpack php8.0-readline php8.0-memcached php8.0-xml php8.0-mbstring php8.0-gd php8.0-mysql php8.0-curl php8.0-intl php8.0-memcache php8.0-memcached memcached libapache2-mod-php8.0 php8.0-zip php8.0-mysql For...

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

Written by on 06/11/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
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 Multi-Language Admin Interface

Written by on 30/10/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
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: Manage a Multi-Server Admin Interface

Written by admin on 11/09/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
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: Use json fields

Written by on 10/09/2020
Category:   PHP, Sonata
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

Written by on 09/09/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
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 configuration interface.

Written by on 23/08/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
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: Create a REST API

Written by admin on 18/08/2020
Category:   PHP, Sonata
Tags:   symfon, sonata, api, swagger
In this article, we will see how to create a REST API with FOS/RestBundle, including authentication, and a Swagger-like documentation generator. List of necessary bundles:friendsofsymfony/rest-bundle: Provides a set of tools to help develop a RESTful APIhttps://github.com/FriendsOfSymfony/FOSRestBundlejms/serializer-bundle: Allows object serialization.https://packagist.org/packages/jms/serializer-bundlelexik/jwt-authentication-bundle: Manages JSON web tokens.htt...

Symfony 4 / Sonata: Install the Sonata Page CMS

Written by on 07/07/2020
Category:   PHP, Sonata
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 ...

Symfony 4 / Sonata: Create a CSV export page

Written by on 02/04/2020
Category:   PHP, Sonata
Tags:   sonata, export, csv, symfony
The default interfaces of Sonata are CRUDs. This is incredibly practical (otherwise, we wouldn't use it). But an administration is not only composed of CRUDs. Here we will see how to create a simple data export page, by removing the default views of the interfaces, and creating our own to manage our export button. 1 – Adding the export library composer require sonata-project/exporter We then need to add a configuration file for our exporter. #config/packag...

Symfony 4/ Sonata: Create a Nested Interface

Written by on 02/03/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
We are going to see how to build an admin interface composed of several tables that have Many2Many relationships.Let's revisit our example of a many/many interface available hereWe have a zone table, which is made up of several elements of the departments table. On these departments, we have agencies.To top it off, and to give meaning to this data chain, we add a zx_credential table, which represents salespeople.Here is our data chain: Salespeople->Zones->Departments->Agencies. ...

Symfony4 / Sonata: Create a Many/Many Admin

Written by on 01/03/2020
Category:   PHP, Sonata
Tags:   sonata, symfony
We will develop here all the manipulations to build a many to many interface via Sonata.We will take as an example a zone management with a connection by departments. Each zone is thus constituted of multiple connections with the department table.In MysqlWorkbench, it looks like this: To generate the entities, we use the following command: php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity Next, we ...

Symfony 4 / Sonata: Create a nested CRUD interface (child 1->N) with drag'n drop ordering

Written by admin on 21/02/2020
Category:   PHP, Sonata
In short, we want to create a CRUD interface, 1N, with which, when we are editing an item, we add a panel to manage all the child items.Here we have a wtype table, with a wconf table that contains a series of records linked to a wtype item. Just like for the implementation example of sortable with drag'n'drop ( available here ) we are going to use the following components:pixassociates/sortable-behavior-bundle and stof/doctrine-extension...