Currently the template is defined like this:
Company/PdfDesign/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Company\PdfDesign\Model\CompanyDesign">
<arguments>
<argument name="templateFiles" xsi:type="array">
<item name="extras" xsi:type="string">Company_PdfDesign::pdf/table/extras.phtml</item>
</argument>
</arguments>
</type>
</config>
However, I want to make this dynamic and load it from the settings, so I tried to use a helper like seen here:
Company/PdfDesign/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Company\PdfDesign\Model\CompanyDesign">
<arguments>
<argument name="templateFiles" xsi:type="array">
<item name="extras" xsi:type="helper" helper="Company\PdfDesign\Helper\Table\Extras::getTemplate"></item>
</argument>
</arguments>
</type>
</config>
But if I flush cache from CLI then I get alot of XML errors.´
Invalid Document
Element 'item', attribute '{http://www.w3.org/2001/XMLSchema-instance}type': The QName value 'helper' of the xsi:type attribute does not resolve to a type definition.
Line: 11
Element 'item': The type definition is abstract.
Line: 11
Internal error: xmlSchemaXPathProcessHistory, The state object to be removed is not the first in the list.
Line: 10
Internal error: xmlSchemaValidateChildElem, calling xmlRegExecPushString2().
Line: 9
Internal error: xmlSchemaValidateElem, calling xmlSchemaStreamValidateChildElement().
Line: 9
Internal error: xmlSchemaDocWalk, calling xmlSchemaValidateElem().
Line: 9
How can I load the value from a helper instead of hardcoding it?
Company\PdfDesign\Model\CompanyDesign
<?php
/**
* @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz)
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Company\PdfDesign\Model;
use \Fooman\PdfCore\Helper\Logo;
use \Magento\Framework\App\Config\ScopeConfigInterface;
/**
* Design source for Default Design
*/
class CompanyDesign implements \Fooman\PdfDesign\Model\Api\DesignInterface
{
...
public function __construct(
array $templateFiles = []
) {
$this->templateFiles = $templateFiles;
}
...
public function getTemplateFiles()
{
return $this->templateFiles;
}
...
}
vendor/fooman/pdfdesign-m2/src/Model/TemplateFileDecider.php
<?php
namespace Fooman\PdfDesign\Model;
use Magento\Framework\Exception\NotFoundException;
/**
* pick template file based on chosen pdf design
*/
class TemplateFileDecider
{
private $defaultDesign;
public function __construct(
DefaultDesign $defaultDesign
) {
$this->defaultDesign = $defaultDesign;
}
public function pick(Api\DesignInterface $design, $templateFor)
{
$designTemplates = $design->getTemplateFiles() + $this->defaultDesign->getTemplateFiles();
if (!isset($designTemplates[$templateFor])) {
throw new NotFoundException(__('No template set for %1', $templateFor));
}
return $designTemplates[$templateFor];
}
}