/**
  * {@inheritdoc}
  */
 public function build(ClassMetadataBuilder $metadataBuilder, ConfigInterface $extendConfig)
 {
     $relations = $extendConfig->get('relation');
     foreach ($relations as $relation) {
         /** @var FieldConfigId $fieldId */
         $fieldId = $relation['field_id'];
         if ($relation['assign'] && $fieldId) {
             $targetEntity = $relation['target_entity'];
             /** @var FieldConfigId|null $targetFieldId */
             $targetFieldId = !empty($relation['target_field_id']) ? $relation['target_field_id'] : null;
             $cascade = !empty($relation['cascade']) ? $relation['cascade'] : [];
             switch ($fieldId->getFieldType()) {
                 case 'manyToOne':
                     $cascade[] = 'detach';
                     $this->buildManyToOneRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId, $cascade);
                     break;
                 case 'oneToMany':
                     $cascade[] = 'detach';
                     $this->buildOneToManyRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId, $cascade);
                     break;
                 case 'manyToMany':
                     if ($relation['owner']) {
                         $this->buildManyToManyOwningSideRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId, $cascade);
                     } elseif ($targetFieldId) {
                         $this->buildManyToManyTargetSideRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId);
                     }
                     break;
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function build(ClassMetadataBuilder $metadataBuilder, ConfigInterface $extendConfig)
 {
     $relations = $extendConfig->get('relation', false, []);
     $schema = $extendConfig->get('schema', false, []);
     foreach ($relations as $relation) {
         /** @var FieldConfigId $fieldId */
         $fieldId = $relation['field_id'];
         if ($fieldId && isset($schema['relation'][$fieldId->getFieldName()])) {
             $targetEntity = $relation['target_entity'];
             /** @var FieldConfigId|null $targetFieldId */
             $targetFieldId = !empty($relation['target_field_id']) ? $relation['target_field_id'] : null;
             $cascade = !empty($relation['cascade']) ? $relation['cascade'] : [];
             switch ($fieldId->getFieldType()) {
                 case RelationType::MANY_TO_ONE:
                     $cascade[] = 'detach';
                     $this->buildManyToOneRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId, $cascade);
                     break;
                 case RelationType::ONE_TO_MANY:
                     $cascade[] = 'detach';
                     $this->buildOneToManyRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId, $cascade);
                     break;
                 case RelationType::MANY_TO_MANY:
                     if ($relation['owner']) {
                         $this->buildManyToManyOwningSideRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId, $cascade);
                     } elseif ($targetFieldId) {
                         $this->buildManyToManyTargetSideRelation($metadataBuilder, $fieldId, $targetEntity, $targetFieldId);
                     }
                     break;
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * @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;
 }
Esempio n. 4
0
 /**
  * @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;
 }
Esempio n. 5
0
 /**
  * @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]]);
     }
 }
Esempio n. 7
0
 /**
  * @param ConfigInterface $formConfig
  * @param string          $class
  * @param string          $property
  *
  * @return TypeGuess
  */
 protected function getTypeGuess(ConfigInterface $formConfig, $class, $property)
 {
     $formType = $formConfig->get('form_type');
     $formOptions = $formConfig->has('form_options') ? $formConfig->get('form_options') : array();
     $formOptions = $this->addLabelOption($formOptions, $class, $property);
     // fallback guess from recursive call must be with low confidence
     return is_null($property) ? $this->createTypeGuess($formType, $formOptions, TypeGuess::LOW_CONFIDENCE) : $this->createTypeGuess($formType, $formOptions);
 }
 /**
  * @param TokenInterface  $token
  * @param ConfigInterface $config
  * @param object          $entity
  */
 protected function setDefaultOrganization(TokenInterface $token, ConfigInterface $config, $entity)
 {
     if ($token instanceof OrganizationContextTokenInterface && $config->has('organization_field_name')) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $fieldName = $config->get('organization_field_name');
         if (!$accessor->getValue($entity, $fieldName)) {
             $accessor->setValue($entity, $fieldName, $token->getOrganizationContext());
         }
     }
 }
