Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Attribute Class Reference
Inheritance diagram for Attribute:
Attribute AbstractAttribute IdentityInterface AbstractExtensibleModel AttributeInterface AttributeInterface AbstractModel CustomAttributesDataInterface CustomAttributesDataInterface MetadataObjectInterface DataObject ExtensibleDataInterface ExtensibleDataInterface Attribute

Public Member Functions

 setWebsite ($website)
 
 getWebsite ()
 
 afterSave ()
 
 getUsedInForms ()
 
 getValidateRules ()
 
 setValidateRules ($rules)
 
 getIsRequired ()
 
 getIsVisible ()
 
 getDefaultValue ()
 
 getMultilineCount ()
 
 afterDelete ()
 
- Public Member Functions inherited from Attribute
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionDataFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList, \Magento\Framework\Locale\ResolverInterface $localeResolver, DateTimeFormatterInterface $dateTimeFormatter, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 deleteEntity ()
 
 loadEntityAttributeIdBySet ()
 
 beforeSave ()
 
 afterSave ()
 
 afterDelete ()
 
 getBackendTypeByInput ($type)
 
 getDefaultValueByInput ($type)
 
 getAttributeCodesByFrontendType ($type)
 
 getStoreLabels ()
 
 getStoreLabel ($storeId=null)
 
 getSortWeight ($setId)
 
 getIdentities ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractAttribute
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionDataFactory, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Eav\Api\Data\AttributeExtensionFactory $eavExtensionFactory=null, FrontendLabelFactory $frontendLabelFactory=null)
 
 loadByCode ($entityType, $code)
 
 getName ()
 
 setAttributeId ($data)
 
 getAttributeId ()
 
 setAttributeCode ($data)
 
 getAttributeCode ()
 
 setAttributeModel ($data)
 
 getAttributeModel ()
 
 setBackendType ($data)
 
 getBackendType ()
 
 setBackendModel ($data)
 
 getBackendModel ()
 
 setBackendTable ($data)
 
 getIsVisibleOnFront ()
 
 getDefaultValue ()
 
 setDefaultValue ($defaultValue)
 
 getAttributeSetId ()
 
 setAttributeSetId ($id)
 
 getEntityTypeId ()
 
 setEntityTypeId ($id)
 
 setEntityType ($type)
 
 getAlias ($entity=null)
 
 setName ($name)
 
 getEntityType ()
 
 setEntity ($entity)
 
 getEntity ()
 
 getEntityIdField ()
 
 getBackend ()
 
 getFrontend ()
 
 getSource ()
 
 usesSource ()
 
 isValueEmpty ($value)
 
 isAllowedEmptyTextValue ($value)
 
 isInSet ($setId)
 
 isInGroup ($setId, $groupId)
 
 getIdByCode ($entityType, $code)
 
 isStatic ()
 
 getBackendTable ()
 
 getFlatColumns ()
 
 _getFlatColumnsDdlDefinition ()
 
 getFlatIndexes ()
 
 getFlatUpdateSelect ($store=null)
 
 getIsUnique ()
 
 setIsUnique ($isUnique)
 
 getFrontendClass ()
 
 setFrontendClass ($frontendClass)
 
 getFrontendInput ()
 
 setFrontendInput ($frontendInput)
 
 getIsRequired ()
 
 setIsRequired ($isRequired)
 
 getOptions ()
 
 setOptions (array $options=null)
 
 getIsUserDefined ()
 
 setIsUserDefined ($isUserDefined)
 
 getDefaultFrontendLabel ()
 
 setDefaultFrontendLabel ($defaultFrontendLabel)
 
 getFrontendLabels ()
 
 setFrontendLabels (array $frontendLabels=null)
 
 getNote ()
 
 setNote ($note)
 
 getSourceModel ()
 
 setSourceModel ($sourceModel)
 
 getValidationRules ()
 
 setValidationRules (array $validationRules=null)
 
 setExtensionAttributes (\Magento\Eav\Api\Data\AttributeExtensionInterface $extensionAttributes)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from AttributeInterface
 getExtensionAttributes ()
 

Protected Member Functions

 _getScopeValue ($key)
 
- Protected Member Functions inherited from Attribute
 _getDefaultBackendModel ()
 
 _getDefaultSourceModel ()
 
- Protected Member Functions inherited from AbstractAttribute
 getSerializer ()
 
 _construct ()
 
 _getDefaultBackendModel ()
 
 _getDefaultFrontendModel ()
 
 _getDefaultSourceModel ()
 
 _getFlatColumnsOldDefinition ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventObject = 'attribute'
 
 $_website
 
- Protected Attributes inherited from Attribute
 $_eventPrefix = 'eav_entity_attribute'
 
 $_eventObject = 'attribute'
 
 $_cacheTag = self::CACHE_TAG
 
 $_localeDate
 
 $reservedAttributeList
 
 $_localeResolver
 
 $dateTimeFormatter
 
- Protected Attributes inherited from AbstractAttribute
 $_name
 
 $_entity
 
 $_backend
 
 $_frontend
 
 $_source
 
 $_attributeIdCache = []
 
 $_dataTable = null
 
 $_eavConfig
 
 $_eavTypeFactory
 
 $_storeManager
 
 $_resourceHelper
 
 $_universalFactory
 
 $optionDataFactory
 
 $dataObjectProcessor
 
 $dataObjectHelper
 
 $serializer
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Data Fields inherited from Attribute
const ATTRIBUTE_CODE_MAX_LENGTH = 60
 
