Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Transform field content from text to richtext

Hello,
I need to transform a simple text into richtext (RTE) without losing the content. How do I do this?
Cordially,

1 Like

I think you should not start first writing a script for that purpose (s below) . You have to make some analysis before. In such cases I will first check the number of objects for this contenttype, just to have an Idea about the script running time later. Second, It is much more easier to work with one object version and to remove old ones before. You can find a clean version script provided by Ibexa in the documentation. of course you have to save your DB before.
Now is time for the script.
Basically, you need to add the RTE fieldtype to your content. The decision to make this field searchable is very important regarding your legacy or solr seach index.
The ContentService is the right service to use. Basically is an ETL Process using symfony command : load, transform and update content for the contenttype in use. You can refer to this example: https://www.ibexa.co/blog/converting-image-fields-to-use-the-image-asset-field-type-in-ez-platform
If you have some HTML code in the text field you should analyse that first during the transformation process.This is where you will spent the most effort. Not sure but maybe you can find some converter examples here:https://github.com/ezsystems/ezplatform-xmltext-fieldtype. I will not exclude simple PHP replace mecanism in this process but you should know about the xml format (links, lists, custom tags(if you have some iframes e.g youtube,instagram code in text) etc…)of the RTE.
Integration test might be helpful. You can test using a test contenttype which has only both fields.
The script is in that case is a sync process and if you have a large amount of content I would look into symfony messenger and async processing first :slight_smile:
I hope above information could help you.

1 Like

Thank you for this answer, I will work on your indications :slight_smile:

@ da_real raises a good question. Is there html in the existing text field?

Another lead :

Add a rich text field parallel to the text field.
It is very well done with the kaliopMigrationBundle.

In the rendering of the object display the rich text field if it is not empty. Otherwise display the text field.

In the admin, specify that the text field is deprecated and invite the admin to enter the rich text field.

This technique allows for a smooth transition.

Good idea i use this thanks you