I have customized CiviCase for a client who is using it to manage project grants. Things have gone pretty well overall. There are many custom fields and several related document templates in use. "Print/Merge Document" works fine when generating a pdf, but often fails when generating a docx file.
The error that is generated on screen is simply "Cannot add TextRun in TextRun.", but looking into the CiviCRM log shows a little more detail and that the error is in the 3rd-party phpoffice code (which I've never heard of before today).
$Fatal Error Details = array:3 [
"message" => "Cannot add TextRun in TextRun."
"code" => null
"exception" => BadMethodCallException {#12247
#message: "Cannot add TextRun in TextRun."
#code: 0
#file: "/var/www/sitename/wordpress/wp-content/plugins/civicrm/civicrm/vendor/phpoffice/phpword/src/PhpWord/Element/AbstractContainer.php"
#line: 266
...
/var/www/sitename/wordpress/wp-content/plugins/civicrm/civicrm/CRM/Utils/PDF/Document.php:90 {
CRM_Utils_PDF_Document::html2doc($pages, $fileName, $format = [])
› $section = $phpWord->addSection($pageStyle + ['breakType' => 'nextPage']);
› \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
› }
The error only occurs when one of the custom fields of type "Rich Text Editor" is populated. All of the simpler fields seem fine. I'm not familiar with this code and so am not really sure whether this is a bug (and out of my power to fix) or some glitch in my custom fields that should be corrected.
Any thoughts?
UPDATE: Converting the rich text field type to multi-line text didn't fix the problem. Accented characters were converted to html entities and paragraph tags were added (or maybe kept) in the filed conversion. However, deleting the content and re-adding it as UTF-8 text with the accents into the multi-line field did prevent the error. I guess there is a bug in the phpoffice code with respect to html entities. Changing the field type is not a fix, but I may be able to live with it if there is no better solution.
Running CiviCRM 5.61.0 on WordPress 6.2.2 on Debian Bullseye