/**
  * Process custom entities and fields. If entity or field marked as searchable - config of this custom
  *  entity or field will bw added to the main search map.
  *
  * @param SearchMappingCollectEvent $event
  */
 public function prepareEntityMapEvent(SearchMappingCollectEvent $event)
 {
     $mapConfig = $event->getMappingConfig();
     $extendConfigs = $this->configManager->getProvider('extend')->getConfigs();
     foreach ($extendConfigs as $extendConfig) {
         if ($extendConfig->is('is_extend') && $extendConfig->get('state') === ExtendScope::STATE_ACTIVE) {
             $className = $extendConfig->getId()->getClassName();
             $searchConfigs = $this->configManager->getConfigs('search', $className);
             if ($extendConfig->get('owner') === ExtendScope::OWNER_CUSTOM) {
                 $mapConfig = $this->addCustomEntityMapping($mapConfig, $extendConfig);
             }
             if (isset($mapConfig[$className]) && ($extendConfig->get('owner') === ExtendScope::OWNER_SYSTEM || $extendConfig->get('owner') === ExtendScope::OWNER_CUSTOM && $this->configManager->getProvider('search')->getConfig($className)->is('searchable'))) {
                 foreach ($searchConfigs as $searchConfig) {
                     /** @var FieldConfigId $fieldId */
                     $fieldId = $searchConfig->getId();
                     if (!$fieldId instanceof FieldConfigId) {
                         continue;
                     }
                     $this->processTitles($mapConfig, $searchConfig, $className, $fieldId->getFieldName());
                     $this->processFields($mapConfig, $searchConfig, $fieldId, $className);
                 }
             }
         }
     }
     $event->setMappingConfig($mapConfig);
 }
예제 #2
0
 /**
  * Add organization field to the entities
  */
 public function collectEntityMapEvent(SearchMappingCollectEvent $event)
 {
     $mapConfig = $event->getMappingConfig();
     foreach (array_keys($mapConfig) as $className) {
         $mapConfig[$className]['fields'][] = ['name' => 'organization', 'target_type' => 'integer', 'target_fields' => ['organization']];
     }
     $event->setMappingConfig($mapConfig);
 }
예제 #3
0
 /**
  * Add organization field to the entities
  *
  * @param SearchMappingCollectEvent $event
  */
 public function collectEntityMapEvent(SearchMappingCollectEvent $event)
 {
     $mapConfig = $event->getMappingConfig();
     foreach ($mapConfig as $className => $mapping) {
         $mapConfig[$className]['fields'][] = ['name' => 'organization', 'target_type' => 'integer', 'target_fields' => ['organization']];
         $mapConfig[$className]['fields'][] = ['name' => 'owner', 'target_type' => 'integer', 'target_fields' => [sprintf('%s_owner', $mapping['alias'])]];
     }
     $event->setMappingConfig($mapConfig);
 }
 public function testEvent()
 {
     $mapConfig = ['test'];
     $event = new SearchMappingCollectEvent($mapConfig);
     $this->assertSame($mapConfig, $event->getMappingConfig());
     $updatedMapConfig = array_merge($mapConfig, ['customEntity']);
     $event->setMappingConfig($updatedMapConfig);
     $this->assertSame($updatedMapConfig, $event->getMappingConfig());
 }