ExpressionEngine allows you to natively, enforce or re-enforce format changes on a field.
This should be done before the switch to Espresso field_type.
Go to Admin and Select Channel Fields

Go to the field you want to transition to Espresso. Switch the field's default formatting.

You'll note an update option appears in orange under the format type once you've switched. This option will allow you to propagate the change to all entries, using the field.
This is the simplest option.
Unfortunately, with Expresso field_type, you want to do some of these modifications, BEFORE you switch field_types. For example, if you where using XHTML
formatting. You'd want to switch that to <br />
to preserve white space, before switching to Espresso. Why? Because the white space under the current XHTML
formatting doesn't actually use <p>
or <br />
tags and Espresso doesn't recognize new line \r
or \n
marks.
If you've ALREADY switched field types and lost all your white space, the easiest way to return it, is rollback your database, perform the switches to the field before changing field_type. Because restoring whitespace after the fact is pretty much a manual operation.
UPDATED
If you want to add the paragraph tags to the field, you can do so by running a MySQL update query:
UPDATE exp_channel_data SET field_id_### = REPLACE(field_id_###, '\r', '</p><p>') WHERE channel_id IN('3');
UPDATE exp_channel_data SET field_id_### = REPLACE(field_id_###, '\n', '</p><p>') WHERE channel_id IN('3');
Basically, for the specified field, in the specified channel, you are finding return marks
replacing them with a close than open paragraph tag, then doing the same for the new lines
. This works fine, with one exception, 'It doesn't provide the initial 'open' or the last 'close' paragraph tag. You can of course, do so on the template, by enclosing the field like so
<p>{expresso-field}</p>
or, you can drop into PHP to do it. Since we didn't want to modify a number of templates, one of our consultants (Joe Chellman) whipped up this
$db = mysql_connect ('ip_address', 'account', 'password');
mysql_select_db ( 'database' );
mysql_set_charset ( 'utf8' );
$q = "SELECT entry_id, field_id_XXX FROM exp_channel_data WHERE channel_id='##' AND field_id_XXX like '%\n%' AND field_id_XXX not like '%<p>%'";
$result = mysql_query($q);
while ($row = mysql_fetch_object ( $result )) {
$entry_id = $row->entry_id;
$body = $row->field_id_XXX;
// recut the text
$body = mysql_real_escape_string(paraWrapper($body));
// put it back
$restoreQuery = "UPDATE exp_channel_data SET field_id_XXX = '$body' WHERE entry_id = $entry_id";
// print $restoreQuery . "\n";
// print $query2 . "\n";
$restoreResult = mysql_query($restoreQuery);
if (mysql_errno () != 0) {
print 'Error on update for ' . $entry_id . ':' . mysql_error() . "\n";
} else {
print "Update of $entry_id successful.\n";
}
}
// will you convert?!
// $q_convert = 'UPDATE exp_channel_fields SET field_type = "expresso" WHERE field_id = XX';
function paraWrapper($text) {
$text = str_replace (array('<br><br>', '<br /><br />'), array('', ''), $text);
return "<p>" . implode( "</p>\n\n<p>", preg_split( '/\n(?:\s*\n)+/', $text ) ) . "</p>";
}
The XXX
, XX
, and ##
are where field numbers, channel id's are needed. The last part of the script, also finishes the conversion of the field, from text to espresso. Of course, that's all in a PHP script.