From 2c73f86e25a00d16af175dbc93abe5a7f5b54522 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 5 Sep 2025 09:50:05 -0500 Subject: [PATCH 1/5] Create ListItemRun --- src/PhpWord/Writer/RTF/Element/ListItemRun | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/PhpWord/Writer/RTF/Element/ListItemRun diff --git a/src/PhpWord/Writer/RTF/Element/ListItemRun b/src/PhpWord/Writer/RTF/Element/ListItemRun new file mode 100644 index 0000000000..605d715248 --- /dev/null +++ b/src/PhpWord/Writer/RTF/Element/ListItemRun @@ -0,0 +1,51 @@ +element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { + return ''; + } + + $writer = new Container($this->parentWriter, $this->element); + $this->getStyles(); + + $content = ''; + $content .= $this->writeOpening(); + $content .= '{'; + $content .= $writer->write(); + $content .= '}'; + $content .= $this->writeClosing(); + + return $content; + } +} From b211b3cc36d317f3250f1cc0d3b6cf9f3f32527f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 5 Sep 2025 09:51:30 -0500 Subject: [PATCH 2/5] Update Container.php - $withoutP now checks for ListItemRun Field also added to match the $withoutP in PhpOffice\PhpWord\Element\AbstractContainer --- src/PhpWord/Writer/RTF/Element/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PhpWord/Writer/RTF/Element/Container.php b/src/PhpWord/Writer/RTF/Element/Container.php index dcac8ec071..8a5ba87da8 100644 --- a/src/PhpWord/Writer/RTF/Element/Container.php +++ b/src/PhpWord/Writer/RTF/Element/Container.php @@ -46,7 +46,7 @@ public function write() return ''; } $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); - $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote']) ? true : false; + $withoutP = in_array($containerClass, ['TextRun', 'Footnote', 'Endnote', 'ListItemRun', 'Field']) ? true : false; $content = ''; $elements = $container->getElements(); From 3761021326387d7948a4221ad4739c2cd9c7ea4f Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 5 Sep 2025 09:58:21 -0500 Subject: [PATCH 3/5] Update 1.5.0.md - Changelog for Pull 2823 --- docs/changes/1.x/1.5.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes/1.x/1.5.0.md b/docs/changes/1.x/1.5.0.md index b96865bada..d8528171e5 100644 --- a/docs/changes/1.x/1.5.0.md +++ b/docs/changes/1.x/1.5.0.md @@ -7,6 +7,7 @@ ### Bug fixes - Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776) +- Writer RTF: Create element ListItemRun by [@rasamassen](https://github.com/rasamassen) in [#2823](https://github.com/PHPOffice/PHPWord/pull/2823) ### Miscellaneous @@ -16,4 +17,4 @@ ### BC Breaks -### Notes \ No newline at end of file +### Notes From 534ef067924ceb6587995f1ce072174dae55e3b9 Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 5 Sep 2025 10:55:50 -0500 Subject: [PATCH 4/5] Update ListItemRun - Implements required ListItem tags --- src/PhpWord/Writer/RTF/Element/ListItemRun | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Element/ListItemRun b/src/PhpWord/Writer/RTF/Element/ListItemRun index 605d715248..1431f32e72 100644 --- a/src/PhpWord/Writer/RTF/Element/ListItemRun +++ b/src/PhpWord/Writer/RTF/Element/ListItemRun @@ -32,15 +32,34 @@ class ListItemRun extends TextRun */ public function write() { - if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { + $element = $this->element; + if (!$element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { return ''; } - $writer = new Container($this->parentWriter, $this->element); + $writer = new Container($this->parentWriter, $element); $this->getStyles(); + $depth = (int) $element->getDepth(); + $style = $element->getStyle(); + + echo $depth . '
'; + print_r($style); + $content = ''; $content .= $this->writeOpening(); + if ($style instanceof \PhpOffice\PhpWord\Style\ListItem) { + $numStyle = $style->getNumberingStyle(); + $levels = $numStyle->getLevels(); + $content .= '\ilvl' . $element->getDepth(); + $content .= '\ls' . $style->getNumId(); + $content .= '\tx' . $levels[$depth]->getTabPos(); + $hanging = $levels[$depth]->getLeft() + $levels[$depth]->getHanging(); + $left = 0 - $levels[$depth]->getHanging(); + $content .= '\fi' . $left; + $content .= '\li' . $hanging; + $content .= '\lin' . $hanging; + } $content .= '{'; $content .= $writer->write(); $content .= '}'; From eebb61ae7ffa7fb4c49630e4391f861fc171eecd Mon Sep 17 00:00:00 2001 From: rasamassen Date: Fri, 5 Sep 2025 11:01:19 -0500 Subject: [PATCH 5/5] Update ListItemRun - Forgot to remove extraneous code --- src/PhpWord/Writer/RTF/Element/ListItemRun | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/PhpWord/Writer/RTF/Element/ListItemRun b/src/PhpWord/Writer/RTF/Element/ListItemRun index 1431f32e72..d8c13eb962 100644 --- a/src/PhpWord/Writer/RTF/Element/ListItemRun +++ b/src/PhpWord/Writer/RTF/Element/ListItemRun @@ -43,9 +43,6 @@ class ListItemRun extends TextRun $depth = (int) $element->getDepth(); $style = $element->getStyle(); - echo $depth . '
'; - print_r($style); - $content = ''; $content .= $this->writeOpening(); if ($style instanceof \PhpOffice\PhpWord\Style\ListItem) {