const ATTRIBUTE_CODE_MIN_LENGTH = 1
 
const CACHE_TAG = 'EAV_ATTRIBUTE'
 
- Data Fields inherited from AbstractAttribute
const TYPE_STATIC = 'static'
 
const EMPTY_STRING = ''
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from AttributeInterface
const ATTRIBUTE_ID = 'attribute_id'
 
const IS_UNIQUE = 'is_unique'
 
const SCOPE = 'scope'
 
const FRONTEND_CLASS = 'frontend_class'
 
const ATTRIBUTE_CODE = 'attribute_code'
 
const FRONTEND_INPUT = 'frontend_input'
 
const IS_REQUIRED = 'is_required'
 
const OPTIONS = 'options'
 
const IS_USER_DEFINED = 'is_user_defined'
 
const FRONTEND_LABEL = 'frontend_label'
 
const FRONTEND_LABELS = 'frontend_labels'
 
const NOTE = 'note'
 
const BACKEND_TYPE = 'backend_type'
 
const BACKEND_MODEL = 'backend_model'
 
const SOURCE_MODEL = 'source_model'
 
const VALIDATE_RULES = 'validate_rules'
 
const ENTITY_TYPE_ID = 'entity_type_id'
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@api

Since
100.0.2

Definition at line 23 of file Attribute.php.

Member Function Documentation

◆ _getScopeValue()

_getScopeValue (   $key)
protected

Return scope value by key

Parameters
string$key
Returns
mixed

Definition at line 137 of file Attribute.php.

138  {
139  $scopeKey = sprintf('scope_%s', $key);
140  if ($this->getData($scopeKey) !== null) {
141  return $this->getData($scopeKey);
142  }
143  return $this->getData($key);
144  }

◆ afterDelete()

afterDelete ( )

{}

Definition at line 193 of file Attribute.php.

194  {
195  $this->_eavConfig->clear();
196  return parent::afterDelete();
197  }

◆ afterSave()

afterSave ( )

Processing object after save data

Returns
$this

Definition at line 76 of file Attribute.php.

77  {
78  $this->_eavConfig->clear();
79  return parent::afterSave();
80  }

◆ getDefaultValue()

getDefaultValue ( )

Return default value for attribute

Returns
mixed @codeCoverageIgnore

Implements AttributeInterface.

Definition at line 174 of file Attribute.php.

175  {
176  return $this->_getScopeValue('default_value');
177  }

◆ getIsRequired()

getIsRequired ( )

Return is attribute value required

Returns
mixed @codeCoverageIgnore

Implements AttributeInterface.

Definition at line 152 of file Attribute.php.

153  {
154  return $this->_getScopeValue('is_required');
155  }

◆ getIsVisible()

getIsVisible ( )

Return is visible attribute flag

Returns
mixed @codeCoverageIgnore

Definition at line 163 of file Attribute.php.

164  {
165  return $this->_getScopeValue('is_visible');
166  }

◆ getMultilineCount()

getMultilineCount ( )

Return count of lines for multiply line attribute

Returns
mixed @codeCoverageIgnore

Definition at line 185 of file Attribute.php.

186  {
187  return $this->_getScopeValue('multiline_count');
188  }

◆ getUsedInForms()

getUsedInForms ( )

Return forms in which the attribute

Returns
array

Definition at line 87 of file Attribute.php.

88  {
89  $forms = $this->getData('used_in_forms');
90  if ($forms === null) {
91  $forms = $this->_getResource()->getUsedInForms($this);
92  $this->setData('used_in_forms', $forms);
93  }
94  return $forms;
95  }

◆ getValidateRules()

getValidateRules ( )

Return validate rules

Returns
array

Definition at line 102 of file Attribute.php.

103  {
104  $rules = $this->getData('validate_rules');
105  if (is_array($rules)) {
106  return $rules;
107  } elseif (!empty($rules)) {
108  return (array)$this->getSerializer()->unserialize($rules);
109  }
110  return [];
111  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ getWebsite()

getWebsite ( )

Return active website instance

Returns
Website

Definition at line 62 of file Attribute.php.

63  {
64  if ($this->_website === null) {
65  $this->_website = $this->_storeManager->getWebsite();
66  }
67 
68  return $this->_website;
69  }

◆ setValidateRules()

setValidateRules (   $rules)

Set validate rules

Parameters
array | string$rules
Returns
$this

Definition at line 119 of file Attribute.php.

120  {
121  if (empty($rules)) {
122  $rules = null;
123  } elseif (is_array($rules)) {
124  $rules = $this->getSerializer()->serialize($rules);
125  }
126  $this->setData('validate_rules', $rules);
127 
128  return $this;
129  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ setWebsite()

setWebsite (   $website)

Set active website instance

Parameters
Website | int$website
Returns
$this @codeCoverageIgnore

Definition at line 51 of file Attribute.php.

52  {
53  $this->_website = $this->_storeManager->getWebsite($website);
54  return $this;
55  }

Field Documentation

◆ $_eventObject

$_eventObject = 'attribute'
protected

Name of the module Override itName of the module Override it

Definition at line 35 of file Attribute.php.

◆ $_website

$_website
protected

Definition at line 42 of file Attribute.php.


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