objectManager = $objectManager; $this->metadataPool = $metadataPool; } /** * @param string $entityType * @param array|null $entityData * @return \Magento\Framework\Model\Entity\ScopeInterface[] * @throws ConfigurationMismatchException * @throws \Exception */ public function getEntityContext($entityType, $entityData = []) { $entityContext = []; $metadata = $this->metadataPool->getMetadata($entityType); foreach ($metadata->getEntityContext() as $contextProviderClass) { $contextProvider = $this->objectManager->get($contextProviderClass); if (!$contextProvider instanceof ScopeProviderInterface) { throw new ConfigurationMismatchException( new Phrase( 'The configuration for the "%1" type is incorrect. ' . 'Verify the type and configuration and try again.', [$entityType] ) ); } $entityContext[] = $contextProvider->getContext($entityType, $entityData); } return $entityContext; } }