Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent infinite loop when tokens are used in headers or footers #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,21 @@ public function replaceHtmlToken(string $macroVariable, string $renderedTokenMes
// styles.
PhpWord\Shared\Html::addHtml($section, $renderedTokenMessage);
$elements = $section->getElements();
// setValue() and setElementsValue() replace only the first occurrence of macro variables in the document, so loop
// until all have been replaced.
do {
if ([] === $elements) {
// Note: If the paragraph had the macro as its only content, it
// will not be removed (i.e. leave an empty paragraph).
$this->setValue($macroVariable, '');
}
else {
if ([] === $elements) {
// Note: If the paragraph had the macro as its only content, it
// will not be removed (i.e. leave an empty paragraph).
$this->setValue($macroVariable, '');
}
else {
// setElementsValue() replace only the first occurrence of macro variables in the document, so loop
// until all have been replaced.
// @todo Replace not only macros in the main part, but also in headers and footers.
do {
// ... or as HTML: Render all elements and insert in the text
// run or paragraph containing the macro.
$this->setElementsValue($macroVariable, $elements, TRUE);
}
} while (in_array($macroVariable, $this->getVariables(), TRUE));
} while (in_array($macroVariable, $this->getVariablesForPart($this->tempDocumentMainPart), TRUE));
}
}
catch (Exception $exception) {
throw new CRM_Core_Exception(
Expand Down
Loading