I am updating nodes on my site using my new custom module, and I've run into something annoying. Almost all these nodes have a body field that was originally either hand-coded or with some old Drupal WYSIWYG module that saved line breaks as <br>
tags. Their format now has CKE5 enabled and the display (full node display) runs all the paragraphs together even though the break tags are in there.
If I manually open a node, I can see that there is a banner asking me to click a link to enable CKE5, but even then, the paragraphs do not display properly. E.g.
Looking at the HTML source window, it is clear that the new <p>
tags are wrapped around the whole thing.
<p>
I am updating nodes on my site using my new custom module, and I've run into something annoying. Almost all these nodes have a body field that was originally either hand-coded or with some old Drupal WYSIWYG module that saved line breaks as <code class="php"><br></code> tags. Their format now has CKE5 enabled and the display (full node display) runs all the paragraphs together even though the break tags are in there.<br>
<br>
<a href="https://www.authorssite.com/single_product.cfm?product_id=13">See and hear samples on the author's Website</a><br>
<br>
</p>
The strange thing is that visually, it looks correct in the CKE5 window:
So, is there a way for me to fix this from code? Two things to be done:
-
Making the output respect the
<br>
tags. Or converting them into<p>
tags, or something ... - Enabling CKE5 for the field ... though maybe this is not essential. Idk.
I don't fancy manually editing a couple thousand nodes....
With the help of the Backdrop office hours crew, I was able to figure out a solution that works for me.
I just added an explicit format setting to the long-text field before saving it, something like this:
// set $body_value to updated value replacing <br> tags with <p> tags
$wrapper->body = array('value' => $body_value, 'format'=>1, 'safe_value' => '');
$node->save();
... and now it works! (CKE5 will have to be enabled when someone goes in to edit it manually, but the display is correct.)