Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Eav Class Reference
Inheritance diagram for Eav:
AbstractModifier ModifierInterface

Public Member Functions

 __construct (LocatorInterface $locator, CatalogEavValidationRules $catalogEavValidationRules, Config $eavConfig, RequestInterface $request, GroupCollectionFactory $groupCollectionFactory, StoreManagerInterface $storeManager, FormElementMapper $formElementMapper, MetaPropertiesMapper $metaPropertiesMapper, ProductAttributeGroupRepositoryInterface $attributeGroupRepository, ProductAttributeRepositoryInterface $attributeRepository, SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderBuilder $sortOrderBuilder, EavAttributeFactory $eavAttributeFactory, Translit $translitFilter, ArrayManager $arrayManager, ScopeOverriddenValue $scopeOverriddenValue, DataPersistorInterface $dataPersistor, $attributesToDisable=[], $attributesToEliminate=[], CompositeConfigProcessor $wysiwygConfigProcessor=null, ScopeConfigInterface $scopeConfig=null, AttributeCollectionFactory $attributeCollectionFactory=null)
 
 modifyMeta (array $meta)
 
 addContainerChildren (array $attributeContainer, ProductAttributeInterface $attribute, $groupCode, $sortOrder)
 
 getContainerChildren (ProductAttributeInterface $attribute, $groupCode, $sortOrder)
 
 setupAttributeMeta (ProductAttributeInterface $attribute, $groupCode, $sortOrder)
 
 setupAttributeContainerMeta (ProductAttributeInterface $attribute)
 
 setupAttributeData (ProductAttributeInterface $attribute)
 
- Public Member Functions inherited from ModifierInterface
 modifyData (array $data)
 

Data Fields

const SORT_ORDER_MULTIPLIER = 10
 
- Data Fields inherited from AbstractModifier
const FORM_NAME = 'product_form'
 
const DATA_SOURCE_DEFAULT = 'product'
 
const DATA_SCOPE_PRODUCT = 'data.product'
 
const DEFAULT_GENERAL_PANEL = 'product-details'
 
const GENERAL_PANEL_ORDER = 10
 
const CONTAINER_PREFIX = 'container_'
 
const META_CONFIG_PATH = '/arguments/data/config'
 

Protected Member Functions

 formatPrice ($value)
 
- Protected Member Functions inherited from AbstractModifier
 getNextGroupSortOrder (array $meta, $groupCodes, $defaultSortOrder, $iteration=1)
 
 getNextAttributeSortOrder (array $meta, $attributeCodes, $defaultSortOrder, $iteration=1)
 
 startsWith ($haystack, $needle)
 
 getGeneralPanelName (array $meta)
 
 getFirstPanelCode (array $meta)
 
 getGroupCodeByField (array $meta, $field)
 
 formatPrice ($value)
 
 formatWeight ($value)
 

Protected Attributes

 $locator
 
 $eavConfig
 
 $catalogEavValidationRules
 
 $request
 
 $groupCollectionFactory
 
 $storeManager
 
 $formElementMapper
 
 $metaPropertiesMapper
 
 $attributeGroupRepository
 
 $searchCriteriaBuilder
 
 $attributeRepository
 
 $sortOrderBuilder
 
 $eavAttributeFactory
 
 $translitFilter
 
 $arrayManager
 
 $attributesToEliminate
 
 $dataPersistor
 

Detailed Description

Class Eav

@api

@SuppressWarnings(PHPMD.CouplingBetweenObjects) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity)

Since
101.0.0

Definition at line 48 of file Eav.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( LocatorInterface  $locator,
CatalogEavValidationRules  $catalogEavValidationRules,
Config  $eavConfig,
RequestInterface  $request,
GroupCollectionFactory  $groupCollectionFactory,
StoreManagerInterface  $storeManager,
FormElementMapper  $formElementMapper,
MetaPropertiesMapper  $metaPropertiesMapper,
ProductAttributeGroupRepositoryInterface  $attributeGroupRepository,
ProductAttributeRepositoryInterface  $attributeRepository,
SearchCriteriaBuilder  $searchCriteriaBuilder,
SortOrderBuilder  $sortOrderBuilder,
EavAttributeFactory  $eavAttributeFactory,
Translit  $translitFilter,
ArrayManager  $arrayManager,
ScopeOverriddenValue  $scopeOverriddenValue,
DataPersistorInterface  $dataPersistor,
  $attributesToDisable = [],
  $attributesToEliminate = [],
CompositeConfigProcessor  $wysiwygConfigProcessor = null,
ScopeConfigInterface  $scopeConfig = null,
AttributeCollectionFactory  $attributeCollectionFactory = null 
)

