158 \
Magento\Framework\Module\Dir\Reader $modulesReader,
164 if (empty($this->_moduleName)) {
165 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The current module pathname is undefined.'));
167 if (empty($this->_entityTypeCode)) {
168 throw new \Magento\Framework\Exception\LocalizedException(
169 __(
'The current module EAV entity is undefined.')
174 $this->_modulesReader = $modulesReader;
175 $this->_attrDataFactory = $attrDataFactory;
176 $this->_universalFactory = $universalFactory;
177 $this->_httpRequest = $httpRequest;
178 $this->_validatorConfigFactory = $validatorConfigFactory;
188 return $this->_universalFactory->create(
189 str_replace(
'_',
'\\', $this->_moduleName) .
'\\Model\\ResourceModel\\Form\\Attribute\\Collection' 204 )->addFormCodeFilter(
218 $this->_store = $this->_storeManager->getStore(
$store);
231 if (
$entity->getEntityTypeId()) {
245 $this->_entityType = $this->_eavConfig->getEntityType(
$entityType);
257 $this->_formCode = $formCode;
268 if ($this->_store ===
null) {
269 $this->_store = $this->_storeManager->getStore();
282 if (empty($this->_formCode)) {
283 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The form code is not defined.'));
296 if ($this->_entityType ===
null) {
310 if ($this->_entity ===
null) {
311 throw new \Magento\Framework\Exception\LocalizedException(
__(
'The entity instance is not defined.'));
321 public function getAttributes()
323 if ($this->_attributes ===
null) {
324 $this->_attributes = [];
325 $this->_userAttributes = [];
364 if ($this->_userAttributes ===
null) {
366 $this->getAttributes();
378 if ($this->_systemAttributes ===
null) {
380 $this->getAttributes();
392 if ($this->_allowedAttributes ===
null) {
394 $this->getAttributes();
441 $dataModel->setRequestScope($scope);
442 $dataModel->setRequestScopeOnly($scopeOnly);
454 protected function _getValidator(array
$data)
456 if ($this->_validator ===
null) {
457 $configFiles = $this->_modulesReader->getConfigurationFiles(
'validation.xml');
459 $validatorFactory = $this->_validatorConfigFactory->create([
'configFiles' => $configFiles]);
460 $builder = $validatorFactory->createValidatorBuilder(
'eav_entity',
'form');
462 $builder->addConfiguration(
463 'eav_data_validator',
466 $builder->addConfiguration(
467 'eav_data_validator',
468 [
'method' =>
'setData',
'arguments' => [
$data]]
470 $this->_validator = $builder->createValidator();
483 $validator = $this->_getValidator(
$data);
484 if (!$validator->isValid($this->getEntity())) {
486 foreach ($validator->getMessages() as $errorMessages) {
487 $messages = array_merge($messages, (array)$errorMessages);
500 public function compactData(array
$data)
505 $dataModel->setExtractedData(
$data);
521 public function restoreData(array
$data)
526 $dataModel->setExtractedData(
$data);
547 $dataModel->setExtractedData(
$data);
558 public function resetEntityData()
562 $value = $this->
getEntity()->getOrigData($attribute->getAttributeCode());
576 $this->_isAjax = (bool)$flag;
596 public function initDefaultValues()
600 foreach ($this->getAttributes() as
$attribute) {
602 if ($default !=
'') {
603 $this->
getEntity()->setData($attribute->getAttributeCode(), $default);
618 if (
null !== $setValue) {
619 $this->_ignoreInvisible = (bool)$setValue;
633 if ($this->_ignoreInvisible && !
$attribute->getIsVisible()) {