예제 #1
0
 /**
  * {@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;
             }
         }
     }
 }
예제 #2
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);
 }
예제 #3
0
 /**
  * {@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;
             }
         }
     }
 }
예제 #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;
 }
 /**
  * @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]]);
     }
 }
예제 #6
0
 /**
  * @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());
         }
     }
 }
 /**
  * @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;
                 }
             }
         }
     }
 }
예제 #8
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;
             }
         }
     }
 }
예제 #9
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);
         }
     }
 }
예제 #10
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)) {
             $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;
 }
예제 #12
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;
 }
예제 #13
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;
 }
예제 #14
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;
 }
 /**
  * Makes sure that both source and target entities know about a reverse relation
  *
  * @param ConfigInterface $fieldConfig
  */
 protected function ensureReverseRelationCompleted(ConfigInterface $fieldConfig)
 {
     /** @var FieldConfigId $fieldConfigId */
     $fieldConfigId = $fieldConfig->getId();
     $relationKey = $fieldConfig->get('relation_key');
     $selfConfig = $this->extendConfigProvider->getConfig($fieldConfigId->getClassName());
     $selfRelations = $selfConfig->get('relation', false, []);
     if (isset($selfRelations[$relationKey]['field_id']) && $selfRelations[$relationKey]['field_id']) {
         return;
     }
     $targetConfig = $this->extendConfigProvider->getConfig($fieldConfig->get('target_entity'));
     $targetRelations = $targetConfig->get('relation', false, []);
     if (!isset($targetRelations[$relationKey])) {
         return;
     }
     $selfFieldId = new FieldConfigId('extend', $fieldConfigId->getClassName(), $fieldConfigId->getFieldName(), $this->fieldTypeHelper->getUnderlyingType($fieldConfigId->getFieldType()));
     $selfRelations[$relationKey]['field_id'] = $selfFieldId;
     $targetRelations[$relationKey]['target_field_id'] = $selfFieldId;
     $selfConfig->set('relation', $selfRelations);
     $targetConfig->set('relation', $targetRelations);
     $this->configManager->persist($selfConfig);
     $this->configManager->persist($targetConfig);
 }
예제 #16
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;
 }
예제 #17
0
 /**
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  *
  * @param ConfigInterface $extendConfig
  * @param array|null $aliases
  * @param array|null $skippedOrigins
  */
 protected function checkSchema(ConfigInterface $extendConfig, $aliases, array $skippedOrigins = null)
 {
     $extendProvider = $this->em->getExtendConfigProvider();
     $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');
     $properties = [];
     $relationProperties = $schema ? $schema['relation'] : [];
     $defaultProperties = [];
     $addRemoveMethods = [];
     $fieldConfigs = $extendProvider->filter($this->createOriginFilterCallback($skippedOrigins), $className, true);
     foreach ($fieldConfigs as $fieldConfig) {
         $this->checkFields($entityName, $fieldConfig, $relationProperties, $defaultProperties, $properties, $doctrine);
         $extendProvider->persist($fieldConfig);
     }
     $relations = $extendConfig->get('relation', false, []);
     foreach ($relations as &$relation) {
         if (!$relation['field_id']) {
             continue;
         }
         $relation['assign'] = true;
         if ($relation['field_id']->getFieldType() !== RelationType::MANY_TO_ONE) {
             $fieldName = $relation['field_id']->getFieldName();
             $addRemoveMethods[$fieldName]['self'] = $fieldName;
             if ($relation['target_field_id']) {
                 $addRemoveMethods[$fieldName]['target'] = $relation['target_field_id']->getFieldName();
                 $addRemoveMethods[$fieldName]['is_target_addremove'] = $relation['field_id']->getFieldType() === RelationType::MANY_TO_MANY;
             }
         }
         $this->updateRelationValues($relation['target_entity'], $relation['field_id']);
     }
     $extendConfig->set('relation', $relations);
     $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);
     $extendProvider->persist($extendConfig);
 }
