/** * Process field * * @param array $mapConfig * @param ConfigInterface $searchConfig * @param FieldConfigId $fieldId * @param string $className */ protected function processFields(&$mapConfig, ConfigInterface $searchConfig, FieldConfigId $fieldId, $className) { $extendConfigProvider = $this->configManager->getProvider('extend'); $fieldName = $fieldId->getFieldName(); if ($searchConfig->is('searchable')) { $fieldType = $this->transformCustomType($fieldId->getFieldType()); if (in_array($fieldType, [Indexer::RELATION_ONE_TO_ONE, Indexer::RELATION_MANY_TO_ONE])) { $config = $extendConfigProvider->getConfig($className, $fieldName); $targetEntity = $config->get('target_entity'); $targetField = $config->get('target_field'); $targetType = $this->transformCustomType($this->configManager->getId('extend', $targetEntity, $targetField)->getFieldType()); $field = ['name' => $fieldName, 'relation_type' => $fieldType, 'relation_fields' => [['name' => $targetField, 'target_type' => $targetType, 'target_fields' => [strtolower($fieldName . '_' . $targetField)]]]]; } elseif (in_array($fieldType, [Indexer::RELATION_MANY_TO_MANY, Indexer::RELATION_ONE_TO_MANY])) { $config = $extendConfigProvider->getConfig($className, $fieldName); $targetEntity = $config->get('target_entity'); $targetFields = array_unique(array_merge($config->get('target_grid'), $config->get('target_title'), $config->get('target_detailed'))); $fields = []; foreach ($targetFields as $targetField) { $targetType = $this->transformCustomType($this->configManager->getId('extend', $targetEntity, $targetField)->getFieldType()); $fields[] = ['name' => $targetField, 'target_type' => $targetType, 'target_fields' => [strtolower($fieldName . '_' . $targetField)]]; } $field = ['name' => $fieldName, 'relation_type' => $fieldType, 'relation_fields' => $fields]; } else { $field = ['name' => $fieldName, 'target_type' => $fieldType, 'target_fields' => [strtolower($fieldName)]]; } $mapConfig[$className][self::FIELDS_PATH][] = $field; } }
/** * @param string $entityClassName * @param string $relationType * * @return array */ protected function getEntityChoiceList($entityClassName, $relationType) { /** @var EntityConfigId[] $entityIds */ $entityIds = $this->targetEntityClass ? [$this->configManager->getId('extend', $this->targetEntityClass)] : $this->configManager->getIds('extend'); if (in_array($relationType, [RelationTypeBase::ONE_TO_MANY, RelationTypeBase::MANY_TO_MANY], true)) { $entityIds = array_filter($entityIds, function (EntityConfigId $configId) { $config = $this->configManager->getConfig($configId); return $config->is('is_extend'); }); } $entityIds = array_filter($entityIds, function (EntityConfigId $configId) { $config = $this->configManager->getConfig($configId); return !$config->is('state', ExtendScope::STATE_NEW) && ($this->targetEntityClass || !$config->is('is_deleted')); }); $choices = []; foreach ($entityIds as $entityId) { $className = $entityId->getClassName(); if (!$this->configManager->hasConfig($className, 'id') && !ExtendHelper::isCustomEntity($className)) { // @todo: temporary ignore entities that don't have PK with name 'id' // remove this in https://magecore.atlassian.net/browse/BAP-9713 continue; } if ($className !== $entityClassName) { $entityConfig = $this->configManager->getProvider('entity')->getConfig($className); $choices[$className] = $entityConfig->get('label'); } } return $choices; }
/** * @param string $className * @param string $fieldName * * @return bool */ protected function isMultiEnumField($className, $fieldName) { if ($this->configManager->hasConfig($className, $fieldName)) { /** @var FieldConfigId $fieldId */ $fieldId = $this->configManager->getId('extend', $className, $fieldName); if ($fieldId->getFieldType() === 'multiEnum') { return true; } } return false; }
/** * Gets an instance of FieldConfigId or EntityConfigId depends on the given parameters. * * @param string|null $className * @param string|null $fieldName * @param string|null $fieldType * @return ConfigIdInterface */ public function getId($className = null, $fieldName = null, $fieldType = null) { if ($className) { $className = $this->getClassName($className); } if ($fieldName) { if ($fieldType) { return new FieldConfigId($this->getScope(), $className, $fieldName, $fieldType); } else { return $this->configManager->getId($this->getScope(), $className, $fieldName); } } else { return new EntityConfigId($this->getScope(), $className); } }
/** * @param string $targetClassName * @param string $activityClassName * * @return bool */ public function isApplicableTarget($targetClassName, $activityClassName) { if (!isset($this->providers[$activityClassName]) || !$this->configManager->hasConfig($targetClassName)) { return false; } return $this->providers[$activityClassName]->isApplicableTarget($this->configManager->getId('entity', $targetClassName), $this->configManager); }