Esempio n. 9
0
 /**
  * @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
  * @param ClassMetadataBuilder $cmBuilder
  */
 protected function prepareRelations(ConfigInterface $config, ClassMetadataBuilder $cmBuilder)
 {
     if ($config->is('relation')) {
         foreach ($config->get('relation') as $relation) {
             /** @var FieldConfigId $fieldId */
             if ($relation['assign'] && ($fieldId = $relation['field_id'])) {
                 /** @var FieldConfigId $targetFieldId */
                 $targetFieldId = $relation['target_field_id'];
                 $targetFieldName = $targetFieldId ? ExtendConfigDumper::FIELD_PREFIX . $targetFieldId->getFieldName() : null;
                 $fieldName = ExtendConfigDumper::FIELD_PREFIX . $fieldId->getFieldName();
                 $defaultName = ExtendConfigDumper::DEFAULT_PREFIX . $fieldId->getFieldName();
                 switch ($fieldId->getFieldType()) {
                     case 'manyToOne':
                         $builder = $cmBuilder->createManyToOne($fieldName, $relation['target_entity']);
                         if ($targetFieldName) {
                             $builder->inversedBy($targetFieldName);
                         }
                         $builder->addJoinColumn($fieldName . '_id', 'id', true, false, 'SET NULL');
                         $builder->cascadeDetach();
                         $builder->build();
                         break;
                     case 'oneToMany':
                         /** create 1:* */
                         $builder = $cmBuilder->createOneToMany($fieldName, $relation['target_entity']);
                         $builder->mappedBy($targetFieldName);
                         $builder->cascadeDetach();
                         $builder->build();
                         /** create 1:1 default */
                         $builder = $cmBuilder->createOneToOne($defaultName, $relation['target_entity']);
                         $builder->addJoinColumn($defaultName . '_id', 'id', true, false, 'SET NULL');
                         $builder->build();
                         break;
                     case 'manyToMany':
                         if ($relation['owner']) {
                             $builder = $cmBuilder->createManyToMany($fieldName, $relation['target_entity']);
                             if ($targetFieldName) {
                                 $builder->inversedBy($targetFieldName);
                             }
                             $builder->setJoinTable(ExtendHelper::generateManyToManyJoinTableName($fieldId, $relation['target_entity']));
                             $builder->build();
                             $builder = $cmBuilder->createOneToOne($defaultName, $relation['target_entity']);
                             $builder->addJoinColumn($defaultName . '_id', 'id', true, false, 'SET NULL');
                             $builder->build();
                         } else {
                             $cmBuilder->addInverseManyToMany($fieldName, $relation['target_entity'], $targetFieldName);
                         }
                         break;
                 }
             }
         }
     }
 }
Esempio n. 11
0
 /**
  * @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);
 }
Esempio n. 12
0
 /**
  * {@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 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;
 }
Esempio n. 14
0
 /**
  * @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;
 }
Esempio n. 15
0
 /**
  * @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;
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function build(ClassMetadataBuilder $metadataBuilder, ConfigInterface $extendConfig)
 {
     $relations = $extendConfig->get('relation', false, []);
     $schema = $extendConfig->get('schema', false, []);
     foreach ($relations as $relationKey => $relation) {
         /** @var FieldConfigId $fieldId */
         $fieldId = $relation['field_id'];
         if ($fieldId && isset($schema['relation'][$fieldId->getFieldName()])) {
             switch ($fieldId->getFieldType()) {
                 case RelationType::MANY_TO_ONE:
                     $this->buildManyToOneRelation($metadataBuilder, $fieldId, $relation);
                     break;
                 case RelationType::ONE_TO_MANY:
                     $this->buildOneToManyRelation($metadataBuilder, $fieldId, $relation, $relationKey);
                     break;
                 case RelationType::MANY_TO_MANY:
                     $this->buildManyToManyRelation($metadataBuilder, $fieldId, $relation);
                     break;
             }
         }
     }
 }
Esempio n. 17
0
 /**
  * @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;
 }
Esempio n. 18
0
 /**
  * @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;
 }
Esempio n. 19
0
 /**
  * {@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;
 }
 /**
  * @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
  * @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;
 }
Esempio n. 22
0
 /**
  * @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));
 }
Esempio n. 23
0
 /**
  * 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;
 }
Esempio n. 24
0
 /**
  * @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;
 }
Esempio n. 25
0
 /**
  * @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();
     }
 }
Esempio n. 26
0
 /**
  * @param ConfigInterface $enumFieldConfig
  *
  * @return bool
  */
 protected function updateEnumFieldConfig(ConfigInterface $enumFieldConfig)
 {
     $hasChanges = false;
     $attributes = ['enum_name', 'enum_locale', 'enum_public', 'enum_options'];
     foreach ($attributes as $code) {
         if ($enumFieldConfig->get($code) !== null) {
             $enumFieldConfig->remove($code);
             $hasChanges = true;
         }
     }
     if ($hasChanges) {
         $this->configManager->persist($enumFieldConfig);
     }
     return $hasChanges;
 }
 /**
  * @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);
 }
Esempio n. 28
0
 /**
  * @return ConfigIdInterface
  */
 public function getConfigId()
 {
     return $this->config->getId();
 }
Esempio n. 29
0
 /**
  * @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;
 }
Esempio n. 30
0
 /**
  * @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;
 }