Is it possible to change an existing text field (that already has data in it) from a long text field to a long text field with summary? If so, how would I go about it?

Is there a way to do it within the CMS, or would I have to do a similar thing  to what's described here: https://forum.backdropcms.org/forum/how-programmatically-change-type-sav...?

Thanks.

Most helpful answers

There isn't a way to change the type of a field within the CMS.  "Long text" and "Long text with summary" are different field types and have different columns in their tables, not to mention widgets and formatters.

So, AFAIK, currently the only way is to add another field to the content type, and then programmatically, loop through the  nodes, get the values and formats of for the long text with summary field, and assign it to the long text field and save the node. Then delete the long text with summary field. 

I think it would be a similar way, but is there any reason to do this? Why not just create a summary field? It will be easier to get the results you want in views if you have full control over the two elements.

There is a long standing issue to remove this field type, but it has not moved forward in many years.

Comments

I think it would be a similar way, but is there any reason to do this? Why not just create a summary field? It will be easier to get the results you want in views if you have full control over the two elements.

There is a long standing issue to remove this field type, but it has not moved forward in many years.

@yorkshirepudding - If I switch to a new summary field, I have concerns about 2 things.

1. Is the text_summary function the right one to use to create default summaries for existing (100s of) nodes?

2. How would the summary field be populated for new nodes? I don't want users or editors to have to create them manually for every node.

For my use case, the old <!--break--> delimiter would be perfect. Too bad it doesn't work with CKEditor.

@leeksoup

1. I've never actually done this but looking at the function definition it should work.

2. I'm not aware of any method to do this, but in theory, it would be possible to automate; it's just not something I've ever looked at.

There isn't a way to change the type of a field within the CMS.  "Long text" and "Long text with summary" are different field types and have different columns in their tables, not to mention widgets and formatters.

So, AFAIK, currently the only way is to add another field to the content type, and then programmatically, loop through the  nodes, get the values and formats of for the long text with summary field, and assign it to the long text field and save the node. Then delete the long text with summary field. 

@yorkshirepudding, @argiepiano - thanks!

I will have to think which option makes more sense for my use case. If I add a summary field, I will have to also update all the views that currently use Content | Teaser. Hmm ...