Eav constructor.

Parameters
LocatorInterface$locator
CatalogEavValidationRules$catalogEavValidationRules
Config$eavConfig
RequestInterface$request
GroupCollectionFactory$groupCollectionFactory
StoreManagerInterface$storeManager
FormElementMapper$formElementMapper
MetaPropertiesMapper$metaPropertiesMapper
ProductAttributeGroupRepositoryInterface$attributeGroupRepository
ProductAttributeRepositoryInterface$attributeRepository
SearchCriteriaBuilder$searchCriteriaBuilder
SortOrderBuilder$sortOrderBuilder
EavAttributeFactory$eavAttributeFactory
Translit$translitFilter
ArrayManager$arrayManager
ScopeOverriddenValue$scopeOverriddenValue
DataPersistorInterface$dataPersistor
array$attributesToDisable
array$attributesToEliminate
CompositeConfigProcessor | null$wysiwygConfigProcessor
ScopeConfigInterface | null$scopeConfig
AttributeCollectionFactory$attributeCollectionFactory@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 241 of file Eav.php.

264  {
265  $this->locator = $locator;
266  $this->catalogEavValidationRules = $catalogEavValidationRules;
267  $this->eavConfig = $eavConfig;
268  $this->request = $request;
269  $this->groupCollectionFactory = $groupCollectionFactory;
270  $this->storeManager = $storeManager;
271  $this->formElementMapper = $formElementMapper;
272  $this->metaPropertiesMapper = $metaPropertiesMapper;
273  $this->attributeGroupRepository = $attributeGroupRepository;
274  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
275  $this->attributeRepository = $attributeRepository;
276  $this->sortOrderBuilder = $sortOrderBuilder;
277  $this->eavAttributeFactory = $eavAttributeFactory;
278  $this->translitFilter = $translitFilter;
279  $this->arrayManager = $arrayManager;
280  $this->scopeOverriddenValue = $scopeOverriddenValue;
281  $this->dataPersistor = $dataPersistor;
282  $this->attributesToDisable = $attributesToDisable;
283  $this->attributesToEliminate = $attributesToEliminate;
284  $this->wysiwygConfigProcessor = $wysiwygConfigProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
285  ->get(CompositeConfigProcessor::class);
286  $this->scopeConfig = $scopeConfig ?: \Magento\Framework\App\ObjectManager::getInstance()
287  ->get(ScopeConfigInterface::class);
288  $this->attributeCollectionFactory = $attributeCollectionFactory
289  ?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeCollectionFactory::class);
290  }

Member Function Documentation

◆ addContainerChildren()

addContainerChildren ( array  $attributeContainer,
ProductAttributeInterface  $attribute,
  $groupCode,
  $sortOrder 
)

Add container children

Parameters
array$attributeContainer
ProductAttributeInterface$attribute
string$groupCode
int$sortOrder
Returns
array @api
Since
101.0.0

Definition at line 363 of file Eav.php.

368  {
369  foreach ($this->getContainerChildren($attribute, $groupCode, $sortOrder) as $childCode => $child) {
370  $attributeContainer['children'][$childCode] = $child;
371  }
372 
373  $attributeContainer = $this->arrayManager->merge(
374  ltrim(static::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER),
375  $attributeContainer,
376  [
377  'sortOrder' => $sortOrder * self::SORT_ORDER_MULTIPLIER
378  ]
379  );
380 
381  return $attributeContainer;
382  }
getContainerChildren(ProductAttributeInterface $attribute, $groupCode, $sortOrder)
Definition: Eav.php:394

◆ formatPrice()

formatPrice (   $value)
protected

Format price according to the locale of the currency

Parameters
mixed$value
Returns
string
Since
101.0.0

Definition at line 1039 of file Eav.php.

1040  {
1041  if (!is_numeric($value)) {
1042  return null;
1043  }
1044 
1045  $store = $this->storeManager->getStore();
1046  $currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
1047  $value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
1048 
1049  return $value;
1050  }
$value
Definition: gender.phtml:16

◆ getContainerChildren()

getContainerChildren ( ProductAttributeInterface  $attribute,
  $groupCode,
  $sortOrder 
)

Retrieve container child fields

Parameters
ProductAttributeInterface$attribute
string$groupCode
int$sortOrder
Returns
array @api
Since
101.0.0

