I've created my custom entity (EAV). I could see all fields on edit page of single entity.
app/code/Klever/ProductPricing/Controller/Adminhtml/WallMaterial/Edit.php
public function execute() { // 1. Get ID and create model $id = $this->getRequest()->getParam('entity_id'); $model = $this->_objectManager->create(\Klever\ProductPricing\Model\WallMaterial::class); // 2. Initial checking if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This Wallmaterial no longer exists.')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } $this->_coreRegistry->register('klever_productpricing_wallmaterial', $model); // 3. Build edit form /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $this->initPage($resultPage)->addBreadcrumb( $id ? __('Edit Wallmaterial') : __('New Wallmaterial'), $id ? __('Edit Wallmaterial') : __('New Wallmaterial') ); $resultPage->getConfig()->getTitle()->prepend(__('Wallmaterials')); $resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Wallmaterial %1', $model->getId()) : __('New Wallmaterial')); return $resultPage; }
Here is how I try to pass data to custom column of my admin list.
app/code/Klever/ProductPricing/Ui/Component/Listing/Column/Thumbnail.php
public function prepareDataSource(array $dataSource) { if(isset($dataSource['data']['items'])) { $fieldName = $this->getData('name'); foreach($dataSource['data']['items'] as & $item) { // TODO GET EAV ATTRIBUTE VALUE $attribute = $this->eavConfig->getAttribute(\Klever\ProductPricing\Model\WallMaterial::ENTITY, 'image'); // $options = $attribute->getSource()->getAllOptions(); // $model = $this->_objectManager->create(\Klever\ProductPricing\Model\WallMaterial::class); // $model->load($item['entity_id']); $eav = $this->wallMaterialResourceModel->getItemById($item['entity_id']); $url = ''; if(isset($item[$fieldName]) && $item[$fieldName] != '') { $url = $this->urlBuilder->getUrl( static::URL_PATH_EDIT, [ 'entity_id' => $item['entity_id'] ] ); } $item[$fieldName . '_src'] = $url; $item[$fieldName . '_alt'] = $this->getAlt($item) ?: ''; $item[$fieldName . '_link'] = $this->urlBuilder->getUrl( static::URL_PATH_EDIT, ['entity_id' => $item['entity_id']] ); $item[$fieldName . '_orig_src'] = $url; } } return $dataSource; }
But when I am on listing page I have an access just to main attribute 'title' of my entity.
I've tried to edit _initSelect() method @ app/code/Klever/ProductPricing/Model/ResourceModel/WallMaterial/Collection.php
like:
protected function _initSelect() { $this->getSelect()->from( ['klever_wallmaterial_entity'], ['*'] )->join( ['klever_wallmaterial_entity_datetime'], 'klever_wallmaterial_entity_datetime.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_decimal'], 'klever_wallmaterial_entity_decimal.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_int'], 'klever_wallmaterial_entity_int.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_text'], 'klever_wallmaterial_entity_text.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_varchar'], 'klever_wallmaterial_entity_varchar.entity_id = klever_wallmaterial_entity.entity_id' ); return $this; }
But it did not help. I constantly see just title and empty orig_data array. How could I get all my attributes on my entity?
app/code/Klever/ProductPricing/view/adminhtml/ui_component/klever_wallmaterial_entity_listing.xml
<?xml version="1.0" ?>
<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">klever_wallmaterial_entity_listing.klever_wallmaterial_entity_listing_data_source</item>
</item>
</argument>
<settings>
<spinner>klever_wallmaterial_entity_columns</spinner>
<deps>
<dep>klever_wallmaterial_entity_listing.klever_wallmaterial_entity_listing_data_source</dep>
</deps>
<buttons>
<button name="add">
<url path="*/*/new"/>
<class>primary</class>
<label translate="true">Add new WallMaterial</label>
</button>
</buttons>
</settings>
<dataSource component="Magento_Ui/js/grid/provider" name="klever_wallmaterial_entity_listing_data_source">
<settings>
<updateUrl path="mui/index/render"/>
</settings>
<aclResource>Klever_ProductPricing::WallMaterial</aclResource>
<dataProvider class="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" name="klever_wallmaterial_entity_listing_data_source">
<settings>
<requestFieldName>id</requestFieldName>
<primaryFieldName>entity_id</primaryFieldName>
</settings>
</dataProvider>
</dataSource>
<listingToolbar name="listing_top">
<settings>
<sticky>true</sticky>
</settings>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="klever_wallmaterial_entity_columns">
<settings>
<editorConfig>
<param name="selectProvider" xsi:type="string">klever_wallmaterial_entity_listing.klever_wallmaterial_entity_listing.klever_wallmaterial_entity_columns.ids</param>
<param name="enabled" xsi:type="boolean">true</param>
<param name="indexField" xsi:type="string">entity_id</param>
<param name="clientConfig" xsi:type="array">
<item name="saveUrl" path="klever_productpricing/WallMaterial/inlineEdit" xsi:type="url"/>
<item name="validateBeforeSave" xsi:type="boolean">false</item>
</param>
</editorConfig>
<childDefaults>
<param name="fieldAction" xsi:type="array">
<item name="provider" xsi:type="string">klever_wallmaterial_entity_listing.klever_wallmaterial_entity_listing.klever_wallmaterial_entity_columns_editor</item>
<item name="target" xsi:type="string">startEdit</item>
<item name="params" xsi:type="array">
<item name="0" xsi:type="string">${ $.$data.rowIndex }</item>
<item name="1" xsi:type="boolean">true</item>
</item>
</param>
</childDefaults>
</settings>
<selectionsColumn name="ids">
<settings>
<indexField>entity_id</indexField>
</settings>
</selectionsColumn>
<column name="entity_id">
<settings>
<filter>text</filter>
<sorting>asc</sorting>
<label translate="true">ID</label>
</settings>
</column>
<column name="title">
<settings>
<filter>text</filter>
<label translate="true">title</label>
<editor>
<editorType>text</editorType>
<validation>
<rule name="required-entry" xsi:type="boolean">false</rule>
</validation>
</editor>
</settings>
</column>
<column name="image" class="Klever\ProductPricing\Ui\Component\Listing\Column\Thumbnail">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/thumbnail</item>
<item name="sortable" xsi:type="boolean">false</item>
<item name="altField" xsi:type="string">image</item>
<item name="has_preview" xsi:type="string">1</item>
<item name="label" xsi:type="string" translate="true">Image</item>
<item name="resizeEnabled" xsi:type="boolean">true</item>
<item name="resizeDefaultWidth" xsi:type="string">300</item>
</item>
</argument>
</column>
<actionsColumn class="Klever\ProductPricing\Ui\Component\Listing\Column\WallMaterialActions" name="actions">
<settings>
<indexField>entity_id</indexField>
<resizeEnabled>false</resizeEnabled>
<resizeDefaultWidth>107</resizeDefaultWidth>
</settings>
</actionsColumn>
</columns>
</listing>
I have exactly the same problem. Anyone got a suggestion? This is quiet a common issue , please suggest me if you find any solution for it targetpayandbenefits
@guess4me wrote:
I've created my custom entity (EAV). I could see all fields on edit page of single e...app/code/Klever/ProductPricing/Controller/Adminhtml/WallMaterial/Edit.php
public function execute() { // 1. Get ID and create model $id = $this->getRequest()->getParam('entity_id'); $model = $this->_objectManager->create(\Klever\ProductPricing\Model\WallMaterial::class); // 2. Initial checking if ($id) { $model->load($id); if (!$model->getId()) { $this->messageManager->addErrorMessage(__('This Wallmaterial no longer exists.')); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); return $resultRedirect->setPath('*/*/'); } } $this->_coreRegistry->register('klever_productpricing_wallmaterial', $model); // 3. Build edit form /** @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $this->initPage($resultPage)->addBreadcrumb( $id ? __('Edit Wallmaterial') : __('New Wallmaterial'), $id ? __('Edit Wallmaterial') : __('New Wallmaterial') ); $resultPage->getConfig()->getTitle()->prepend(__('Wallmaterials')); $resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Wallmaterial %1', $model->getId()) : __('New Wallmaterial')); return $resultPage; }
Here is how I try to pass data to custom column of my admin list.app/code/Klever/ProductPricing/Ui/Component/Listing/Column/Thumbnail.php
public function prepareDataSource(array $dataSource) { if(isset($dataSource['data']['items'])) { $fieldName = $this->getData('name'); foreach($dataSource['data']['items'] as & $item) { // TODO GET EAV ATTRIBUTE VALUE $attribute = $this->eavConfig->getAttribute(\Klever\ProductPricing\Model\WallMaterial::ENTITY, 'image'); // $options = $attribute->getSource()->getAllOptions(); // $model = $this->_objectManager->create(\Klever\ProductPricing\Model\WallMaterial::class); // $model->load($item['entity_id']); $eav = $this->wallMaterialResourceModel->getItemById($item['entity_id']); $url = ''; if(isset($item[$fieldName]) && $item[$fieldName] != '') { $url = $this->urlBuilder->getUrl( static::URL_PATH_EDIT, [ 'entity_id' => $item['entity_id'] ] ); } $item[$fieldName . '_src'] = $url; $item[$fieldName . '_alt'] = $this->getAlt($item) ?: ''; $item[$fieldName . '_link'] = $this->urlBuilder->getUrl( static::URL_PATH_EDIT, ['entity_id' => $item['entity_id']] ); $item[$fieldName . '_orig_src'] = $url; } } return $dataSource; }But when I am on listing page I have an access just to main attribute 'title' of my entity.
I've tried to edit _initSelect() method @ app/code/Klever/ProductPricing/Model/ResourceModel/WallMaterial/Collection.php
like:
protected function _initSelect() { $this->getSelect()->from( ['klever_wallmaterial_entity'], ['*'] )->join( ['klever_wallmaterial_entity_datetime'], 'klever_wallmaterial_entity_datetime.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_decimal'], 'klever_wallmaterial_entity_decimal.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_int'], 'klever_wallmaterial_entity_int.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_text'], 'klever_wallmaterial_entity_text.entity_id = klever_wallmaterial_entity.entity_id' )->join( ['klever_wallmaterial_entity_varchar'], 'klever_wallmaterial_entity_varchar.entity_id = klever_wallmaterial_entity.entity_id' ); return $this; }But it did not help. I constantly see just title and empty orig_data array. How could I get all my attributes on my entity?
@guess4me
EAV (Entity-attribute-value) is a model of storing the values of entity attributes in a certain data storage. As a data storage, Magento 2 supports MySQL-compatible databases (like MySQL, MySQL NDB Cluster, MariaDB, Percona and others).
The principles of EAV data storage work in Magento
What happens when a new attribute is added to the system
A table of the classical EAV model has 3 columns:
In the Flat model, the attribute values are stored in the same table as the entities, for each attribute, a separate column in the table is created.
In the EAV model, attribute values are stored in a separate table, where a separate column is not created for each attribute. For each attribute value of an entity, however, a new row is created in the EAV table. Americanexpress.com/confirmcard