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;
}
}