Magento – Magento 2 – Add custom block to admin order create form

adminhtmlcreate-ordermagento2modulesales-order

I need to add new block to admin order create form (in totals section). First I tried to do it by adding sales_order_create_index.xml to my module and adding my block to

<referenceBlock name="data">

but it did not work and it's because all child blocks of "data" block are called in data.phtml with $block->getChildHtml() method.

UPDATE

Now I decited to use plugins instead, I added plugin to Magento\Sales\Block\Adminhtml\Order\Create\Data like this

class DataPlugin
{
    public function beforegetChildHtml($subject, $alias = '', $useCache = true){

       if($alias=='totals'){
          echo 'test';
       }

    }
}

And it's works. But how I can insert my block here instead of printing text

Best Answer

This is the way I can insert my custom block

namespace Exto\StoreCredit\Model\Plugin\Admin\Order\Create;

 class DataPlugin extends \Magento\Backend\Block\Template
 {

    public function beforegetChildHtml($subject, $alias = '', $useCache = true){
     if($alias=='totals'){
        echo $this->getLayout()
        ->createBlock('\Magento\Backend\Block\Template')
        ->setTemplate('Vendor_Module::test.phtml')
        ->toHtml();
     }

}

}