예제 #18
0
 /**
  * @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);
 }
예제 #19
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;
 }
 /**
  * Return view link options or simple text
  *
  * @param object          $targetEntity
  * @param ConfigInterface $field
  *
  * @throws \Doctrine\ORM\Mapping\MappingException
  * @return array|string
  */
 protected function getValueForManyToOne($targetEntity, ConfigInterface $field)
 {
     $targetFieldName = $field->get('target_field');
     $targetClassName = $field->get('target_entity');
     if (!class_exists($targetClassName)) {
         return '';
     }
     $title = (string) $this->propertyAccessor->getValue($targetEntity, $targetFieldName);
     $targetMetadata = $this->entityManager->getClassMetadata($targetClassName);
     $id = $this->propertyAccessor->getValue($targetEntity, $targetMetadata->getSingleIdentifierFieldName());
     $relationExtendConfig = $this->extendProvider->getConfig($targetClassName);
     $routeOptions = $relationExtendConfig->is('owner', ExtendScope::OWNER_CUSTOM) ? $this->getCustomEntityViewRouteOptions($targetClassName, $id) : $this->getClassViewRouteOptions($targetClassName, $id);
     if ($routeOptions['route']) {
         return ['link' => $this->router->generate($routeOptions['route'], $routeOptions['route_params']), 'title' => $title];
     }
     return $title;
 }
예제 #21
0
 /**
  * @param string          $labelKey
  * @param string          $entityClass
  * @param string          $relationName
  * @param ConfigInterface $targetEntityConfig
  *
  * @return string
  */
 protected function getAssociationLabel($labelKey, $entityClass, $relationName, ConfigInterface $targetEntityConfig)
 {
     $label = $targetEntityConfig->get($labelKey);
     if (!$label) {
         $label = ConfigHelper::getTranslationKey('entity', $labelKey, $entityClass, $relationName);
     }
     return $label;
 }
예제 #22
0
 /**
  * @param ConfigInterface $entityConfig
  * @param string          $relationKey
  *
  * @return bool
  */
 protected function hasRelation(ConfigInterface $entityConfig, $relationKey)
 {
     $relations = $entityConfig->get('relation', false, []);
     return isset($relations[$relationKey]);
 }
 /**
  * {@inheritDoc}
  */
 protected function getOwnershipMetadata(ConfigInterface $config)
 {
     $ownerType = $config->get('frontend_owner_type');
     $ownerFieldName = $config->get('frontend_owner_field_name');
     $ownerColumnName = $config->get('frontend_owner_column_name');
     $organizationFieldName = $config->get('organization_field_name');
     $organizationColumnName = $config->get('organization_column_name');
     return new FrontendOwnershipMetadata($ownerType, $ownerFieldName, $ownerColumnName, $organizationFieldName, $organizationColumnName);
 }
 /**
  * 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;
 }
예제 #25
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;
 }
 /**
  * {@inheritdoc}
  */
 protected function isTargetEntityApplicable(ConfigInterface $targetEntityConfig)
 {
     $entityClasses = $targetEntityConfig->get($this->getAssociationAttributeName());
     return !empty($entityClasses);
 }
예제 #27
0
 /**
  * @param array $options
  * @param ConfigInterface $extendConfig
  * @param FieldConfigId $fieldConfigId
  *
  * @return array
  */
 protected function addConstraintsToOptions(array $options, ConfigInterface $extendConfig, FieldConfigId $fieldConfigId)
 {
     switch ($fieldConfigId->getFieldType()) {
         case 'decimal':
             $options['constraints'] = [new Decimal(['precision' => $extendConfig->get('precision'), 'scale' => $extendConfig->get('scale')])];
             break;
         case 'string':
             $length = $extendConfig->get('length') ?: 255;
             $options['constraints'] = [new Length(['max' => $length])];
             break;
     }
     return $options;
 }
 /**
  * @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);
 }
예제 #29
0
 /**
  * {@inheritdoc}
  */
 protected function apply(ConfigInterface $config)
 {
     return $config->get('state') === ExtendScope::STATE_ACTIVE || !in_array($config->get('origin'), $this->skippedOrigins, true);
 }
 /**
  * @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'));
 }