Merge pull request #1541 from morrisdj/develop

Add "Plain Text" type to SDT (Structured Document Tags)
This commit is contained in:
troosan 2018-12-26 23:16:06 +01:00 committed by GitHub
commit bbe517aa60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 3 deletions

View File

@ -11,6 +11,7 @@ v0.16.0 (xx dec 2018)
- Add ability to pass a Style object in Section constructor @ndench #1416 - Add ability to pass a Style object in Section constructor @ndench #1416
- Add support for hidden text @Alexmg86 #1527 - Add support for hidden text @Alexmg86 #1527
- Add support for setting images in TemplateProcessor @SailorMax #1170 - Add support for setting images in TemplateProcessor @SailorMax #1170
- Add "Plain Text" type to SDT (Structured Document Tags) @morrisdj #1541
### Fixed ### Fixed
- Fix regex in `cloneBlock` function @nicoder #1269 - Fix regex in `cloneBlock` function @nicoder #1269

View File

@ -90,7 +90,7 @@ class SDT extends Text
*/ */
public function setType($value) public function setType($value)
{ {
$enum = array('comboBox', 'dropDownList', 'date'); $enum = array('plainText', 'comboBox', 'dropDownList', 'date');
$this->type = $this->setEnumVal($value, $enum, 'comboBox'); $this->type = $this->setEnumVal($value, $enum, 'comboBox');
return $this; return $this;

View File

@ -73,6 +73,18 @@ class SDT extends Text
$this->endElementP(); // w:p $this->endElementP(); // w:p
} }
/**
* Write text.
*
* @see http://www.datypic.com/sc/ooxml/t-w_CT_SdtText.html
* @param \PhpOffice\Common\XMLWriter $xmlWriter
*/
private function writePlainText(XMLWriter $xmlWriter)
{
$xmlWriter->startElement('w:text');
$xmlWriter->endElement(); // w:text
}
/** /**
* Write combo box. * Write combo box.
* *

View File

@ -29,8 +29,8 @@ class SDTTest extends \PHPUnit\Framework\TestCase
*/ */
public function testConstruct() public function testConstruct()
{ {
$types = array('comboBox', 'dropDownList', 'date'); $types = array('plainText', 'comboBox', 'dropDownList', 'date');
$type = $types[rand(0, 2)]; $type = $types[rand(0, 3)];
$value = rand(0, 100); $value = rand(0, 100);
$alias = 'alias'; $alias = 'alias';
$tag = 'my_tag'; $tag = 'my_tag';

View File

@ -387,6 +387,7 @@ class ElementTest extends \PHPUnit\Framework\TestCase
$section->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'))->setValue('select value'); $section->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'))->setValue('select value');
$section->addSDT('dropDownList'); $section->addSDT('dropDownList');
$section->addSDT('date')->setAlias('date_alias')->setTag('my_tag'); $section->addSDT('date')->setAlias('date_alias')->setTag('my_tag');
$section->addSDT('plainText');
$doc = TestHelperDOCX::getDocument($phpWord); $doc = TestHelperDOCX::getDocument($phpWord);
@ -405,6 +406,8 @@ class ElementTest extends \PHPUnit\Framework\TestCase
$this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:date')); $this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:date'));
$this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:alias')); $this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:alias'));
$this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:tag')); $this->assertTrue($doc->elementExists($path . '[3]/w:sdt/w:sdtPr/w:tag'));
$this->assertTrue($doc->elementExists($path . '[4]/w:sdt/w:sdtPr/w:text'));
} }
/** /**