Closed francescorm closed 2 years ago
I'm having the same problem. Did you find a fix for this?
Hi there, no i'm sorry but i have plan to check it.
On 27/01/22 08:21, jubalin wrote:
I'm having the same problem. Did you find a fix for this?
— Reply to this email directly, view it on GitHub https://github.com/Smile-SA/magento2-module-custom-entity/issues/32#issuecomment-1022917163, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALNDETTAAGENGG6UARWM4BLUYDW7BANCNFSM5IY2UYHQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
I got a fix for this. I've overridden \Smile\ScopedEav\Ui\DataProvider\Entity\Form\Modifier\Eav in a custom module until the module is updated, it'w working fine. This is my fix:
`<?php
namespace W2e\SmileEntityOverride\Ui\DataProvider\Entity\Form\Modifier;
use Magento\Catalog\Model\Category\FileInfo; use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute; use Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory as EavAttributeFactory; use Magento\Ui\Component\Form\Element\Wysiwyg as WysiwygElement; use Magento\Ui\Component\Form\Field; use Smile\ScopedEav\Api\Data\AttributeInterface;
class Eav extends \Smile\ScopedEav\Ui\DataProvider\Entity\Form\Modifier\Eav { /**
@var Helper\Eav */ private $eavHelper;
/**
@var \Smile\ScopedEav\Model\Locator\LocatorInterface */ private $locator;
/**
@var \Magento\Framework\Stdlib\ArrayManager */ private $arrayManager;
/**
@var \Smile\ScopedEav\Ui\DataProvider\Entity\Form\EavValidationRules */ private $validationRules;
/**
@var \Magento\Framework\App\Request\DataPersistorInterface */ private $dataPersistor;
/**
@var array */ private $bannedInputTypes;
/**
@var array */ private $attributesToEliminate;
/**
@var array */ private $attributesToDisable;
/**
@var FileInfo */ private $fileInfo;
/**
@var array */ private $attributesCache = [];
/**
@since 101.0.0 */ protected $eavAttributeFactory;
/**
@param array $attributesToDisable Attribute codes to be disabled. */ public function construct( \Smile\ScopedEav\Ui\DataProvider\Entity\Form\Modifier\Helper\Eav $eavHelper, \Smile\ScopedEav\Model\Locator\LocatorInterface $locator, \Magento\Framework\Stdlib\ArrayManager $arrayManager, \Smile\ScopedEav\Ui\DataProvider\Entity\Form\EavValidationRules $validationRules, \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor, EavAttributeFactory $eavAttributeFactory, FileInfo $fileInfo, array $bannedInputTypes = [], array $attributesToEliminate = [], array $attributesToDisable = [] ) { $this->eavHelper = $eavHelper; $this->locator = $locator; $this->arrayManager = $arrayManager; $this->bannedInputTypes = $bannedInputTypes; $this->validationRules = $validationRules; $this->dataPersistor = $dataPersistor; $this->attributesToEliminate = $attributesToEliminate; $this->attributesToDisable = $attributesToDisable; $this->fileInfo = $fileInfo; $this->eavAttributeFactory = $eavAttributeFactory; parent::construct($eavHelper, $locator, $arrayManager, $validationRules, $dataPersistor, $fileInfo); }
/**
@return array */ public function setupAttributeMeta(AttributeInterface $attribute, $groupCode, $sortOrder) { $configPath = static::META_CONFIG_PATH;
$meta = $this->arrayManager->set($configPath, [], [
'dataType' => $attribute->getFrontendInput(),
'formElement' => $this->eavHelper->getFormElement($attribute->getFrontendInput()),
'visible' => true,
'required' => $attribute->getIsRequired(),
'notice' => $attribute->getNote(),
'default' => $attribute->getDefaultValue(),
'label' => $attribute->getDefaultFrontendLabel(),
'code' => $attribute->getAttributeCode(),
'source' => $groupCode,
'scopeLabel' => $this->getScopeLabel($attribute),
'globalScope' => $this->isScopeGlobal($attribute),
'sortOrder' => $sortOrder * self::SORT_ORDER_MULTIPLIER,
]);
$attributeModel = $this->getAttributeModel($attribute);
if ($attributeModel->usesSource()) {
$source = $attributeModel->getSource();
$options = $source->getAllOptions();
$meta = $this->arrayManager->merge($configPath, $meta, ['options' => $this->convertOptionsValueToString($options)]);
}
if ($this->canDisplayUseDefault($attribute)) {
$meta = $this->arrayManager->merge($configPath, $meta, ['service' => ['template' => 'ui/form/element/helper/service']]);
}
if (!$this->arrayManager->exists($configPath . '/componentType', $meta)) {
$meta = $this->arrayManager->merge($configPath, $meta, ['componentType' => Field::NAME]);
}
if (in_array($attribute->getAttributeCode(), $this->attributesToDisable)) {
$meta = $this->arrayManager->merge($configPath, $meta, ['disabled' => true]);
}
$childData = $this->arrayManager->get($configPath, $meta, []);
if (($rules = $this->validationRules->build($attribute, $childData))) {
$meta = $this->arrayManager->merge($configPath, $meta, ['validation' => $rules]);
}
$meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
switch ($attribute->getFrontendInput()) {
case 'boolean':
$meta = $this->customizeCheckbox($attribute, $meta);
break;
case 'textarea':
$meta = $this->customizeWysiwyg($attribute, $meta);
break;
case 'image':
$meta = $this->customizeImage($attribute, $meta);
break;
}
return $meta;
}
/**
@return array */ private function convertOptionsValueToString(array $options) : array { array_walk( $options, function (&$value) { if (isset($value['value']) && is_scalar($value['value'])) { $value['value'] = (string)$value['value']; } } );
return $options;
}
private function getAttributeModel($attribute) { // The statement below solves performance issue related to loading same attribute options on different models if ($attribute instanceof EavAttribute) { return $attribute; } $attributeId = $attribute->getAttributeId();
if (!array_key_exists($attributeId, $this->attributesCache)) {
$this->attributesCache[$attributeId] = $this->eavAttributeFactory->create()->load($attributeId);
}
return $this->attributesCache[$attributeId];
}
/**
@return bool */ private function isScopeGlobal(AttributeInterface $attribute) { return $this->eavHelper->isScopeGlobal($attribute); }
/**
@return bool */ private function canDisplayUseDefault(AttributeInterface $attribute) { return $this->eavHelper->canDisplayUseDefault($attribute, $this->locator->getEntity()); }
/**
@return \Magento\Framework\Phrase|string */ private function getScopeLabel(AttributeInterface $attribute) { return $this->eavHelper->getScopeLabel($attribute); }
/**
@return array */ private function addUseDefaultValueCheckbox(AttributeInterface $attribute, array $meta) { $canDisplayService = $this->canDisplayUseDefault($attribute);
if ($canDisplayService) {
$storeId = $this->locator->getStore()->getId();
$entity = $this->locator->getEntity();
$meta['arguments']['data']['config']['service'] = ['template' => 'ui/form/element/helper/service'];
$meta['arguments']['data']['config']['disabled'] = !$this->eavHelper->hasValueForStore($entity, $attribute, $storeId);
}
return $meta;
}
/**
@return array */ private function customizeWysiwyg(AttributeInterface $attribute, array $meta) { if (!$attribute->getIsWysiwygEnabled()) { return $meta; }
$meta['arguments']['data']['config']['formElement'] = WysiwygElement::NAME;
$meta['arguments']['data']['config']['wysiwyg'] = true;
$meta['arguments']['data']['config']['wysiwygConfigData'] = [
'add_variables' => false,
'add_widgets' => false,
'add_directives' => true,
'use_container' => true,
'container_class' => 'hor-scroll',
];
return $meta;
}
/**
@return array */ private function customizeCheckbox(AttributeInterface $attribute, array $meta) { if ($attribute->getFrontendInput() === 'boolean') { $meta['arguments']['data']['config']['prefer'] = 'toggle'; $meta['arguments']['data']['config']['valueMap'] = [ 'true' => '1', 'false' => '0', ]; }
return $meta;
}
/**
@return array */ private function customizeImage(AttributeInterface $attribute, array $meta) { if ($attribute->getFrontendInput() !== 'image') { return $meta; } $meta['arguments']['data']['config']['formElement'] = 'fileUploader'; $meta['arguments']['data']['config']['allowedExtensions'] = 'jpg jpeg gif png'; $meta['arguments']['data']['config']['elementTmpl'] = 'ui/form/element/uploader/image'; $meta['arguments']['data']['config']['uploaderConfig'] = [ 'url' => 'scoped_eav/entity/image_upload', ];
return $meta;
} } `
Thank you @jublm i will push a new release this morning
When you add multiselect attribute and try to open an entity you will receive this error
1 exception(s): Exception #0 (ReflectionException): Class does not exist
Exception #0 (ReflectionException): Class does not exist