Replacing an Entry Type field with another field while maintaining the content #15814
-
We have a "Plain Text" field which we would like to replace with a CKEditor field. Now I know it is possible to just change the field configuration to a CKEditor, but we use the same field in different Entry Types where it need to stay as a "Plain Text" field. Is there a way to "replace" the field while keeping the content or a way to migrate the data? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can create a new CKEditor field, attach it to the entry type(s) you wish to use it on, and then populate it with values from the original Plain Text field using the php craft resave/entries --type myEntryType --set myCkeditorField --to myPlainTextField Or if the Plain Text field isn’t currently storing HTML, you can wrap its values in a php craft resave/entries --type myEntryType --set myCkeditorField \
--to "fn(\$entry) => sprintf('<p>%s</p>', (string)\$entry->myPlainTextField)" Once you’ve done that and verified the CKEditor fields look right (on all environments), you can remove the Plain Text field from the entry type(s) it’s no longer needed on. |
Beta Was this translation helpful? Give feedback.
You can create a new CKEditor field, attach it to the entry type(s) you wish to use it on, and then populate it with values from the original Plain Text field using the
resave/entries
command:Or if the Plain Text field isn’t currently storing HTML, you can wrap its values in a
<p>
tag:php craft resave/entries --type myEntryType --set myCkeditorField \ --to "fn(\$entry) => sprintf('<p>%s</p>', (string)\$entry->myPlainTextField)"
Once you’ve done that and verified the CKEditor fields look right (on all environments), you can remove the Plain Text field from the entry type(s) it’s no longer needed on.