Skip to content

Commit bbe517a

Browse files
authored
Merge pull request #1541 from morrisdj/develop
Add "Plain Text" type to SDT (Structured Document Tags)
2 parents 254d300 + dcf637d commit bbe517a

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ v0.16.0 (xx dec 2018)
1111
- Add ability to pass a Style object in Section constructor @ndench #1416
1212
- Add support for hidden text @Alexmg86 #1527
1313
- Add support for setting images in TemplateProcessor @SailorMax #1170
14+
- Add "Plain Text" type to SDT (Structured Document Tags) @morrisdj #1541
1415

1516
### Fixed
1617
- Fix regex in `cloneBlock` function @nicoder #1269

src/PhpWord/Element/SDT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getType()
9090
*/
9191
public function setType($value)
9292
{
93-
$enum = array('comboBox', 'dropDownList', 'date');
93+
$enum = array('plainText', 'comboBox', 'dropDownList', 'date');
9494
$this->type = $this->setEnumVal($value, $enum, 'comboBox');
9595

9696
return $this;

src/PhpWord/Writer/Word2007/Element/SDT.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ public function write()
7373
$this->endElementP(); // w:p
7474
}
7575

76+
/**
77+
* Write text.
78+
*
79+
* @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtText.html
80+
* @param \PhpOffice\Common\XMLWriter $xmlWriter
81+
*/
82+
private function writePlainText(XMLWriter $xmlWriter)
83+
{
84+
$xmlWriter->startElement('w:text');
85+
$xmlWriter->endElement(); // w:text
86+
}
87+
7688
/**
7789
* Write combo box.
7890
*

tests/PhpWord/Element/SDTTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class SDTTest extends \PHPUnit\Framework\TestCase
2929
*/
3030
public function testConstruct()
3131
{
32-
$types = array('comboBox', 'dropDownList', 'date');
33-
$type = $types[rand(0, 2)];
32+
$types = array('plainText', 'comboBox', 'dropDownList', 'date');
33+
$type = $types[rand(0, 3)];
3434
$value = rand(0, 100);
3535
$alias = 'alias';
3636
$tag = 'my_tag';

tests/PhpWord/Writer/Word2007/ElementTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ public function testSDTElements()
387387
$section->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'))->setValue('select value');
388388
$section->addSDT('dropDownList');
389389
$section->addSDT('date')->setAlias('date_alias')->setTag('my_tag');
390+
$section->addSDT('plainText');
390391

391392
$doc = TestHelperDOCX::getDocument($phpWord);
392393

@@ -405,6 +406,8 @@ public function testSDTElements()
405406
$this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:date'));
406407
$this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:alias'));
407408
$this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:tag'));
409+
410+
$this->assertTrue($doc->elementExists($path . '[4]/w:sdt/w:sdtPr/w:text'));
408411
}
409412

410413
/**

0 commit comments

Comments
 (0)