Problem/Motivation
On certain entity types, the Published, Authored by, and Authored on fields are displayed twice on the translation form. This is confusing to the users and the behavior after saving is unclear concerning which value of the two is kept.
Steps to reproduce
Set up a multilingual website, allow Media to be translated. Upon translating a media, the 3 aforementioned fields are present twice on the form:
red: published status; blue: authoring information.
Proposed resolution
Show Published, Authored by, and Authored on fields only if those are not provided natively by the entity type.
Look of the form with the patch applied:
Note: nodes and comments currently have logic that hide the duplicated fields: this can be removed in this issue.
Note: blocks should have the published checkbox displayed even though the field is not supported in the blocks UI (see #2834546: UI for publishing/unpublishing block_content blocks) so for those, we force-display the field.
Remaining tasks
Should this be postponed on #2834546: UI for publishing/unpublishing block_content blocks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#81 | 2971390-81.patch | 21.12 KB | kostyashupenko |
#80 | 2971390-nr-bot.txt | 85 bytes | needs-review-queue-bot |
#75 | 2971390-75.patch | 21.11 KB | quietone |
| |||
#75 | interdiff-68-75.txt | 2.3 KB | quietone |
#71 | Screenshot 2023-07-21 at 15-08-53 Create German translation of IMG_2110.JPG Drush Site-Install.png | 49.01 KB | mathilde_dumond |
Issue fork drupal-2971390
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedProviding a fix for the metadata field name.
Comment #4
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedOops, the above patch contains invalid paths. Fixed.
Comment #5
BerdirSetting to needs work for tests.
Comment #6
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedAdding tests.
Comment #8
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedThis also affects Media and other commonly translated entities. We could possibly think about moving the fix from #6 into
\Drupal\content_translation\ContentTranslationHandler::entityFormAlter()
.Connection with the related issue #2974560: Introduce a permission to check whether a user is able to access uid field.
Comment #9
BerdirOn the handler, we have things like \Drupal\content_translation\ContentTranslationHandler::hasAuthor() and and hasPublishedStatus() + hasCreated(). This hardcoded logic probably predates those generic checks and field definitions by a long time.
Maybe we can use those to dynamically define those fields only if necessary. We then likely also need to update the submit logic to not call setAuthor() and so on if we don't have the field exposed. Not quite sure how that even works right now to be honest. I can imagine the value is actually replaced anyway.
Comment #10
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedI am uploading a patch that implements the idea from #9 - conditionally displaying
content_translation_status
,content_translation_uid
andcontent_translation_created
fields depending whether an entity type has those fields defined.Edit: Sorry for no interdiff patch. It is based on a new idea, so not sure how relevant it would be.
Comment #12
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedQuite some changes in this patch. Hopefully, tests are passing.
Comments:
Not sure about this part...
This look like a leftover that could be removed.
I'm not sure whether we need to display content translation metadata fields if native metadata are available but hidden in the form display configuration... So something like:
!$this->hasAuthor() || !$form_display->getComponent('uid')
or not. That would allow translators to fill the metadata if native metadata is hidden. On the other hand, a site-builder would not be able to hide those fields through UI if they want?This aims to dynamically support all the content entities where
\Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase
or deprecated\Drupal\content_translation\Tests\ContentTranslationUITestBase
are used. However, it has a dirty special case forcreated
field.By dynamically showing the content translation metadata fields depending on the native metadata fields this becomes obsolete.
This seems to be a requirement for
\Drupal\Tests\content_translation\Functional\ContentTestTranslationUITest
.I'm wondering why do we need to do this per entity type. In
Drupal\content_translation\ContentTranslationHandler::entityFormEntityBuild()
, if there is no content translation metadata field value set, we could possibly get those values from the entity itself and theDrupal\entity_test\EntityTestTranslationHandler::entityFormEntityBuild()
method would not be needed.E.g:
Comment #14
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedTest fix workaround...
Comment #15
BerdirLooks quite nice to me, lets get some feedback from @plach about the direction before we continue with it.
This is actually a temporary state:
#2834546: UI for publishing/unpublishing block_content blocks
We should at least add a todo or even consider to postpone..
why can we only remove the name but not the status logic?
you're actually calling $this->container here anyway, is that just to avoid repeated calls? IMHO not worth it for a test helper.
you can also use isset($this->fieldStorageDefinitions), array_key_exists() is only necessary when the value of the array key could be NULL
I think this is a rather strange pattern, I know some don't agree but IMHO it is fine to just use \Drupal:: in test code, then you don't need to implement that setUp() method multiple times.
those additions are necessary because we test that they are shown/not shown in the generic test?
Comment #17
borisson_Setting back to needs work to resolve the issues raised in #16, we should also try to point this issue at @plach for that review.
Comment #18
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedReroll of #14 - manually fixed conflicts on:
core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
core/modules/content_translation/src/Tests/ContentTranslationUITestBase.php
Since these moved to using
getAccountName()
Triggering test bot by setting to needs review, but this still needs work (see #17).
Comment #19
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedHelps if i attach the patch...
Comment #21
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedOops!
Comment #22
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedI'm new to the patch, but in the hope of pushing this forward here is a bit of work on it:
Re #15:
1. I've added a @TODO for now, hopefully the other issue lands earlier than this.
2. I think we can remove this indeed. Done.
3.
Not entirely sure what you mean, left as is.
Done.
4. I have no opinion one way or the other, so left it as is.
5. That would be my guess, left it as is.
Comment #25
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedSeems like we do need to use
array_key_exists()
Comment #27
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedComment #28
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedRerolled, manually fixed conflicts on :
Comment #30
BerdirFormatting for @todo is not correct, I'd put it below the explanation, lowercase and then the second line needs to be indented by two spaces.
Also, the issue seems to be wrong, might be my fault, that's the issue for taxonomy status, there should be a separate one for block_content.
this should get the same @todo so we don't forget to remove it.
what I mean is that we should drop $this->fieldStorageDefinitions, just get them directly in the trait, also use \Drupal::service() there.
format_date() is deprecated, that seems to be the reason for all the test fails.
Comment #31
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedThanks for the review @Berdir!
#30.1 Great catch on the wrong issue, fixed that and the formatting. Linking now to #2834546: UI for publishing/unpublishing block_content blocks
#30.2 Added.
#30.3 Got it, done.
#30.4 Fixed.
Comment #32
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedForgot to remove the setUp from
\Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase
, sorry test bot...Comment #35
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedRe #15.2 - On #12.2 its mentioned that the title could be a leftover that could be removed. However if we remove the line for the status, seems like the status isn't saved.
NodeTranslationHandler::entityFormEntityBuild()
has the same logic so I believe we need that in place, so re-adding it here.Comment #36
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedComment #39
BerdirVarious improvements:
* terms need the same hack now as block_content, this is pretty sad, will talk to @amateescu about this as well if we can provide a more generic solution for this. Maybe check the form display configuration of the field definition?
* Improved the generic test logic to handle widget form elements like status[value] and uid[0][target_id]
* Improved entityFormEntityBuild() to only set the value if the form element is accessible, that works also for the block_content and term cases.
* With that fix, we actually can remove the overrides in node and comment, because the parent doesn't try to override the values anymore.
Comment #40
amateescu CreditAttribution: amateescu commentedDiscussed a bit with @Berdir and my opinion is that CT should alter the form display for publishable entity types and expose their status field rather than doing it with form alters :)
Comment #41
bklineComment #42
bklineComment #44
BerdirRerolled. term status is now exposed, so that's one less to worry about.
Comment #45
BerdirAnother reroll.
Comment #46
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation for Pfizer, Inc. commentedUpdated the patch since #2899923: UI for publishing/unpublishing taxonomy terms got in
Comment #47
BerdirReroll for 9.0,x, only change is the removed old base test class.
Comment #48
xjmThis would be a minor-only change. Since 8.9.x and 9.0.x are now in beta, I'm moving this to 9.1.x. Thanks!
Comment #49
AnybodyWhao, thank you all very much, this solved a heavy bug for us after #2899923: UI for publishing/unpublishing taxonomy terms which made it impossible to unpublish commerce product variation translations through the UI! While the core status checkbox could be unchecked in the translation, the content_translation checkbox was disabled="disabled" and could not be changed. That lead to overridden value for the status checkbox. So the status could not be changed to disabled anymore.
In #2899923#76 I posted a screenshot of a further case, where the published status is also affected by this and can not be changed due to the bug:
Top checkbox is disabled, can not be changed but overrides the checkbox below.
We're using #46 in 8.8.6 in production on a large site since some days and I can finally confirm it works very well and without any problems. Thank you so much.
So RTBC+1 for #46 on 8.x. Would be very helpful to also fix this in 8.9.x as follow-up fix for #2899923. I don't see this as a new feature, but much more as an important bugfix for a broken UI as described above.
Comment #50
AnybodyHi @Berdir & @xjm, is this ready for RTBC? And do we have a chance to backport this as written in #49 to also fix 8.x installations where this bug is also still unfixed?
Comment #51
hchonovIt is tagged as "Needs issue summary update". I would go through the patch after the IS is updated to reflect the taken decisions.
Comment #53
BerdirReroll.
Comment #55
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedUpdated deprecation notices.
Comment #57
BerdirThanks for the updates. The changes to ContentTranslationWorkflowsTest that are failing are pretty new, so that makes sense. Another (test) entity type with "inconsistent" field definitions (a status field without form display configuration) though, that is a bit trickier, Will get back to that in a follow-up comment.
Comment #58
BerdirSo, this patch does have basically two effects:
a) Prevents duplicate author/created/status fields from showing up if already exposed as widgets in the given entity form. Some entity types like node and comment have custom handlers in place to hide those fields, but most entity types don't, even in core. For example taxonomy terms and media. So this causes a change for those entity types but I think that might be acceptable in a minor release. The duplicate fields are very confusing and cause bugs, like overwriting the actual field widgets.
b) The logic for showing/hiding those extra fields automatically is however tied to just whether the field exists or not and not if it's visible in the form. For entity types that have for example a status field but don't show it in the UI (like block_content and test entities in core), that results then in neither the regular status field nor the content translation status field being exposed. To keep the current behavior in e.g. block_content, that results in having to override it to show those fields anyway and some entity types need form display configuration for our translation tests to work.
Like this:
Question is: How much change is allowed and how strict do we need to be with BC with these changes? Form structures are not included in our BC promise, but what about form structures by a default implementation of an entity handler?
Options:
1) This is fine, we're OK with the change and move forward. Hopefully block_content will eventually expose the status field and we can remove these overrides again.
2) We check not whether an entity type has a field but also if it is enabled in the current form display. I don't like this, seems very unpredictable. Maybe you don't need the node author/created field on a node type, hide it and then instead one pops up from content_translation and only on translations? Yep, weird.
3) We make the new behavior strictly opt-in, with a new base class maybe or a entity type definition flag. You need to explicitly set that in D9 and in D10 it becomes the default and the old class is removed (or the new opt-in flag removed). That would mean no unexpected changes happen to your entity type, but a lot of contrib/custom entity types would then also not benefit from these imho rather important UX fixes unless they explicitly change something in their code. Not in D9 anyway. And they would only get deprecation messages if they have explicit content_translation test coverage. If they would, they'd have already customized this.
Thoughts?
Comment #60
BerdirAnother reroll due to test conflicts.
Comment #61
BerdirAnother one.
Comment #62
BerdirAnother reroll, this time conflicted on PHP 8.1 related changes in EntityTestMulRevPub.php.
Comment #65
AnybodyThanks @Berdir! Just wanted to inform that we're using the patch(es) successfully since #46. So far RTBC +1.
Sadly I'm not experienced enough in this topic to decide on #58, Who could?
Comment #67
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #68
Berdirgit apply -3 still appllied fine.
Comment #69
smustgrave CreditAttribution: smustgrave at Mobomo commentedFor the issue summary update.
Haven't done a review yet.
Comment #71
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedI updated the summary
Comment #72
mathilde_dumond CreditAttribution: mathilde_dumond at MD Systems GmbH commentedsmall fix in the summary about the blocks published state
Comment #73
smustgrave CreditAttribution: smustgrave at Mobomo commentedConfirmed the issue on a standard install
Adding a 2nd language for the Image media bundle
Applied patch #68 and am no longer seeing the duplicates
Comment #74
BerdirThanks, really hoping this will finally land :)
As mentioned before and also in the issue summary. this part is a bit weird and an edge case between a change and a bugfix.
This is keeping the current status, which is arguably strange as the default translation has no status, but the translations then do.
We could also say it's a bugfix, there shouldn't be a translation status, but people might have unpublished translations and then they couldn't publish them anymore.
I think this is very unlikely to happen to any other contrib/custom entity type, either they have a status, and then also a UI or not.
Comment #75
quietone CreditAttribution: quietone at PreviousNext commentedI'm triaging RTBC issues.
I read the IS and comments. I did not find unanswered questions. Both #15 and #22.1 question whether this should be postponed on #2834546: UI for publishing/unpublishing block_content blocks. There wasn't any discussion about that. Should this be postponed? I've added this question to the remaining tasks.
I read the comments in the patch and had the following thoughts. Since this is testing against 10.1 instead of 11.x I will make a new patch for item 2 below.
It would be more helpful in the @todo gave a hint at what to do here. It is to remove that next line? But then what is the purpose of the form alter? And I guess this is not needed if the other issue is completed first, which goes back to the postponing question.
This applies to the other instances of the @todo as well.
A bit of incorrect grammar here I think. How about "Provides methods to assert ..."
Comment #76
quietone CreditAttribution: quietone at PreviousNext commentedI don't think the question about postponing and #75.1 block this from RTBC. But I really shouldn't restore RTBC because of the edit I made to a comment.
Comment #77
Berdir> Both #15 and #22.1 question whether this should be postponed on #2834546: UI for publishing/unpublishing block_content blocks. Should this be postponed? I've added this question to the remaining tasks.
:shrug:
It would simplify the patch, but we've been soft-blocked by that issue for 5 years now. It's classified as a feature, this is a bug that fixes some pretty annoying issues for multilingual sites.
Nothing changes if we get this in compared to HEAD for blocks, we just need a bit of a workaround for it, which the other issue can easily remove again. The change that happens is technically also correct, if the module for some reason doesn't want to have a status visible, why should translations? We're just doing this for BC. Thinking this through, this whole concept maybe shouldn't exist at all, it's a leftover of Drupal 7 really where modules didn't have the ability to have translatable base fields/properties. Of course, no idea how to remove it now in a way that is backwards compatible.
IMHO the hidden concern is the last paragraph of #74, whether or not there are any custom or contrib entity types with a similar case, we would have never thought of that without the current state of block_content. IMHO it's fairly unlikely. I did just create a change record to notify about the UI changes and impacts on entity types: https://www.drupal.org/node/3383265.
The comment change in #75 is fine, the interdiff seems a bit confused about some line changes, but I think nothing changed there.
Comment #78
smustgrave CreditAttribution: smustgrave at Mobomo commentedFor what it's worth I am trying to get #2834546: UI for publishing/unpublishing block_content blocks into 10.2 or 10.3. But since there could be some back n forth on that one agree with @Berdir about moving this forward.
Comment #79
quietone CreditAttribution: quietone at PreviousNext commented@Berdir, thanks for the explanation.
Comment #80
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #81
kostyashupenkoRerolled
Comment #82
smustgrave CreditAttribution: smustgrave at Mobomo commentedAll green from reroll. Restoring status
Comment #84
andypostComment #86
smustgrave CreditAttribution: smustgrave at Mobomo commentedSeems unrelated
Comment #87
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #88
smustgrave CreditAttribution: smustgrave at Mobomo commentedRerunning tests but patch still applies cleanly.
Comment #89
smustgrave CreditAttribution: smustgrave at Mobomo commentedFound out why there's no MR
Comment #90
Anybody@smustgrave what does #89 mean? Or should it mean "Find" (active)
Comment #92
BerdirCreated MR and rerolled.
Comment #93
smustgrave CreditAttribution: smustgrave at Mobomo commentedLeft some comments that I should of noticed before but appears to have phpcs errors also.
Thanks for picking this one back up.