Module Description
This a utility/developer-only module for converting fields from one type to another. E.g., for changing plain text (textarea) fields to filtered text (WYSIWYG), or short text fields to long text. Existing field data is preserved as long as the new field type schema has columns with the same names as the old schema (e.g., "value").

This module is based on the approach outlined in this documentation.

Warnings Supported field types
The script does not take care of differences in column names between the old field schema and the new, so there is potential for data loss depending on the field types being converted from → to. More info regarding the handling of database schema:


* Columns that exist in both old and new field schemas are preserved.
* New columns that didn't exist before are created.
* Old columns that don't exist in the new schema are simply deleted.

Large databases
On very large databases or brittle infrastructure, the database queries to change table columns can timeout, resulting in data loss. Be sure to test this in a staging environment first, and back-up the production database before executing the script. For a low-risk alternative, see the Plain Text as Formatted module.

Usage Implement hook_post_update_NAME() and call FieldTypeConverter::processBatch(). E.g., to convert a plain-text node field named field_foo to long filtered text (i.e., WYSIWYG):

function hook_post_update_NAME(&$sandbox) { $field_map['node'] = [ 'field_foo' => 'text_long', ]; return \Drupal\field_type_converter\FieldTypeConverter::processBatch($sandbox, $field_map); } Then:


* Execute the database updates (docs).
* Visit the "Manage form display" and "Manage display" tabs for the affected entity bundles, and simply re-save the displays. This updates the configuration to match the new field type.
* Export the configuration changes (docs).
* Commit the changes to your code repository.

After deploying the new code to upstream environments, be sure to execute database updates before importing config.

Next steps Consider adding a UI to support changing field types by site builders and other non-developers.

Project Usage
123
Creation Date
Changed Date
Security Covered
Not Covered By Security Advisory
Version Available
Alpha
Module Summary
This module aims to solve the conversion of fields from one type to another, preserving existing field data as long as the new field type schema has columns with the same names as the old schema.
Data Name
field_type_converter

OPENAI CHATBOT

OPENAI CHATBOT

14:34:02
Generic Chatbot
Hi, I'm a Drupal module expert powered by OpenAI, answering your questions about the Drupal module ecosystem. How can I be helpful today? Please note that we will log your question.