Add this code on your form code where you want to add innerlisting
<insertListing>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">Name_of_listing_file</item>
</item>
</argument>
</insertListing>
Make your banner_form.xml file like below:
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">banner_form.banner_form_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">General Information</item>
<item name="template" xsi:type="string">templates/form/collapsible</item>
</argument>
<settings>
<buttons>
<button name="save_and_continue" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\SaveAndContinueButton"/>
<button name="save" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\SaveButton"/>
<button name="reset" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\ResetButton"/>
<button name="delete" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\DeleteButton"/>
<button name="back" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\BackButton"/>
</buttons>
<namespace>banner_form</namespace>
<dataScope>data</dataScope>
<deps>
<dep>banner_form.banner_form_data_source</dep>
</deps>
</settings>
<dataSource name="banner_form_data_source">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
<settings>
<submitUrl path="banner/manage/save"/>
</settings>
<dataProvider class="Aht\BannerSlider\Model\Banner\DataProvider" name="banner_form_data_source">
<settings>
<requestFieldName>id</requestFieldName>
<primaryFieldName>id</primaryFieldName>
</settings>
</dataProvider>
</dataSource>
<fieldset name="general">
<settings>
<label/>
</settings>
<field name="id" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">banner</item>
</item>
</argument>
<settings>
<dataType>text</dataType>
<visible>false</visible>
<dataScope>id</dataScope>
</settings>
</field>
<field name="name" sortOrder="20" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">banner</item>
</item>
</argument>
<settings>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
<dataType>text</dataType>
<label translate="true">Banner Name</label>
<dataScope>name</dataScope>
</settings>
</field>
</fieldset>
<fieldset name="banner_information" sortOrder="10">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string">Banner Information</item>
<item name="collapsible" xsi:type="boolean">false</item>
</item>
</argument>
<insertListing>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">banner_listing</item>
</item>
</argument>
</insertListing>
</fieldset>
I have added below code:
<fieldset name="banner_information" sortOrder="10">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string">Banner Information</item>
<item name="collapsible" xsi:type="boolean">false</item>
</item>
</argument>
<insertListing>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="autoRender" xsi:type="boolean">true</item>
<item name="ns" xsi:type="string">banner_listing</item>
</item>
</argument>
</insertListing>
</fieldset>
It is possible yo change the layout of pdfslip by using Model file.
edit, create a di.xml file under MY\MODULE\etc\adminhtml\
and edit it as followed
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="MY\MODULE\Model\Order\Pdf\Invoice" />
</config>
After that create a Invoice.php file under MY\MODULE\Model\Order\Pdf
and change it like this
<?php
namespace MY\MODULE\Model\Order\Pdf;
class Invoice extends \Magento\Sales\Model\Order\Pdf\Invoice
{
protected function _doDrawHeader(\Zend_Pdf_Page $page)
{
/* Add table head */
$this->_setFontRegular($page, 10);
$page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
$page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y + 5, 570, $this->y - 25);
$this->y -= 10;
$page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0));
//columns headers
$lines[0][] = ['text' => __('Products'), 'feed' => 35];
$lines[0][] = ['text' => __('SKU'), 'feed' => 290, 'align' => 'right'];
$lines[0][] = ['text' => __('Qty'), 'feed' => 435, 'align' => 'right'];
$lines[0][] = ['text' => __('Price'), 'feed' => 360, 'align' => 'right'];
$lines[0][] = ['text' => __('Tax'), 'feed' => 495, 'align' => 'right'];
$lines[0][] = ['text' => __('Subtotal'), 'feed' => 565, 'align' => 'right'];
$lineBlock = ['lines' => $lines, 'height' => 5];
$this->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
$page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
$this->y -= 20;
}
public function getPdf($invoices = [])
{
$this->_beforeGetPdf();
$this->_initRenderer('invoice');
$pdf = new \Zend_Pdf();
$this->_setPdf($pdf);
$style = new \Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
$this->_localeResolver->emulate($invoice->getStoreId());
$this->_storeManager->setCurrentStore($invoice->getStoreId());
}
$page = $this->newPage();
$order = $invoice->getOrder();
/* Add image */
$this->insertLogo($page, $invoice->getStore());
/* Add address */
$this->insertAddress($page, $invoice->getStore());
/* Add head */
$this->insertOrder(
$page,
$order,
$this->_scopeConfig->isSetFlag(
self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$order->getStoreId()
)
);
/* Add document text and number */
$this->insertDocumentNumber($page, __('Invoice # ') . $invoice->getIncrementId());
/* Add table */
$this->_doDrawHeader($page);
/* Add body */
foreach ($invoice->getAllItems() as $item) {
if ($item->getOrderItem()->getParentItem()) {
continue;
}
/* Draw item */
$this->_drawItem($item, $page, $order);
$page = end($pdf->pages);
}
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
$this->_localeResolver->revert();
}
}
$this->_afterGetPdf();
return $pdf;
}
/**
* Create new page and assign to PDF object
*
* @param array $settings
* @return \Zend_Pdf_Page
*/
public function newPage(array $settings = [])
{
/* Add new table head */
$page = $this->_getPdf()->newPage(\Zend_Pdf_Page::SIZE_A4);
$this->_getPdf()->pages[] = $page;
$this->y = 800;
if (!empty($settings['table_header'])) {
$this->_doDrawHeader($page);
}
return $page;
}
}
As it is editing a protected function __DrawHeader
you should changes its name, like _doDrawHeader
. Also you should edit its name in the calling method $this->_doDrawHeader($page);
in public function getPdf
Best Answer
Just to consolidate all this information:
1: Create (or use) a custom module under
app/code/YourModule
- egapp/code/YourModule/Sales
2: Add a
<preference \>
entry toapp/code/YourModule/Sales/etc/di.xml
- eg:3: Create the file
app/code/YourModule/Sales/Model/Order/Pdf/Invoice.php
That will reduce your invoices from 3Mb each to 2Kb.