0

Facing an Error while add a complex component modal as insertlisting for add dynamic row in my ui-component admin form:

Error is as below:

"Warning: DOMDocument::loadXML(): xmlParseEntityRef: no name in Entity, line: 521 in /home/.../.../vendor/magento/framework/View/Element/UiComponent/Config/DomMerger.php on line 324";i:1;s:9157:"#0 [internal function]: Magento\Framework\App\ErrorHandler->handler(2, 'DOMDocument::lo...', '/home/ashish/ap...', 324, Array)

Code is below:

<fieldset name="tool_templates">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="collapsible" xsi:type="boolean">false</item>
            <item name="label" xsi:type="string" translate="true">Assign Tools and Templates</item>
            <item name="additionalClasses" xsi:type="string">admin__fieldset-section</item>
            <item name="sortOrder" xsi:type="number">50</item>
        </item>
    </argument>
<container name="button_set">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="boolean">false</item>
            <item name="content" xsi:type="string" translate="true">Related toots and templates are shown to customers the tools and templates relating to the article.</item>
            <item name="template" xsi:type="string">ui/form/components/complex</item>
        </item>
    </argument>
    <container name="button_tool_template">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="title" xsi:type="string" translate="true">Add Tools & Templates</item>
                <item name="component" xsi:type="string">Magento_Ui/js/form/components/button</item>
                <item name="actions" xsi:type="array">
                    <item name="0" xsi:type="array">
                        <item name="targetName" xsi:type="string">cms_article_form.cms_article_form.related_services.tool_templates.modal</item>
                        <item name="actionName" xsi:type="string">toggleModal</item>
                    </item>
                    <item name="1" xsi:type="array">
                        <item name="targetName" xsi:type="string">cms_article_form.cms_article_form.related_services.tool_templates.modal.cms_tool_templates_article_listing</item>
                        <item name="actionName" xsi:type="string">render</item>
                    </item>
                </item>
                <item name="provider" xsi:type="boolean">false</item>
            </item>
        </argument>
    </container>
</container>
<modal name="modal">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="dataScope" xsi:type="string"></item>
            <item name="component" xsi:type="string">Magento_Ui/js/modal/modal-component</item>
            <item name="options" xsi:type="array">
                <item name="title" xsi:type="string" translate="true">Assign Tools & Templates</item>
                <item name="buttons" xsi:type="array">
                    <item name="0" xsi:type="array">
                        <item name="text" xsi:type="string" translate="true">Cancel</item>
                        <item name="actions" xsi:type="array">
                            <item name="0" xsi:type="string">closeModal</item>
                        </item>
                    </item>
                    <item name="1" xsi:type="array">
                        <item name="text" xsi:type="string" translate="true">Assign Selected Tools & Templates</item>
                        <item name="class" xsi:type="string">action-primary</item>
                        <item name="actions" xsi:type="array">
                            <item name="0" xsi:type="array">
                                <item name="targetName" xsi:type="string">index=cms_tool_templates_article_listing</item>
                                <item name="actionName" xsi:type="string">save</item>
                            </item>
                            <item name="1" xsi:type="string">closeModal</item>
                        </item>
                    </item>
                </item>
            </item>
        </item>
    </argument>
    <insertListing name="cms_tool_templates_article_listing">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="autoRender" xsi:type="boolean">false</item>
                <item name="dataScope" xsi:type="string">cms_tool_templates_article_listing</item>
                <item name="externalProvider" xsi:type="string">cms_tool_templates_article_listing.cms_tool_templates_article_listing_data_source</item>
                <item name="selectionsProvider" xsi:type="string">cms_tool_templates_article_listing.cms_tool_templates_article_listing.article_columns.ids</item>
                <item name="ns" xsi:type="string">cms_tool_templates_article_listing</item>
                <item name="render_url" xsi:type="url" path="mui/index/render" />
                <item name="realTimeLink" xsi:type="boolean">true</item>
                <item name="dataLinks" xsi:type="array">
                    <item name="imports" xsi:type="boolean">false</item>
                    <item name="exports" xsi:type="boolean">true</item>
                </item>
                <item name="behaviourType" xsi:type="string">simple</item>
                <item name="externalFilterMode" xsi:type="boolean">true</item>
                <item name="imports" xsi:type="array">
                    <item name="articleId" xsi:type="string">${ $.provider }:data.article.current_article_id</item>
                </item>
                <item name="exports" xsi:type="array">
                    <item name="articleId" xsi:type="string">${ $.externalProvider }:data.article.current_article_id</item>
                </item>
                <item name="component" xsi:type="string">Magento_Ui/js/form/components/insert-listing</item>
            </item>
        </argument>
    </insertListing>
