Updated Progress
I implemented a workaround on my sandbox so that I can apply the styles to the text for strong/b, i/em, u, s, sub & sup instead of displaying the HTML tags.
I created a custom module and used the Dolibarr Module Builder to create the actions class, then I made it an extension of ModelePDFPropales.
Before the class declaration, I am requiring /core/modules/propale/modules_propale.php
My custom module is called documenttemplates and this is the syntax I am using to do the aforementioned:
require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
/**
* Class ActionsDocumentTemplates
*/
class ActionsDocumentTemplates extends ModelePDFPropales
Inside the class I implemented the afterODTCreation hook function
/* Add here any other hooked methods... */
public function afterODTCreation($parameters, &$object, &$action, $hookmanager)
{
global $langs;
$outputlangs = $langs;
require_once DOL_DOCUMENT_ROOT.'/core/modules/propale/modules_propale.php';
$srctemplatepath = DOL_DATA_ROOT . '/doctemplates/proposals/key_mapping.odt';
ob_clean(); // required so that you don't receive PHP Warning: Cannot modify header information
$this->write_file($parameters['object'], $outputlangs, $srctemplatepath);
return 0;
}
Then I duplicated the following functions from htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php
write_file
setVars
convertVarToOdf
_hasHtmlTag
_replaceHtmlWithOdtTag
_getDataFromHtml
In the write_file function, I made sure that $encode is false whenever setVars is called.
Example:
$odfHandler->setVars($key, $value, false, 'UTF-8');
I also commented out the executeHooks in the write_file function I duplicated so that I do not risk going into an endless hook loop when generating an ODT file.
What this hook functionality does is that it generates the ODT file as normal with the unwanted HTML tags displayed in the file. Then when the ODT file is finished generated, the hook regenerates the ODT file with the styled text in the ODT files instead of the unwanted HTML tags.
I do have one more issue I am trying to figure out and that is how to get the $srctemplatepath dynamically because right now it is hardcoded which limits the ODT file generation to one template. I want to be able to accommodate whatever ODT template the Dolibarr users selects from the dropdown.