3

I am getting this error in magento Ui component admin form , it tried changing container instead of form in Ui form , but that did not help either.

Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught Error: Call to a member function setId() on boolean in /opt/lampp/htdocs/Magentos226/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line 0

DataSource in Ui Form

<dataSource name="item_form_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Vendor\Module\Model\Item\DataProvider</argument>
        <argument name="name" xsi:type="string">igallery_form_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="submit_url" xsi:type="url" path="module/item/save"/>
            </item>
        </argument>
    </argument>
    <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>
</dataSource>

Media Uploader Code in Ui Form

<htmlContent name="gallery" sortOrder="22">
    <argument name="data" xsi:type="array">
        <item name="wrapper" xsi:type="array">
            <item name="label" xsi:type="string" translate="true"> Images</item>
            <item name="collapsible" xsi:type="boolean">true</item>
            <item name="opened" xsi:type="boolean">true</item>
        </item>
    </argument>
    <settings>
        <wrapper>
            <canShow>true</canShow>
            <componentType>fieldset</componentType>
        </wrapper>
    </settings>
    <block name="gallery" class="Vendor\Module\Block\Adminhtml\Media\Helper\Form\Gallery">
        <block class="Vendor\Events\Block\Adminhtml\Media\Helper\Form\Gallery\Image" as="content">
            <arguments>
                <argument name="config" xsi:type="array">
                    <item name="parentComponent" xsi:type="string">module_article_form.module_article_form.block_gallery.block_gallery</item>
                </argument>
            </arguments>                
        </block>
    </block>
</htmlContent> 

DataProvider

<?php

namespace Vendor\Module\Model\Item;

use Vendor\Module\Model\ResourceModel\Item\CollectionFactory;
use Magento\Framework\App\Request\DataPersistorInterface;

class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
{
  protected $collection;
  protected $dataPersistor;
  public $_storeManager;
  protected $loadedData;

public function __construct(
    $name,
    $primaryFieldName,
    $requestFieldName,
    CollectionFactory $blockCollectionFactory,
    DataPersistorInterface $dataPersistor,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    array $meta = [],
    array $data = []
) {
    $this->collection = $blockCollectionFactory->create();
    $this->_storeManager=$storeManager;
    $this->dataPersistor = $dataPersistor;
    parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
}

public function getData()
{
    if (isset($this->loadedData)) {
        return $this->loadedData;
    }
    $items = $this->collection->getItems();

    foreach ($items as $page) {
        $this->loadedData[$page->getId()] = $page->getData();
    }

    $data = $this->dataPersistor->get('media-item');
    if (!empty($data)) {
        $page = $this->collection->getNewEmptyItem();
        $page->setData($data);
        $this->loadedData[$page->getId()] = $page->getData();
        $this->dataPersistor->clear('media-item');
    }

    return $this->loadedData;
  }
}
2
  • 2
    share your code Commented Oct 15, 2018 at 6:39
  • Ranjit Shinde relevant code is added please check
    – Verdu
    Commented Oct 15, 2018 at 9:06

1 Answer 1

3

Check for typo in code make sure your block path is correct Vendor\ModuleName\Block\Adminhtml\Media\Helper\Form\Gallery\Image i check this code it is working for me.

<htmlContent name="gallery" sortOrder="22">
    <argument name="data" xsi:type="array">
        <item name="wrapper" xsi:type="array">
            <item name="label" xsi:type="string" translate="true"> Images</item>
            <item name="collapsible" xsi:type="boolean">true</item>
            <item name="opened" xsi:type="boolean">true</item>
        </item>
    </argument>
    <settings>
        <wrapper>
            <canShow>true</canShow>
            <componentType>fieldset</componentType>
        </wrapper>
    </settings>
    <block name="gallery" class="Vendor\Module\Block\Adminhtml\Media\Helper\Form\Gallery">
        <block class="Vendor\Events\Block\Adminhtml\Media\Helper\Form\Gallery\Image" as="content">
            <arguments>
                <argument name="config" xsi:type="array">
                    <item name="parentComponent" xsi:type="string">module_article_form.module_article_form.block_gallery.block_gallery</item>
                </argument>
            </arguments>                
        </block>
    </block>
</htmlContent>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.