/** * @param ConfigInterface $config * * @return array */ protected function getMissingTranslationKeys(ConfigInterface $config) { $keys = ['label']; if ($config->getId() instanceof EntityConfigId) { $keys[] = 'plural_label'; } $missingTranslationKeys = []; foreach ($keys as $key) { $transKey = $config->get($key); /** * Ignore custom entities created for test environment only (class name starts with "Test"). * It's done to avoid adding and accumulation of unnecessary test entity/field/relation translations. */ if (0 === strpos($transKey, 'extend.entity.test')) { continue; } if (!$this->getTranslator()->hasTrans($transKey)) { $configId = $config->getId(); if ($configId instanceof FieldConfigId) { $transKey .= sprintf(' [Entity: %s; Field: %s]', $configId->getClassName(), $configId->getFieldName()); } else { $transKey .= sprintf(' [Entity: %s]', $configId->getClassName()); } $missingTranslationKeys[] = $transKey; } } return $missingTranslationKeys; }
/** * @param ConfigInterface $fieldConfig * @param string $fieldName * @param object $entity * @return null|mixed */ protected function getEntityFieldData(ConfigInterface $fieldConfig, $fieldName, $entity) { if ($fieldConfig->getId()->getFieldType() != 'optionSet' || !FieldAccessor::hasGetter($entity, $fieldName) || !($options = FieldAccessor::getValue($entity, $fieldName))) { return null; } return $options; }
/** * @param ConfigInterface $sourceEntityConfig The 'extend' config of the source entity * @param string $targetEntityName * @param string $relationName * @param string $targetFieldName A field name is used to show related entity * @param array $options * @param string $fieldType The field type. By default the field type is manyToOne, * but you can specify another type if it is based on manyToOne. * In this case this type should be registered * in entity_extend.yml under underlying_types section * * @return string The relation key */ public function addManyToOneRelation(ConfigInterface $sourceEntityConfig, $targetEntityName, $relationName, $targetFieldName, $options = [], $fieldType = RelationType::MANY_TO_ONE) { $sourceEntityName = $sourceEntityConfig->getId()->getClassName(); $relationKey = ExtendHelper::buildRelationKey($sourceEntityName, $relationName, RelationType::MANY_TO_ONE, $targetEntityName); // add a relation field config if (!$this->configManager->hasConfigFieldModel($sourceEntityName, $relationName)) { $this->configManager->createConfigFieldModel($sourceEntityName, $relationName, $fieldType); $options['extend']['state'] = ExtendScope::STATE_NEW; } else { $configFieldModel = $this->configManager->getConfigFieldModel($sourceEntityName, $relationName); if ($configFieldModel->getType() !== $fieldType) { $this->configManager->changeFieldType($sourceEntityName, $relationName, $fieldType); } } $options['extend']['is_extend'] = true; $options['extend']['relation_key'] = $relationKey; $options['extend']['target_entity'] = $targetEntityName; $options['extend']['target_field'] = $targetFieldName; $this->updateFieldConfigs($sourceEntityName, $relationName, $options); // add relation to config $relations = $sourceEntityConfig->get('relation', false, []); if (!isset($relations[$relationKey])) { $fieldId = new FieldConfigId('extend', $sourceEntityName, $relationName, RelationType::MANY_TO_ONE); $relations[$relationKey] = ['assign' => false, 'field_id' => $fieldId, 'owner' => true, 'target_entity' => $targetEntityName, 'target_field_id' => false]; if (isset($options['extend']['cascade'])) { $relations[$relationKey]['cascade'] = $options['extend']['cascade']; } $sourceEntityConfig->set('relation', $relations); $extendConfigProvider = $this->configManager->getProvider('extend'); $extendConfigProvider->persist($sourceEntityConfig); } return $relationKey; }
/** * @param ConfigInterface $entityConfig * @param string $targetEntityClassName * @param string $relationName */ protected function createOwnerRelation(ConfigInterface $entityConfig, $targetEntityClassName, $relationName) { $relationKey = ExtendHelper::buildRelationKey($entityConfig->getId()->getClassName(), $relationName, 'manyToOne', $this->ownershipMetadataProvider->getOrganizationClass()); if (!isset($entityConfig->get('relation')[$relationKey])) { $this->relationBuilder->addManyToOneRelation($entityConfig, $targetEntityClassName, $relationName, 'id', ['entity' => ['label' => 'oro.custom_entity.' . $relationName . '.label', 'description' => 'oro.custom_entity.' . $relationName . '.description'], 'view' => ['is_displayable' => false], 'form' => ['is_enabled' => false], 'dataaudit' => ['auditable' => true]]); } }
/** * @param ConfigInterface $config * @return bool * @throws \LogicException */ public function putConfigInCache(ConfigInterface $config) { $configId = $config->getId(); if ($this->isDebug && $configId instanceof FieldConfigId) { if ($configId->getFieldType() === null) { // undefined field type can cause unpredictable logical bugs throw new \LogicException(sprintf('A field config "%s::%s" with undefined field type cannot be cached.' . ' It seems that there is some critical bug in entity config core functionality.' . ' Please contact ORO team if you see this error.', $configId->getClassName(), $configId->getFieldName())); } } return $this->cache->save($this->buildConfigCacheKey($config->getId()), $config); }
/** * @param ConfigInterface $config * * @return array */ protected function getMissingTranslationKeys(ConfigInterface $config) { $keys = ['label']; if ($config->getId() instanceof EntityConfigId) { $keys[] = 'plural_label'; } $missingTranslationKeys = []; foreach ($keys as $key) { $transKey = $config->get($key); if (!$this->getTranslator()->hasTrans($transKey)) { $configId = $config->getId(); if ($configId instanceof FieldConfigId) { $transKey .= sprintf(' [Entity: %s; Field: %s]', $configId->getClassName(), $configId->getFieldName()); } else { $transKey .= sprintf(' [Entity: %s]', $configId->getClassName()); } $missingTranslationKeys[] = $transKey; } } return $missingTranslationKeys; }
/** * @param ConfigInterface $config * @param bool $localCacheOnly * * @return bool * * @throws \InvalidArgumentException */ public function saveConfig(ConfigInterface $config, $localCacheOnly = false) { $configId = $config->getId(); if ($this->isDebug && $configId instanceof FieldConfigId && null === $configId->getFieldType()) { // undefined field type can cause unpredictable logical bugs throw new \InvalidArgumentException(sprintf('A field config "%s::%s" with undefined field type cannot be cached.' . ' It seems that there is some critical bug in entity config core functionality.' . ' Please contact ORO team if you see this error.', $configId->getClassName(), $configId->getFieldName())); } $cacheKey = $this->buildConfigCacheKey($configId); $cacheEntry = isset($this->localCache[$cacheKey]) ? $this->localCache[$cacheKey] : $this->fetchConfig($cacheKey, $configId); $cacheEntry[$configId->getScope()] = $config; $this->localCache[$cacheKey] = $cacheEntry; return $localCacheOnly ? true : $this->pushConfig($cacheKey, $cacheEntry); }
/** * {@inheritdoc} */ public function build(ClassMetadataBuilder $metadataBuilder, ConfigInterface $extendConfig) { $className = $extendConfig->getId()->getClassName(); $indices = $extendConfig->get('index'); // TODO: need to be changed to fieldName => columnName // TODO: should be done in scope https://magecore.atlassian.net/browse/BAP-3940 foreach ($indices as $columnName => $enabled) { $fieldConfig = $this->extendConfigProvider->getConfig($className, $columnName); if ($enabled && !$fieldConfig->is('state', ExtendScope::STATE_NEW)) { $indexName = $this->nameGenerator->generateIndexNameForExtendFieldVisibleInGrid($className, $columnName); $metadataBuilder->addIndex([$columnName], $indexName); } } }
/** * @param array $config * * @return bool */ protected function isDisabledItem(array $config) { $createOnly = isset($config['options']['create_only']) && $config['options']['create_only']; // disable config attribute if its value cannot be changed if ($createOnly && $this->configModel->getId()) { return true; } // disable field config attribute if its value cannot be changed for some field types // an attribute marked as create only should not be disabled on create field page if ($this->config->getId() instanceof FieldConfigId && !empty($config['options']['immutable_type']) && in_array($this->config->getId()->getFieldType(), $config['options']['immutable_type'], true) && (!$createOnly || $this->configModel->getId())) { return true; } return false; }
/** * @param ConfigInterface $config * * @return array */ protected function getMissingTranslationKeys(ConfigInterface $config) { $keys = ['label']; if ($config->getId() instanceof EntityConfigId) { $keys[] = 'plural_label'; } $missingTranslationKeys = []; foreach ($keys as $key) { $transKey = $config->get($key); if (!$this->getTranslator()->hasTrans($transKey)) { $missingTranslationKeys[] = $transKey; } } return $missingTranslationKeys; }
/** * @return string */ protected function getHasAssignedExpression() { $entityConfig = $this->configManager->getProvider('extend')->getConfig($this->relationConfig->getId()->getClassName()); $relations = $entityConfig->get('relation'); $relation = $relations[$this->relationConfig->get('relation_key')]; $fieldName = ExtendConfigDumper::FIELD_PREFIX . $relation['target_field_id']->getFieldName(); if (null === $this->hasAssignedExpression) { $entityAlias = 'ce'; $compOperator = $this->relationConfig->getId()->getFieldType() == 'oneToMany' ? '=' : 'MEMBER OF'; if ($this->getRelation()->getId()) { $this->hasAssignedExpression = "CASE WHEN " . "(:relation {$compOperator} {$entityAlias}.{$fieldName} OR {$entityAlias}.id IN (:data_in)) AND " . "{$entityAlias}.id NOT IN (:data_not_in) " . "THEN true ELSE false END"; } else { $this->hasAssignedExpression = "CASE WHEN " . "{$entityAlias}.id IN (:data_in) AND {$entityAlias}.id NOT IN (:data_not_in) " . "THEN true ELSE false END"; } } return $this->hasAssignedExpression; }
/** * @param ConfigInterface $config * @param ConfigManager $configManager * * @return ConfigLogDiff */ protected function computeChanges(ConfigInterface $config, ConfigManager $configManager) { $configId = $config->getId(); $internalValues = $configManager->getProvider($configId->getScope())->getPropertyConfig()->getNotAuditableValues($configId); $changes = array_diff_key($configManager->getConfigChangeSet($config), $internalValues); if (empty($changes)) { return null; } $diff = new ConfigLogDiff(); $diff->setScope($configId->getScope()); $diff->setDiff($changes); $diff->setClassName($configId->getClassName()); if ($configId instanceof FieldConfigId) { $diff->setFieldName($configId->getFieldName()); } return $diff; }
/** * @param ConfigProvider $provider * @param ConfigInterface $config * @param array $data * @param string $state * @return array */ protected function processData(ConfigProvider $provider, ConfigInterface $config, array $data, $state) { if ($provider->getScope() === 'enum' && $config->get('enum_code')) { return []; } $translatable = $provider->getPropertyConfig()->getTranslatableValues($config->getId()); $translations = []; foreach ($data as $code => $value) { if (in_array($code, $translatable, true)) { // check if a label text was changed $labelKey = $config->get($code); if ($state === ExtendScope::STATE_NEW || !$this->translationHelper->isTranslationEqual($labelKey, $value)) { $translations[$labelKey] = $value; } // replace label text with label name in $value variable $value = $labelKey; } $config->set($code, $value); } $this->configManager->persist($config); return $translations; }
/** * {@inheritdoc} */ protected function apply(ConfigInterface $config) { $configId = $config->getId(); $className = $configId->getClassName(); if ($configId instanceof FieldConfigId) { $fieldName = $configId->getFieldName(); if (!isset($this->initialStates['fields'][$className][$fieldName])) { return true; } $initialState = $this->initialStates['fields'][$className][$fieldName]; } else { if (!isset($this->initialStates['entities'][$className])) { return true; } $initialState = $this->initialStates['entities'][$className]; } if ($initialState === ExtendScope::STATE_ACTIVE) { return true; } if ($initialState === ExtendScope::STATE_DELETE && !$config->is('state', ExtendScope::STATE_DELETE)) { return true; } return false; }
/** * @param ConfigInterface $fieldConfig * @param string $relationKey */ protected function createTargetRelation(ConfigInterface $fieldConfig, $relationKey) { /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $fieldConfig->getId(); $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType())); $targetEntityClass = $fieldConfig->get('target_entity'); $selfConfig = $this->extendConfigProvider->getConfig($selfFieldId->getClassName()); $selfRelations = $selfConfig->get('relation'); $selfRelationConfig =& $selfRelations[$relationKey]; $selfRelationConfig['field_id'] = $selfFieldId; $targetConfig = $this->extendConfigProvider->getConfig($targetEntityClass); $targetRelations = $targetConfig->get('relation'); $targetRelationConfig =& $targetRelations[$relationKey]; $targetRelationConfig['target_field_id'] = $selfFieldId; $selfConfig->set('relation', $selfRelations); $targetConfig->set('relation', $targetRelations); $this->extendConfigProvider->persist($targetConfig); }
/** * @param OutputInterface $output * @param ConfigInterface $config * @param string|null $attrName */ protected function dumpConfig(OutputInterface $output, ConfigInterface $config, $attrName = null) { $data = $config->all(); $res = [$config->getId()->getScope() => $data]; if (!empty($attrName) && (isset($data[$attrName]) || array_key_exists($attrName, $data))) { $res = [$config->getId()->getScope() => [$attrName => $data[$attrName]]]; } $output->writeln(print_r($res, true)); }
/** * @param ConfigInterface $config * @return bool */ public function filterFields(ConfigInterface $config) { $extendConfig = $this->extendProvider->getConfigById($config->getId()); /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $extendConfig->getId(); // skip system and not accessible fields if (!$config->is('owner', ExtendScope::OWNER_CUSTOM) || !ExtendHelper::isFieldAccessible($config)) { return false; } // skip invisible fields if (!$this->viewProvider->getConfigById($config->getId())->is('is_displayable')) { return false; } // skip relations if they are referenced to not accessible entity $underlyingFieldType = $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()); if (in_array($underlyingFieldType, RelationType::$anyToAnyRelations, true) && !ExtendHelper::isEntityAccessible($this->extendProvider->getConfig($extendConfig->get('target_entity')))) { return false; } return true; }
/** * @return ConfigIdInterface */ public function getConfigId() { return $this->config->getId(); }
/** * @param object[] $entities * @param object|null $defaultEntity * @param ConfigInterface $extendConfig * * @return array */ protected function getInitialElements($entities, $defaultEntity, ConfigInterface $extendConfig) { $result = []; foreach ($entities as $entity) { $extraData = []; foreach ($extendConfig->get('target_grid') as $fieldName) { $label = $this->configManager->getProvider('entity')->getConfig($extendConfig->get('target_entity'), $fieldName)->get('label'); $extraData[] = ['label' => $this->translator->trans($label), 'value' => FieldAccessor::getValue($entity, $fieldName)]; } $title = []; foreach ($extendConfig->get('target_title') as $fieldName) { $title[] = FieldAccessor::getValue($entity, $fieldName); } /** * If using ExtendExtension with a form that only updates part of * of the entity, we need to make sure an ID is present. An ID * isn't present when a PHP-based Validation Constraint is fired. */ if (null !== $entity->getId()) { $result[] = ['id' => $entity->getId(), 'label' => implode(' ', $title), 'link' => $this->router->generate('oro_entity_detailed', ['id' => $entity->getId(), 'entityName' => str_replace('\\', '_', $extendConfig->getId()->getClassName()), 'fieldName' => $extendConfig->getId()->getFieldName()]), 'extraData' => $extraData, 'isDefault' => $defaultEntity != null && $defaultEntity->getId() == $entity->getId()]; } } return $result; }
/** * @param ConfigInterface $config * @return ConfigInterface */ private function doMerge(ConfigInterface $config) { foreach ($this->persistConfigs as $persistConfig) { if ($config->getId()->toString() == $persistConfig->getId()->toString()) { $config = array_merge($persistConfig->all(), $config->all()); break; } } return $config; }
/** * @param ConfigInterface $extendConfig * * @return bool */ protected function isApplicableField(ConfigInterface $extendConfig) { return !$extendConfig->is('is_deleted') && $extendConfig->is('owner', ExtendScope::OWNER_CUSTOM) && !$extendConfig->is('state', ExtendScope::STATE_NEW) && !in_array($extendConfig->getId()->getFieldType(), RelationType::$toAnyRelations) && (!$extendConfig->has('target_entity') || !$this->extendConfigProvider->getConfig($extendConfig->get('target_entity'))->is('is_deleted')); }
/** * @param object[] $entities * @param object|null $defaultEntity * @param ConfigInterface $extendConfig * * @return array */ protected function getInitialElements($entities, $defaultEntity, ConfigInterface $extendConfig) { $result = []; foreach ($entities as $entity) { $extraData = []; foreach ($extendConfig->get('target_grid') as $fieldName) { $label = $this->configManager->getProvider('entity')->getConfig($extendConfig->get('target_entity'), $fieldName)->get('label'); $extraData[] = ['label' => $this->translator->trans($label), 'value' => FieldAccessor::getValue($entity, $fieldName)]; } $title = []; foreach ($extendConfig->get('target_title') as $fieldName) { $title[] = FieldAccessor::getValue($entity, $fieldName); } $result[] = ['id' => $entity->getId(), 'label' => implode(' ', $title), 'link' => $this->router->generate('oro_entity_detailed', ['id' => $entity->getId(), 'entityName' => str_replace('\\', '_', $extendConfig->getId()->getClassName()), 'fieldName' => $extendConfig->getId()->getFieldName()]), 'extraData' => $extraData, 'isDefault' => $defaultEntity != null && $defaultEntity->getId() == $entity->getId()]; } return $result; }
/** * @param ConfigInterface $extendConfig * * @return bool */ protected function updateStateValues(ConfigInterface $extendConfig) { $hasChanges = false; $extendProvider = $this->em->getExtendConfigProvider(); $className = $extendConfig->getId()->getClassName(); $fieldConfigs = $extendProvider->getConfigs($className, true); if ($extendConfig->is('state', ExtendScope::STATE_DELETE)) { // mark entity as deleted if (!$extendConfig->is('is_deleted')) { $extendConfig->set('is_deleted', true); $extendProvider->persist($extendConfig); $hasChanges = true; } // mark all fields as deleted foreach ($fieldConfigs as $fieldConfig) { if (!$fieldConfig->is('is_deleted')) { $fieldConfig->set('is_deleted', true); $extendProvider->persist($fieldConfig); $hasChanges = true; } } } elseif (!$extendConfig->is('state', ExtendScope::STATE_ACTIVE)) { $hasNotActiveFields = false; foreach ($fieldConfigs as $fieldConfig) { if (!$fieldConfig->is('state', ExtendScope::STATE_DELETE) && !$fieldConfig->is('state', ExtendScope::STATE_ACTIVE)) { $hasNotActiveFields = true; break; } } // Set entity state to active if all fields are active or deleted if (!$hasNotActiveFields) { $extendConfig->set('state', ExtendScope::STATE_ACTIVE); $extendProvider->persist($extendConfig); } $hasChanges = true; } if ($hasChanges) { $extendProvider->flush(); } }
/** * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * * @param ConfigInterface $extendConfig * @param ConfigProvider $configProvider * @param array|null $aliases * @param callable|null $filter function (ConfigInterface $config) : bool */ protected function checkSchema(ConfigInterface $extendConfig, ConfigProvider $configProvider, $aliases, $filter = null) { $className = $extendConfig->getId()->getClassName(); $doctrine = []; $entityName = $className; if (ExtendHelper::isCustomEntity($className)) { $type = 'Custom'; $tableName = $extendConfig->get('table'); if (!$tableName) { $tableName = $this->nameGenerator->generateCustomEntityTableName($className); } $doctrine[$entityName] = ['type' => 'entity', 'table' => $tableName]; // add 'id' field only for Custom entity without inheritance if (!$extendConfig->has('inherit')) { $doctrine[$entityName]['fields'] = ['id' => ['type' => 'integer', 'id' => true, 'generator' => ['strategy' => 'AUTO']]]; } } else { $type = 'Extend'; $entityName = $extendConfig->get('extend_class'); $doctrine[$entityName] = ['type' => 'mappedSuperclass', 'fields' => []]; } $schema = $extendConfig->get('schema', false, []); $properties = isset($schema['property']) && null !== $filter ? $schema['property'] : []; $relationProperties = isset($schema['relation']) && null !== $filter ? $schema['relation'] : []; $defaultProperties = isset($schema['default']) && null !== $filter ? $schema['default'] : []; $addRemoveMethods = isset($schema['addremove']) && null !== $filter ? $schema['addremove'] : []; $fieldConfigs = null === $filter ? $configProvider->getConfigs($className, true) : $configProvider->filter($filter, $className, true); foreach ($fieldConfigs as $fieldConfig) { $this->updateFieldState($fieldConfig); $this->checkFieldSchema($entityName, $fieldConfig, $relationProperties, $defaultProperties, $properties, $doctrine); } $relations = $extendConfig->get('relation', false, []); foreach ($relations as $relation) { /** @var FieldConfigId $fieldId */ $fieldId = $relation['field_id']; if (!$fieldId) { continue; } $fieldName = $fieldId->getFieldName(); $isDeleted = $configProvider->hasConfig($fieldId->getClassName(), $fieldName) ? $configProvider->getConfig($fieldId->getClassName(), $fieldName)->is('is_deleted') : false; if (!isset($relationProperties[$fieldName])) { $relationProperties[$fieldName] = []; if ($isDeleted) { $relationProperties[$fieldName]['private'] = true; } } if (!$isDeleted && $fieldId->getFieldType() !== RelationType::MANY_TO_ONE) { $addRemoveMethods[$fieldName]['self'] = $fieldName; /** @var FieldConfigId $targetFieldId */ $targetFieldId = $relation['target_field_id']; if ($targetFieldId) { $fieldType = $fieldId->getFieldType(); $addRemoveMethods[$fieldName]['target'] = $targetFieldId->getFieldName(); $addRemoveMethods[$fieldName]['is_target_addremove'] = $fieldType === RelationType::MANY_TO_MANY; } } } $schema = ['class' => $className, 'entity' => $entityName, 'type' => $type, 'property' => $properties, 'relation' => $relationProperties, 'default' => $defaultProperties, 'addremove' => $addRemoveMethods, 'doctrine' => $doctrine]; if ($type === 'Extend') { $parentClassName = get_parent_class($className); if ($parentClassName === $entityName) { $parentClassName = $aliases[$entityName]; } $schema['parent'] = $parentClassName; $schema['inherit'] = get_parent_class($parentClassName); } elseif ($extendConfig->has('inherit')) { $schema['inherit'] = $extendConfig->get('inherit'); } $extendConfig->set('schema', $schema); $this->configManager->persist($extendConfig); }
/** * Check if the given configurable field is ready to be used in a business logic. * It means that a field should exist in a class and should not be marked as deleted. * * @param ConfigInterface $extendFieldConfig The field's configuration in the 'extend' scope * * @return bool */ public static function isFieldAccessible(ConfigInterface $extendFieldConfig) { if ($extendFieldConfig->is('is_extend')) { if ($extendFieldConfig->is('is_deleted')) { return false; } if ($extendFieldConfig->is('state', ExtendScope::STATE_NEW)) { return false; } // check if a new field has been requested to be deleted before schema is updated if ($extendFieldConfig->is('state', ExtendScope::STATE_DELETE)) { /** @var FieldConfigId $fieldId */ $fieldId = $extendFieldConfig->getId(); if (!property_exists($fieldId->getClassName(), $fieldId->getFieldName())) { return false; } } } return true; }
/** * @param ConfigInterface $config * @return bool */ public function filterFields(ConfigInterface $config) { $extendConfig = $this->extendProvider->getConfigById($config->getId()); /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $extendConfig->getId(); // skip system, new and deleted fields if (!$config->is('owner', ExtendScope::OWNER_CUSTOM) || $config->is('state', ExtendScope::STATE_NEW) || $config->is('is_deleted')) { return false; } // skip invisible fields if (!$this->viewProvider->getConfigById($config->getId())->is('is_displayable')) { return false; } // skip relations if they are referenced to deleted entity $underlyingFieldType = $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()); if (in_array($underlyingFieldType, RelationType::$anyToAnyRelations) && $this->extendProvider->getConfig($extendConfig->get('target_entity'))->is('is_deleted', true)) { return false; } return true; }
/** * In case of FieldConfigId replaces OLD field name with given NEW one * * @param ConfigInterface $config * @param string $newFieldName * * @return ConfigInterface */ protected function changeConfigFieldName(ConfigInterface $config, $newFieldName) { $configId = $config->getId(); if ($configId instanceof FieldConfigId) { $newConfigId = new FieldConfigId($configId->getScope(), $configId->getClassName(), $newFieldName, $configId->getFieldType()); $config = new Config($newConfigId, $config->getValues()); } return $config; }
/** * @param ConfigInterface $extendConfig * * @return bool */ protected function checkState(ConfigInterface $extendConfig) { $hasChanges = false; $extendProvider = $this->em->getExtendConfigProvider(); $className = $extendConfig->getId()->getClassName(); if ($extendConfig->is('state', ExtendScope::STATE_DELETE)) { // mark entity as deleted if (!$extendConfig->is('is_deleted')) { $extendConfig->set('is_deleted', true); $extendProvider->persist($extendConfig); $hasChanges = true; } // mark all fields as deleted $fieldConfigs = $extendProvider->getConfigs($className, true); foreach ($fieldConfigs as $fieldConfig) { if (!$fieldConfig->is('is_deleted')) { $fieldConfig->set('is_deleted', true); $extendProvider->persist($fieldConfig); $hasChanges = true; } } } elseif (!$extendConfig->is('state', ExtendScope::STATE_ACTIVE)) { $extendConfig->set('state', ExtendScope::STATE_ACTIVE); $extendProvider->persist($extendConfig); $hasChanges = true; } return $hasChanges; }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { foreach ($this->items as $code => $config) { if (isset($config['form']['type'])) { $options = isset($config['form']['options']) ? $config['form']['options'] : array(); $options['config_id'] = $this->config->getId(); $options['config_is_new'] = $this->configModel->getId() == false; /** * Disable field on editAction */ if (isset($config['options']['create_only']) && $this->configModel->getId()) { $options['disabled'] = true; $this->appendClassAttr($options, 'disabled-' . $config['form']['type']); } $propertyOnForm = false; $properties = []; if (isset($config['options']['required_property'])) { $properties[] = $config['options']['required_property']; } if (isset($config['options']['required_properties'])) { $properties = array_merge($properties, $config['options']['required_properties']); } if (!empty($properties)) { foreach ($properties as $property) { if (isset($property['config_id'])) { $configId = $property['config_id']; $fieldName = array_key_exists('field_name', $configId) ? $configId['field_name'] : false; if ($fieldName === false && $this->config->getId() instanceof FieldConfigId) { $fieldName = $this->config->getId()->getFieldName(); } $className = isset($configId['class_name']) ? $configId['class_name'] : $this->config->getId()->getClassName(); $scope = isset($configId['scope']) ? $configId['scope'] : $this->config->getId()->getScope(); if ($fieldName) { $configId = new FieldConfigId($scope, $className, $fieldName, $this->config->getId()->getFieldType()); } else { $configId = new EntityConfigId($scope, $className); } //check if requirement property is set in this form if ($className == $this->config->getId()->getClassName()) { if ($fieldName) { if ($this->config->getId() instanceof FieldConfigId && $this->config->getId()->getFieldName() == $fieldName) { $propertyOnForm = true; } } else { $propertyOnForm = true; } } } else { $propertyOnForm = true; $configId = $this->config->getId(); } $requireConfig = $this->configManager->getConfig($configId); if ($requireConfig->get($property['code']) != $property['value']) { if ($propertyOnForm) { $this->appendClassAttr($options, 'hide'); } else { continue; } } } if ($propertyOnForm) { $this->setAttr($options, 'data-requireProperty', $configId->toString() . $property['code']); $this->setAttr($options, 'data-requireValue', $property['value']); } } if (isset($config['constraints'])) { $options['constraints'] = $this->parseValidator($config['constraints']); } $this->setAttr($options, 'data-property_id', $this->config->getId()->toString() . $code); $builder->add($code, $config['form']['type'], $options); } } }
/** * Add custom entity mapping skeleton * * @param array $mapConfig * @param ConfigInterface $config * @return array */ protected function addCustomEntityMapping(array $mapConfig, ConfigInterface $config) { $className = $config->getId()->getClassName(); $label = $this->configManager->getProvider('entity')->getConfig($className)->get('label'); $mapConfig[$className] = ['alias' => $config->get('schema')['doctrine'][$className]['table'], 'label' => $label, self::TITLE_FIELDS_PATH => [], 'route' => ['name' => 'oro_entity_view', 'parameters' => ['id' => 'id', 'entityName' => '@' . str_replace('\\', '_', $className) . '@']], 'search_template' => 'OroEntityExtendBundle:Search:result.html.twig', self::FIELDS_PATH => [], 'mode' => 'normal']; return $mapConfig; }