Problem/Motivation
Currently CEB::validate will validate only the current translation on which the ::validate() method is being called. Considering that it is called only in the FAPI and there we could edit only a single translation leads to the conclusion that it is fine to validate only a single translation instead of the whole entity and each of its translations ... but actually this is not an entirely correct statement, because while editing a single translation over the API we might edit field values of different translations as well by some form element which if changed will trigger changes in other translations.
An example from the core where multiple translations will be edited on entity form submit -
\Drupal\content_translation\ContentTranslationHandler::entityFormAlter adds the 'retranslate' form element and \Drupal\content_translation\ContentTranslationHandler::entityFormEntityBuild will set the field "content_translation_outdated" of all other translations but the current one to TRUE. Currently we will save all the translations without validating them!
This possibility to validate all entity translations is also required by #2927547: Add an option to show all validation failures even for fields not included in the form display.
Proposed resolution
Introduce a new method FieldableEntityInterface::validateAllTranslations(). By default let the content entity form validate only the current translation.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#16 | 2890405-16.patch | 6.36 KB | hchonov |
#4 | 2890405-4-translation-errors.png | 42.79 KB | hchonov |
Comments
Comment #2
hchonovComment #4
hchonovWe already have a case in core where the validation of an other translation is failing because of the constraint ModerationState. Making the errors shown for other translations prettier.
Comment #6
hchonovI've accedently prepared 2890405-4.patch for 8.3.x and it doesn't apply to 8.4.x ... Here a reroll for 8.4.x.
Comment #7
hchonovAnd here is the fix for the failing constraint .. basically if the state hasn't changed then we don't have to check if the transition is allowed.
Comment #10
hchonovComment #12
hchonovGrrr...
Comment #13
timmillwoodLooks good, but I guess we need specific test for this?
Comment #14
hchonovSure! I'll write a test.
Comment #16
hchonovAfter rethinking this I guess that it is not right to change
FieldableEntityInterface::validate()
to validate all entity translations. Instead it would be better to provide a new methodFieldableEntityInterface::validateAllTranslations()
, which will take of this and when a validation of all entity translations is required then this method should be used.I've update the documentation on the validation methods and properties to indicate that they are bound to the curren entittranslation.
Comment #17
tstoecklerJust a cursory review, but I like the idea of the new patch!
I think this can be shortened to
$this->getTranslationLanguages(FALSE)
Comment #18
hchonovThat would be nice, but unfortunately the parameter of
::getTranslationLanguages()
determines whether the default entity translation language should be included or not, but currently we might be on a non-default entity translation and in this case setting the parameter to FALSE would not be sufficient as we still need the default entity translation. We only want to remove the current translation from the iteration as it is being validated as first.Comment #20
tstoecklerOops, sorry. So much for drive by reviews. You are, as always, correct of course.