</modal>
<dynamicRows name="tool">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="additionalClasses" xsi:type="string">admin__field-wide</item>
            <item name="componentType" xsi:type="string">dynamicRows</item>
            <item name="label" xsi:type="boolean">false</item>
            <item name="columnsHeader" xsi:type="boolean">false</item>
            <item name="columnsHeaderAfterRender" xsi:type="boolean">true</item>
            <item name="renderDefaultRecord" xsi:type="boolean">false</item>
            <item name="template" xsi:type="string">ui/dynamic-rows/templates/grid</item>
            <item name="component" xsi:type="string">Magento_Ui/js/dynamic-rows/dynamic-rows-grid</item>
            <item name="addButton" xsi:type="boolean">false</item>
            <item name="recordTemplate" xsi:type="string">record</item>
            <item name="dataScope" xsi:type="string">data.links</item>
            <item name="deleteButtonLabel" xsi:type="string" translate="true">Remove</item>
            <item name="dataProvider" xsi:type="string">data.cms_tool_templates_article_listing</item>
            <item name="map" xsi:type="array">
                <item name="id" xsi:type="string">id</item>
                <item name="title" xsi:type="string">title</item>
                <item name="link" xsi:type="string">link</item>
                <item name="status" xsi:type="string">status</item>
            </item>
            <item name="links" xsi:type="array">
                <item name="insertData" xsi:type="string">${ $.provider }:${ $.dataProvider }</item>
            </item>
            <item name="sortOrder" xsi:type="string">2</item>
        </item>
    </argument>
    <container name="record">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="isTemplate" xsi:type="boolean">true</item>
                <item name="is_collection" xsi:type="boolean">true</item>
                <item name="component" xsi:type="string">Magento_Ui/js/dynamic-rows/record</item>
                <item name="componentType" xsi:type="string">container</item>
                <item name="componentType" xsi:type="string">container</item> 
                <item name="positionProvider" xsi:type="string">attribute_options.position</item> 
                <item name="dataScope" xsi:type="string"></item>
            </item>
        </argument>
        <field name="id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="elementTmpl" xsi:type="string">ui/dynamic-rows/cells/text</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/form/element/text</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="dataScope" xsi:type="string">id</item>
                    <item name="fit" xsi:type="boolean">false</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                    <item name="sortOrder" xsi:type="string">10</item>
                </item>
            </argument>
        </field>
        <field name="title">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="elementTmpl" xsi:type="string">ui/dynamic-rows/cells/text</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/form/element/text</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="dataScope" xsi:type="string">title</item>
                    <item name="fit" xsi:type="boolean">false</item>
                    <item name="label" xsi:type="string" translate="true">Title</item>
                    <item name="sortOrder" xsi:type="string">20</item>
                </item>
            </argument>
        </field>
        <field name="link">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="elementTmpl" xsi:type="string">ui/dynamic-rows/cells/text</item>
                    <item name="component" xsi:type="string">Magento_Ui/js/form/element/text</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="dataScope" xsi:type="string">link</item>
                    <item name="fit" xsi:type="boolean">false</item>
                    <item name="label" xsi:type="string" translate="true">URL Key</item>
                    <item name="sortOrder" xsi:type="string">30</item>
                </item>
            </argument>
        </field>
        <actionDelete name="actionDelete">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="actionDelete" xsi:type="string">data-grid-actions-cell</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="label" xsi:type="string" translate="true">Actions</item>
                    <item name="fit" xsi:type="boolean">true</item>
                    <item name="sortOrder" xsi:type="string">80</item>
                </item>
            </argument>
        </actionDelete>
        <field name="position">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="dataType" xsi:type="string">number</item>
                    <item name="dataScope" xsi:type="string">position</item>
                    <item name="fit" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">Thumbnail</item>
                    <item name="sortOrder" xsi:type="string">90</item>
                    <item name="visible" xsi:type="boolean">false</item>
                </item>
            </argument>
        </field>
    </container>
</dynamicRows>

cms_tool_templates_article_listing.xml code is below

