indexerRegistry = $indexerRegistry; parent::__construct( $context, $registry, $extensionFactory, $customAttributeFactory, $eavConfig, $eavTypeFactory, $storeManager, $resourceHelper, $universalFactory, $optionDataFactory, $dataObjectProcessor, $dataObjectHelper, $localeDate, $reservedAttributeList, $localeResolver, $dateTimeFormatter, $resource, $resourceCollection, $data ); } /** * Init resource model * * @return void */ protected function _construct() { $this->_init('Magento\Customer\Model\ResourceModel\Attribute'); } /** * Processing object after save data * * @return $this */ public function afterSave() { if ($this->isObjectNew() && (bool)$this->getData(EavAttributeInterface::IS_USED_IN_GRID)) { $this->_getResource()->addCommitCallback([$this, 'invalidate']); } elseif (!$this->isObjectNew() && $this->dataHasChangedFor(EavAttributeInterface::IS_USED_IN_GRID)) { $this->_getResource()->addCommitCallback([$this, 'invalidate']); } return parent::afterSave(); } /** * Init indexing process after customer delete * * @return \Magento\Framework\Model\AbstractModel */ public function afterDeleteCommit() { if ($this->getData(EavAttributeInterface::IS_USED_IN_GRID) == true) { $this->invalidate(); } return parent::afterDeleteCommit(); } /** * Init indexing process after customer save * * @return void */ public function invalidate() { /** @var \Magento\Framework\Indexer\IndexerInterface $indexer */ $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); $indexer->invalidate(); } /** * Check whether attribute is searchable in admin grid and it is allowed * * @return bool */ public function canBeSearchableInGrid() { return $this->getData('is_searchable_in_grid') && in_array($this->getFrontendInput(), ['text', 'textarea']); } /** * Check whether attribute is filterable in admin grid and it is allowed * * @return bool */ public function canBeFilterableInGrid() { return $this->getData('is_filterable_in_grid') && in_array($this->getFrontendInput(), ['text', 'date', 'select', 'boolean']); } /** * @inheritdoc */ public function __sleep() { $this->unsetData('entity_type'); return array_diff( parent::__sleep(), ['indexerRegistry', '_website'] ); } /** * @inheritdoc */ public function __wakeup() { parent::__wakeup(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $this->indexerRegistry = $objectManager->get(\Magento\Framework\Indexer\IndexerRegistry::class); } }