Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Attribute.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Customer\Model;
7 
11 
19 {
23  const MODULE_NAME = 'Magento_Customer';
24 
30  protected $_eventPrefix = 'customer_entity_attribute';
31 
37  protected $_eventObject = 'attribute';
38 
42  protected $indexerRegistry;
43 
47  private $attributeMetadataCache;
48 
75  public function __construct(
76  \Magento\Framework\Model\Context $context,
77  \Magento\Framework\Registry $registry,
78  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
80  \Magento\Eav\Model\Config $eavConfig,
81  \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory,
83  \Magento\Eav\Model\ResourceModel\Helper $resourceHelper,
84  \Magento\Framework\Validator\UniversalFactory $universalFactory,
85  \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionDataFactory,
86  \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
87  \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
88  \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
89  \Magento\Catalog\Model\Product\ReservedAttributeList $reservedAttributeList,
90  \Magento\Framework\Locale\ResolverInterface $localeResolver,
92  \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
93  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
94  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
95  array $data = [],
96  \Magento\Customer\Model\Metadata\AttributeMetadataCache $attributeMetadataCache = null
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  }
123 
129  protected function _construct()
130  {
131  $this->_init(\Magento\Customer\Model\ResourceModel\Attribute::class);
132  }
133 
137  public function afterSave()
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  }
147 
151  public function afterDelete()
152  {
153  $this->attributeMetadataCache->clean();
154  return parent::afterDelete();
155  }
156 
162  public function afterDeleteCommit()
163  {
164  if ($this->getData(EavAttributeInterface::IS_USED_IN_GRID) == true) {
165  $this->invalidate();
166  }
167  return parent::afterDeleteCommit();
168  }
169 
175  public function invalidate()
176  {
178  $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
179  $indexer->invalidate();
180  }
181 
187  public function canBeSearchableInGrid()
188  {
189  return $this->getData('is_searchable_in_grid') && in_array($this->getFrontendInput(), ['text', 'textarea']);
190  }
191 
197  public function canBeFilterableInGrid()
198  {
199  return $this->getData('is_filterable_in_grid')
200  && in_array($this->getFrontendInput(), ['text', 'date', 'select', 'boolean']);
201  }
202 
206  public function __sleep()
207  {
208  $this->unsetData('entity_type');
209  return array_diff(
210  parent::__sleep(),
211  ['indexerRegistry', '_website']
212  );
213  }
214 
218  public function __wakeup()
219  {
222  $this->indexerRegistry = $objectManager->get(\Magento\Framework\Indexer\IndexerRegistry::class);
223  }
224 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$objectManager
Definition: bootstrap.php:17
$storeManager
$resource
Definition: bulk.php:12
__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)
Definition: Attribute.php:75