<listing 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">cms_tool_templates_article_listing.cms_tool_templates_article_listing_data_source</item>
            <item name="deps" xsi:type="string">cms_tool_templates_article_listing.cms_tool_templates_article_listing_data_source</item>
        </item>
        <item name="spinner" xsi:type="string">article_columns</item>
    </argument>
    <dataSource name="cms_tool_templates_article_listing_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
            <argument name="class" xsi:type="string">Package\Cms\Ui\DataProvider\Article\Service\ToolDataProvider</argument>
            <argument name="name" xsi:type="string">cms_tool_templates_article_listing_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">id</argument>
            <argument name="requestFieldName" xsi:type="string">id</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
                    <item name="update_url" xsi:type="url" path="mui/index/render"/>
                    <item name="storageConfig" xsi:type="array">
                        <item name="cacheRequests" xsi:type="boolean">false</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <listingToolbar name="listing_top">
        <filters name="listing_filters">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="statefull" xsi:type="array">
                        <item name="applied" xsi:type="boolean">false</item>
                    </item>
                    <item name="params" xsi:type="array">
                        <item name="filters_modifier" xsi:type="array" />
                    </item>
                    <item name="observers" xsi:type="array">
                        <item name="filters" xsi:type="object">Magento\Ui\Component\Filters</item>
                    </item>
                </item>
            </argument>
        </filters>
        <paging name="listing_paging"/>
    </listingToolbar>
    <columns name="article_columns" class="Magento\Ui\Component\Listing\Columns">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="childDefaults" xsi:type="array">
                    <item name="fieldAction" xsi:type="array">
                        <item name="provider" xsi:type="string">cms_tool_templates_article_listing.cms_tool_templates_article_listing.article_columns_editor</item>
                        <item name="target" xsi:type="string">selectTool</item>
                        <item name="params" xsi:type="array">
                            <item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
                        </item>
                    </item>
                </item>
            </item>
        </argument>
        <selectionsColumn name="ids">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="indexField" xsi:type="string">id</item>
                    <item name="sortOrder" xsi:type="number">0</item>
                    <item name="preserveSelectionsOnFilter" xsi:type="boolean">true</item>
                </item>
            </argument>
        </selectionsColumn>
        <column name="id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="add_field" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">ID</item>
                    <item name="sortOrder" xsi:type="number">10</item>
                </item>
            </argument>
        </column>
        <column name="title">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="add_field" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">Title</item>
                    <item name="sortOrder" xsi:type="number">20</item>
                </item>
            </argument>
        </column>
        <column name="link">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="filter" xsi:type="string">text</item>
                    <item name="add_field" xsi:type="boolean">true</item>
                    <item name="label" xsi:type="string" translate="true">URL Key</item>
                    <item name="sortOrder" xsi:type="number">30</item>
                </item>
            </argument>
        </column>
    </columns>
</listing>

Package\Cms\Ui\DataProvider\Article\Service\ToolDataProvider code is below:

<?php

namespace Package\Cms\Ui\DataProvider\Article\Service;

use Package\Cms\Model\Resource\ToolTemplate\Collection;
use Package\Cms\Model\Resource\ToolTemplate\CollectionFactory;
use Magento\Framework\App\RequestInterface;

/**
 * Class ArticleDataProvider
 */
class ToolDataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider {

    /**
     * @var RequestInterface
     */
    protected $request;

    /**
     * @var article
     */
    private $article;

    /**
     * Construct
     *
     * @param string $name
     * @param string $primaryFieldName
     * @param string $requestFieldName
     * @param CollectionFactory $collectionFactory
     * @param RequestInterface $request
     * @param array $meta
     * @param array $data
     */
    public function __construct(
    $name, $primaryFieldName, $requestFieldName, CollectionFactory $collectionFactory, RequestInterface $request, \Magento\Framework\Api\Search\ReportingInterface $reporting, \Magento\Framework\Api\Search\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder, array $meta = [], array $data = []
    ) {
        parent::__construct(
                $name, $primaryFieldName, $requestFieldName, $reporting, $searchCriteriaBuilder, $request, $filterBuilder, $meta, $data
        );
        $this->collection = $collectionFactory->create();
        $this->request = $request;
    }

    /**
     * @param SearchResultInterface $searchResult
     * @return array
     */
    protected function searchResultToOutput(SearchResultInterface $searchResult) {
        $arrItems = [];
        $arrItems['totalRecords'] = $searchResult->getTotalCount();

        $arrItems['items'] = [];
        foreach ($searchResult->getItems() as $item) {
            $arrItems['items'][] = $item->getData();
        }

        return $arrItems;
    }

    /**
     * {@inheritdoc}
     */
    public function getData() {
        /** @var Collection $collection */
        $collection = $this->getSearchResult();

        $collection
                ->addFieldToSelect([
                    'id',
                    'title',
                    'link',
        ]);
        $collection->addFieldToFilter('status', 1);

        $data = $this->searchResultToOutput($collection);
        return $data;
    }
}

Please let me know if I need to provide any more code.

  • Anyone please respond to the question, please let me know if need to explain any part... I am waiting and finding a way... – Ashish Raj Feb 18 '18 at 12:45
  • HI Ashis, I want to know the insertListing concept with dynamic grid. Could you please let me know the details. – rajat kara Aug 31 '18 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.