Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bundle/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
4 changes: 0 additions & 4 deletions src/bundle/Resources/config/validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,3 @@ EzSystems\EzPlatformContentForms\Data\User\UserAccountFieldData:
username:
- Valid: ~
- NotBlank: ~

EzSystems\EzPlatformContentForms\Data\Content\FieldData:
constraints:
- EzSystems\EzPlatformContentForms\Validator\Constraints\FieldValue: ~
8 changes: 8 additions & 0 deletions src/lib/Form/Processor/User/UserUpdateFormProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/lib/Form/Type/Content/BaseContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, [
Expand All @@ -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']);
}
}
3 changes: 3 additions & 0 deletions src/lib/Form/Type/Content/ContentEditType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Form/Type/FieldType/UserAccountFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
12 changes: 12 additions & 0 deletions src/lib/Validator/Constraints/FieldValueValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down