Definition at line 394 of file Eav.php.

395  {
396  if (!($child = $this->setupAttributeMeta($attribute, $groupCode, $sortOrder))) {
397  return [];
398  }
399 
400  return [$attribute->getAttributeCode() => $child];
401  }
setupAttributeMeta(ProductAttributeInterface $attribute, $groupCode, $sortOrder)
Definition: Eav.php:630

◆ modifyMeta()

modifyMeta ( array  $meta)

Parameters
array$meta
Returns
array
Since
100.1.0

Since
101.0.0

Implements ModifierInterface.

Definition at line 296 of file Eav.php.

297  {
298  $sortOrder = 0;
299 
300  foreach ($this->getGroups() as $groupCode => $group) {
301  $attributes = !empty($this->getAttributes()[$groupCode]) ? $this->getAttributes()[$groupCode] : [];
302 
303  if ($attributes) {
304  $meta[$groupCode]['children'] = $this->getAttributesMeta($attributes, $groupCode);
305  $meta[$groupCode]['arguments']['data']['config']['componentType'] = Fieldset::NAME;
306  $meta[$groupCode]['arguments']['data']['config']['label'] = __($group->getAttributeGroupName());
307  $meta[$groupCode]['arguments']['data']['config']['collapsible'] = true;
308  $meta[$groupCode]['arguments']['data']['config']['dataScope'] = self::DATA_SCOPE_PRODUCT;
309  $meta[$groupCode]['arguments']['data']['config']['sortOrder'] =
310  $sortOrder * self::SORT_ORDER_MULTIPLIER;
311  }
312 
313  $sortOrder++;
314  }
315 
316  return $meta;
317  }
$group
Definition: sections.phtml:16
__()
Definition: __.php:13

◆ setupAttributeContainerMeta()

setupAttributeContainerMeta ( ProductAttributeInterface  $attribute)

Setup attribute container meta

Parameters
ProductAttributeInterface$attribute
Returns
array @api
Since
101.0.0

Definition at line 778 of file Eav.php.

779  {
780  $containerMeta = $this->arrayManager->set(
781  'arguments/data/config',
782  [],
783  [
784  'formElement' => 'container',
785  'componentType' => 'container',
786  'breakLine' => false,
787  'label' => $attribute->getDefaultFrontendLabel(),
788  'required' => $attribute->getIsRequired(),
789  ]
790  );
791 
792  if ($attribute->getIsWysiwygEnabled()) {
793  $containerMeta = $this->arrayManager->merge(
794  'arguments/data/config',
795  $containerMeta,
796  [
797  'component' => 'Magento_Ui/js/form/components/group'
798  ]
799  );
800  }
801 
802  return $containerMeta;
803  }

◆ setupAttributeData()

setupAttributeData ( ProductAttributeInterface  $attribute)

Setup attribute data

Parameters
ProductAttributeInterface$attribute
Returns
mixed|null @api
Since
101.0.0

Definition at line 813 of file Eav.php.

814  {
815  $product = $this->locator->getProduct();
816  $productId = $product->getId();
817  $prevSetId = $this->getPreviousSetId();
818  $notUsed = !$prevSetId
819  || ($prevSetId && !in_array($attribute->getAttributeCode(), $this->getPreviousSetAttributes()));
820 
821  if ($productId && $notUsed) {
822  return $this->getValue($attribute);
823  }
824 
825  return null;
826  }

◆ setupAttributeMeta()

setupAttributeMeta ( ProductAttributeInterface  $attribute,
  $groupCode,
  $sortOrder 
)

Initial meta setup

Parameters
ProductAttributeInterface$attribute
string$groupCode
int$sortOrder
Returns
array
Exceptions

Definition at line 630 of file Eav.php.

