automatic update of the TOC to fix page number missing issues #2556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
On several trials, I noticed that despite using
$phpWord->getSettings()->setUpdateFields(true);
, when the generated file was first opened, the chapter index only updated the page numbers and not the list as well, thus losing the references to any paragraphs (H2 and H3) in the document.On subsequent openings of the file, Word requests the updating of the table of contents fields, but requires the user to specifically select the "update entire table of contents" option, so in the case of a different choice ("update page numbers only") the references to the paragraphs present in each chapter are lost, as mentioned above.
The change made in
PhpWord/Writer/Word2007/Element/TOC.php
on line116
allows the entire table of contents to be automatically updated by only requiring the generic update of the fields, but without requiring the second step, whatever the number of file openings.Fixes #1691 #1396
Checklist:
composer run-script check --timeout=0
and no errors were reported