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

Public Member Functions

 __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\Indexer\IndexerRegistry $indexerRegistry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], \Magento\Customer\Model\Metadata\AttributeMetadataCache $attributeMetadataCache=null)
 
 afterSave ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 canBeSearchableInGrid ()
 
 canBeFilterableInGrid ()
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from Attribute
 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 ()
 

Data Fields

const MODULE_NAME = 'Magento_Customer'
 
- 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'
 

Protected Member Functions

 _construct ()
 
- Protected Member Functions inherited from Attribute
 _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

 $_eventPrefix = 'customer_entity_attribute'
 
 $_eventObject = 'attribute'
 
 $indexerRegistry
 
- Protected Attributes inherited from Attribute
 $_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

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Customer attribute model

@method int getSortOrder() @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 18 of file Attribute.php.

Constructor & Destructor Documentation

◆ __construct()

__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\Indexer\IndexerRegistry  $indexerRegistry,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
\Magento\Customer\Model\Metadata\AttributeMetadataCache  $attributeMetadataCache = null 
)

Constructor

Parameters
\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\Indexer\IndexerRegistry$indexerRegistry
\Magento\Framework\Model\ResourceModel\AbstractResource | null$resource
\Magento\Framework\Data\Collection\AbstractDb | null$resourceCollection
array | null$data
\Magento\Customer\Model\Metadata\AttributeMetadataCache | null$attributeMetadataCache@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 75 of file Attribute.php.

97  {
98  $this->indexerRegistry = $indexerRegistry;
99  $this->attributeMetadataCache = $attributeMetadataCache ?: \Magento\Framework\App\ObjectManager::getInstance()
100  ->get(\Magento\Customer\Model\Metadata\AttributeMetadataCache::class);
101  parent::__construct(
102  $context,
103  $registry,
104  $extensionFactory,
106  $eavConfig,
107  $eavTypeFactory,
109  $resourceHelper,
110  $universalFactory,
114  $localeDate,
116  $localeResolver,
118  $resource,
119  $resourceCollection,
120  $data
121  );
122  }
$storeManager
$resource
Definition: bulk.php:12

Member Function Documentation

◆ __sleep()

__sleep ( )

Definition at line 206 of file Attribute.php.

207  {
208  $this->unsetData('entity_type');
209  return array_diff(
210  parent::__sleep(),
211  ['indexerRegistry', '_website']
212  );
213  }

◆ __wakeup()

__wakeup ( )

Definition at line 218 of file Attribute.php.

219  {
222  $this->indexerRegistry = $objectManager->get(\Magento\Framework\Indexer\IndexerRegistry::class);
223  }
$objectManager
Definition: bootstrap.php:17

◆ _construct()

_construct ( )
protected

Init resource model

Returns
void

Definition at line 129 of file Attribute.php.

130  {
131  $this->_init(\Magento\Customer\Model\ResourceModel\Attribute::class);
132  }

◆ afterDelete()

afterDelete ( )

Definition at line 151 of file Attribute.php.

152  {
153  $this->attributeMetadataCache->clean();
154  return parent::afterDelete();
155  }

◆ afterDeleteCommit()

afterDeleteCommit ( )

Init indexing process after customer delete

Returns
\Magento\Framework\Model\AbstractModel

Definition at line 162 of file Attribute.php.

163  {
164  if ($this->getData(EavAttributeInterface::IS_USED_IN_GRID) == true) {
165  $this->invalidate();
166  }
167  return parent::afterDeleteCommit();
168  }

◆ afterSave()

afterSave ( )

Definition at line 137 of file Attribute.php.

138  {
139  if ($this->isObjectNew() && (bool)$this->getData(EavAttributeInterface::IS_USED_IN_GRID)) {
140  $this->_getResource()->addCommitCallback([$this, 'invalidate']);
142  $this->_getResource()->addCommitCallback([$this, 'invalidate']);
143  }
144  $this->attributeMetadataCache->clean();
145  return parent::afterSave();
146  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17

◆ canBeFilterableInGrid()

canBeFilterableInGrid ( )

Check whether attribute is filterable in admin grid and it is allowed

Returns
bool

Definition at line 197 of file Attribute.php.

198  {
199  return $this->getData('is_filterable_in_grid')
200  && in_array($this->getFrontendInput(), ['text', 'date', 'select', 'boolean']);
201  }

◆ canBeSearchableInGrid()

canBeSearchableInGrid ( )

Check whether attribute is searchable in admin grid and it is allowed

Returns
bool

Definition at line 187 of file Attribute.php.

188  {
189  return $this->getData('is_searchable_in_grid') && in_array($this->getFrontendInput(), ['text', 'textarea']);
190  }

Field Documentation

◆ $_eventObject

$_eventObject = 'attribute'
protected

Definition at line 37 of file Attribute.php.

◆ $_eventPrefix

$_eventPrefix = 'customer_entity_attribute'
protected

Definition at line 30 of file Attribute.php.

◆ $indexerRegistry

$indexerRegistry
protected

Definition at line 42 of file Attribute.php.

◆ MODULE_NAME

const MODULE_NAME = 'Magento_Customer'

Name of the module

Definition at line 23 of file Attribute.php.


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