631  {
632  $configPath = ltrim(static::META_CONFIG_PATH, ArrayManager::DEFAULT_PATH_DELIMITER);
633  $attributeCode = $attribute->getAttributeCode();
634  $meta = $this->arrayManager->set($configPath, [], [
635  'dataType' => $attribute->getFrontendInput(),
636  'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()),
637  'visible' => $attribute->getIsVisible(),
638  'required' => $attribute->getIsRequired(),
639  'notice' => $attribute->getNote() === null ? null : __($attribute->getNote()),
640  'default' => (!$this->isProductExists()) ? $this->getAttributeDefaultValue($attribute) : null,
641  'label' => __($attribute->getDefaultFrontendLabel()),
642  'code' => $attributeCode,
643  'source' => $groupCode,
644  'scopeLabel' => $this->getScopeLabel($attribute),
645  'globalScope' => $this->isScopeGlobal($attribute),
646  'sortOrder' => $sortOrder * self::SORT_ORDER_MULTIPLIER,
647  ]);
648 
649  // TODO: Refactor to $attribute->getOptions() when MAGETWO-48289 is done
650  $attributeModel = $this->getAttributeModel($attribute);
651  if ($attributeModel->usesSource()) {
652  $options = $attributeModel->getSource()->getAllOptions();
653  $meta = $this->arrayManager->merge($configPath, $meta, [
654  'options' => $this->convertOptionsValueToString($options),
655  ]);
656  }
657 
658  if ($this->canDisplayUseDefault($attribute)) {
659  $meta = $this->arrayManager->merge($configPath, $meta, [
660  'service' => [
661  'template' => 'ui/form/element/helper/service',
662  ]
663  ]);
664  }
665 
666  if (!$this->arrayManager->exists($configPath . '/componentType', $meta)) {
667  $meta = $this->arrayManager->merge($configPath, $meta, [
668  'componentType' => Field::NAME,
669  ]);
670  }
671 
672  $product = $this->locator->getProduct();
673  if (in_array($attributeCode, $this->attributesToDisable)
674  || $product->isLockedAttribute($attributeCode)) {
675  $meta = $this->arrayManager->merge($configPath, $meta, [
676  'disabled' => true,
677  ]);
678  }
679 
680  // TODO: getAttributeModel() should not be used when MAGETWO-48284 is complete
681  $childData = $this->arrayManager->get($configPath, $meta, []);
682  if (($rules = $this->catalogEavValidationRules->build($this->getAttributeModel($attribute), $childData))) {
683  $meta = $this->arrayManager->merge($configPath, $meta, [
684  'validation' => $rules,
685  ]);
686  }
687 
688  $meta = $this->addUseDefaultValueCheckbox($attribute, $meta);
689 
690  switch ($attribute->getFrontendInput()) {
691  case 'boolean':
692  $meta = $this->customizeCheckbox($attribute, $meta);
693  break;
694  case 'textarea':
695  $meta = $this->customizeWysiwyg($attribute, $meta);
696  break;
697  case 'price':
698  $meta = $this->customizePriceAttribute($attribute, $meta);
699  break;
700  case 'gallery':
701  // Gallery attribute is being handled by "Images And Videos" section
702  $meta = [];
703  break;
704  }
705 
706  return $meta;
707  }
__()
Definition: __.php:13
$attributeCode
Definition: extend.phtml:12

Field Documentation

◆ $arrayManager

$arrayManager
protected

Definition at line 140 of file Eav.php.

◆ $attributeGroupRepository

$attributeGroupRepository
protected

Definition at line 104 of file Eav.php.

◆ $attributeRepository

$attributeRepository
protected

Definition at line 116 of file Eav.php.

◆ $attributesToEliminate

$attributesToEliminate
protected

Definition at line 156 of file Eav.php.

◆ $catalogEavValidationRules

$catalogEavValidationRules
protected

Definition at line 68 of file Eav.php.

◆ $dataPersistor

$dataPersistor
protected

Definition at line 162 of file Eav.php.

◆ $eavAttributeFactory

$eavAttributeFactory
protected

Definition at line 128 of file Eav.php.

◆ $eavConfig

$eavConfig
protected

Definition at line 62 of file Eav.php.

◆ $formElementMapper

$formElementMapper
protected

Definition at line 92 of file Eav.php.

◆ $groupCollectionFactory

$groupCollectionFactory
protected

Definition at line 80 of file Eav.php.

◆ $locator

$locator
protected

Definition at line 56 of file Eav.php.

◆ $metaPropertiesMapper

$metaPropertiesMapper
protected

Definition at line 98 of file Eav.php.

◆ $request

$request
protected

Definition at line 74 of file Eav.php.

◆ $searchCriteriaBuilder

$searchCriteriaBuilder
protected

Definition at line 110 of file Eav.php.

◆ $sortOrderBuilder

$sortOrderBuilder
protected

Definition at line 122 of file Eav.php.

◆ $storeManager

$storeManager
protected

Definition at line 86 of file Eav.php.

◆ $translitFilter

$translitFilter
protected

Definition at line 134 of file Eav.php.

◆ SORT_ORDER_MULTIPLIER

const SORT_ORDER_MULTIPLIER = 10

Definition at line 50 of file Eav.php.


The documentation for this class was generated from the following file: