readFactory = $readFactory; $this->moduleReader = $moduleReader; } /** * Compiles the Element node * * @param CompilerInterface $compiler * @param \DOMElement $node * @param DataObject $processedObject * @param DataObject $context * @return void */ public function compile( CompilerInterface $compiler, \DOMElement $node, DataObject $processedObject, DataObject $context ) { $ownerDocument = $node->ownerDocument; $parentNode = $node->parentNode; $document = new \DOMDocument(); $document->loadXML($this->getContent($node->getAttribute(static::INCLUDE_PATH))); foreach ($this->getChildNodes($document->documentElement) as $child) { $compiler->compile($child, $processedObject, $context); } $newFragment = $ownerDocument->createDocumentFragment(); foreach ($document->documentElement->childNodes as $child) { $newFragment->appendXML($document->saveXML($child)); } $parentNode->replaceChild($newFragment, $node); } /** * Get child nodes * * @param \DOMElement $node * @return \DOMElement[] */ protected function getChildNodes(\DOMElement $node) { $childNodes = []; foreach ($node->childNodes as $child) { $childNodes[] = $child; } return $childNodes; } /** * Get content of include file (in adminhtml area) * * @param string $includePath * @return string * @throws LocalizedException */ protected function getContent($includePath) { // list($moduleName, $filename) = explode('::', $includePath); $path = 'adminhtml/' . $filename; $directoryRead = $this->readFactory->create( $this->moduleReader->getModuleDir(Dir::MODULE_ETC_DIR, $moduleName) ); if ($directoryRead->isExist($path) && $directoryRead->isFile($path)) { return $directoryRead->readFile($path); } throw new LocalizedException(__('The "%1" file doesn\'t exist.', $path)); } }