diff --git a/src/bundle/Controller/UserController.php b/src/bundle/Controller/UserController.php index d3f806d2..278a8b5f 100644 --- a/src/bundle/Controller/UserController.php +++ b/src/bundle/Controller/UserController.php @@ -170,7 +170,7 @@ public function editAction( string $language, Request $request ) { - $user = $this->userService->loadUser($contentId); + $user = $this->userService->loadUser($contentId, [$language]); if (!$this->permissionResolver->canUser('content', 'edit', $user)) { throw new CoreUnauthorizedException('content', 'edit', ['userId' => $contentId]); } diff --git a/src/bundle/Resources/config/validation.yaml b/src/bundle/Resources/config/validation.yaml index 949c7058..ba8049f2 100644 --- a/src/bundle/Resources/config/validation.yaml +++ b/src/bundle/Resources/config/validation.yaml @@ -29,7 +29,3 @@ EzSystems\EzPlatformContentForms\Data\User\UserAccountFieldData: username: - Valid: ~ - NotBlank: ~ - -EzSystems\EzPlatformContentForms\Data\Content\FieldData: - constraints: - - EzSystems\EzPlatformContentForms\Validator\Constraints\FieldValue: ~ diff --git a/src/lib/Form/Processor/User/UserUpdateFormProcessor.php b/src/lib/Form/Processor/User/UserUpdateFormProcessor.php index a752a15a..7bf7d7e4 100644 --- a/src/lib/Form/Processor/User/UserUpdateFormProcessor.php +++ b/src/lib/Form/Processor/User/UserUpdateFormProcessor.php @@ -81,6 +81,14 @@ private function setContentFields(UserUpdateData $data, string $languageCode): v $data->contentUpdateStruct = $this->contentService->newContentUpdateStruct(); foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) { + if ( + !$fieldData->fieldDefinition->isTranslatable + && $data->user->contentInfo->mainLanguageCode !== $languageCode + ) { + // Skip updating not translatable fields when editing not main language + + continue; + } $data->contentUpdateStruct->setField($fieldDefIdentifier, $fieldData->value, $languageCode); } } diff --git a/src/lib/Form/Type/Content/BaseContentType.php b/src/lib/Form/Type/Content/BaseContentType.php index a2e57765..19336e7e 100644 --- a/src/lib/Form/Type/Content/BaseContentType.php +++ b/src/lib/Form/Type/Content/BaseContentType.php @@ -8,6 +8,7 @@ namespace EzSystems\EzPlatformContentForms\Form\Type\Content; +use EzSystems\EzPlatformContentForms\Validator\Constraints\FieldValue; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; @@ -42,6 +43,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'content' => $options['content'] ?? null, 'contentCreateStruct' => $options['contentCreateStruct'] ?? null, 'contentUpdateStruct' => $options['contentUpdateStruct'] ?? null, + 'constraints' => [ + new FieldValue(null, null, ['intent' => $options['intent']]), + ], ], ]) ->add('redirectUrlAfterPublish', HiddenType::class, [ @@ -59,7 +63,12 @@ public function buildView(FormView $view, FormInterface $form, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver - ->setDefaults(['translation_domain' => 'ezplatform_content_forms_content']) + ->setDefined(['intent']) + ->setAllowedTypes('intent', 'string') + ->setDefaults([ + 'translation_domain' => 'ezplatform_content_forms_content', + 'intent' => 'update', + ]) ->setRequired(['languageCode', 'mainLanguageCode']); } } diff --git a/src/lib/Form/Type/Content/ContentEditType.php b/src/lib/Form/Type/Content/ContentEditType.php index a5950cf9..2699f09c 100644 --- a/src/lib/Form/Type/Content/ContentEditType.php +++ b/src/lib/Form/Type/Content/ContentEditType.php @@ -68,6 +68,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) public function configureOptions(OptionsResolver $resolver) { $resolver + ->setDefined(['intent']) + ->setAllowedTypes('intent', 'string') + ->setAllowedValues('intent', ['register', 'update', 'create', 'translate']) ->setDefaults([ 'content' => null, 'contentCreateStruct' => null, diff --git a/src/lib/Form/Type/FieldType/UserAccountFieldType.php b/src/lib/Form/Type/FieldType/UserAccountFieldType.php index b11cef2a..c37f3468 100644 --- a/src/lib/Form/Type/FieldType/UserAccountFieldType.php +++ b/src/lib/Form/Type/FieldType/UserAccountFieldType.php @@ -67,6 +67,6 @@ public function configureOptions(OptionsResolver $resolver) 'translation_domain' => 'ezplatform_content_forms_fieldtype', ]) ->setRequired(['intent']) - ->setAllowedValues('intent', ['register', 'create', 'update']); + ->setAllowedValues('intent', ['register', 'create', 'update', 'translate']); } } diff --git a/src/lib/Validator/Constraints/FieldValueValidator.php b/src/lib/Validator/Constraints/FieldValueValidator.php index 6e69b66b..90f113f5 100644 --- a/src/lib/Validator/Constraints/FieldValueValidator.php +++ b/src/lib/Validator/Constraints/FieldValueValidator.php @@ -42,6 +42,18 @@ public function validate($value, Constraint $constraint): void $fieldDefinition = $this->getFieldDefinition($value); $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier); + if ( + false === $fieldDefinition->isTranslatable + && isset($constraint->payload['intent']) + && $constraint->payload['intent'] === 'translate' + ) { + // In content translation mode and the field is not translatable. + // Validation has to be skipped or it'll violate constraints on + // some field i.e. ezuser + + return; + } + if ($fieldDefinition->isRequired && $fieldType->isEmptyValue($fieldValue)) { $validationErrors = [ new ValidationError(