/** * 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); }
/** * {@inheritdoc} */ public function preUpdate() { $entityConfigs = $this->configManager->getConfigs('extend'); foreach ($entityConfigs as $entityConfig) { if (!$entityConfig->is('is_extend')) { continue; } $fieldConfigs = $this->configManager->getConfigs('extend', $entityConfig->getId()->getClassName()); foreach ($fieldConfigs as $fieldConfig) { if (!$fieldConfig->in('state', [ExtendScope::STATE_NEW, ExtendScope::STATE_UPDATE])) { continue; } // @todo: we need to find a way to use this extension to process OWNER_SYSTEM relations as well // currently we have several problems here: // - collision with associations // - no support unidirectional relations if (!$fieldConfig->is('owner', ExtendScope::OWNER_CUSTOM)) { continue; } /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $fieldConfig->getId(); if (in_array($fieldConfigId->getFieldType(), RelationType::$anyToAnyRelations, true)) { $this->createRelation($fieldConfig); } } } }
/** * {@inheritdoc} */ public function process(ContextInterface $context) { /** @var CollectPublicResourcesContext $context */ $resources = $context->getResult(); $configs = $this->configManager->getConfigs('extend', null, true); foreach ($configs as $config) { if ($config->is('is_extend') && $config->is('owner', ExtendScope::OWNER_CUSTOM)) { $resources->add(new PublicResource($config->getId()->getClassName())); } } }
/** * Gets configuration data for all configurable entities (if $className is not specified) * or all configurable fields of the given $className. * * @param string|null $className * @param bool $withHidden Set true if you need ids of all configurable entities, * including entities marked as mode="hidden" * * @return array|ConfigInterface[] */ public function getConfigs($className = null, $withHidden = false) { if ($className) { $className = $this->getClassName($className); } return $this->configManager->getConfigs($this->getScope(), $className, $withHidden); }
/** * @dataProvider getConfigsProvider */ public function testGetConfigs($scope, $className, $withHidden, $expectedConfigs) { $models = [$this->createEntityConfigModel('EntityClass1'), $this->createEntityConfigModel('EntityClass2'), $this->createEntityConfigModel('HiddenEntity', ConfigModel::MODE_HIDDEN)]; $entityModel = $this->createEntityConfigModel('EntityClass1'); $fieldModels = [$this->createFieldConfigModel($entityModel, 'f1', 'int'), $this->createFieldConfigModel($entityModel, 'f2', 'int'), $this->createFieldConfigModel($entityModel, 'hiddenField', 'int', ConfigModel::MODE_HIDDEN)]; $this->modelManager->expects($this->any())->method('checkDatabase')->willReturn(true); $this->configCache->expects($this->any())->method('getConfigurable')->willReturn(true); $this->modelManager->expects($this->once())->method('getModels')->with($className)->willReturn($className ? $fieldModels : $models); if ($className) { $this->modelManager->expects($this->any())->method('getFieldModel')->willReturnMap([[$className, 'f1', $fieldModels[0]], [$className, 'f2', $fieldModels[1]], [$className, 'hiddenField', $fieldModels[2]]]); } else { $this->modelManager->expects($this->any())->method('getEntityModel')->willReturnMap([['EntityClass1', $models[0]], ['EntityClass2', $models[1]], ['HiddenEntity', $models[2]]]); } $result = $this->configManager->getConfigs($scope, $className, $withHidden); $this->assertEquals($expectedConfigs, array_values($result)); }
/** * @return string[] */ public function getFields() { if (empty($this->fields)) { $this->fields = []; $fieldConfigs = $this->configManager->getConfigs('extend', self::CALENDAR_PROPERTY_CLASS); foreach ($fieldConfigs as $fieldConfig) { if (!ExtendHelper::isFieldAccessible($fieldConfig)) { continue; } /** @var FieldConfigId $fieldId */ $fieldId = $fieldConfig->getId(); $fieldType = $fieldId->getFieldType(); $underlyingFieldType = $this->fieldTypeHelper->getUnderlyingType($fieldType); if (in_array($underlyingFieldType, RelationType::$toManyRelations, true)) { // ignore to-many relations continue; } $this->fields[$fieldId->getFieldName()] = $fieldType; } } return $this->fields; }
/** * @return string[] */ public function getFields() { if (empty($this->fields)) { $this->fields = []; $fieldConfigs = $this->configManager->getConfigs('extend', self::CALENDAR_PROPERTY_CLASS); foreach ($fieldConfigs as $fieldConfig) { if ($fieldConfig->is('state', ExtendScope::STATE_NEW) || $fieldConfig->is('is_deleted')) { continue; } /** @var FieldConfigId $fieldId */ $fieldId = $fieldConfig->getId(); $fieldType = $fieldId->getFieldType(); $underlyingFieldType = $this->fieldTypeHelper->getUnderlyingType($fieldType); if (in_array($underlyingFieldType, ['ref-many', 'manyToMany', 'oneToMany'])) { // ignore multiple relations continue; } $this->fields[$fieldId->getFieldName()] = $fieldType; } } return $this->fields; }