Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When creating a content type, the checkbox "Enable Translation" is set by default. However this state is not saved.
Steps to reproduce:
- Install drupal, minimum profile
- Enable Content Translation and Language modules.
- Add a language
- Create a content type 'foo' do not set "Enable Translation"
- Create a node of type 'foo' (not sure if this step is needed)
- Edit the content type 'foo' and set "Enable Translation"
- Create a content type 'bar'.
- Observe the state of the "Enable Translation" checkbox. (= ON)
- Save and re-edit the content type 'bar'.
- Observe the state of the "Enable Translation" checkbox. (= OFF)
Proposed resolution
Remaining tasks
* Determine if "Enable Translation" should be set by default or not.
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#14 | 2328161-diff-11-14.txt | 1.5 KB | vijaycs85 |
#14 | 2328161-content-translation-enabled-14.patch | 2.7 KB | vijaycs85 |
Comments
Comment #1
Sutharsan CreditAttribution: Sutharsan commentedComment #2
vijaycs85I don't remember the issue number on top of my head, but we discussed it. Basically we have 2 places to enable content translation. 1) in content type 2) content translation admin page. Each has different validation rules ( say admin page doesn't allow to enable translation for a content type if there is no translatable field, where as content type does). One of @gaber suggestion was to remove this option in content type edit and provide link to admin page.
EDIT: this is the issue I was talking about: #2306087: Entity configuration form allows to enable translation without any translatable field
Comment #3
vijaycs85Comment #4
vijaycs85Initial patch...
Comment #5
vijaycs85Comment #6
Gábor HojtsyIMHo it should not be enabled by default. Not clear from the issue summary is if this happens with new content types? The bundle is not known at the time, so you should theoretically get FALSE. Theoretically. However looks like https://api.drupal.org/api/drupal/core%21modules%21content_translation%2... defaults to the first defined bundle for the entity type is none was provided, so the default state of the checkbox for new content types will be "random" depending on whether the first bundle returned was or was not configured multilingual.
The patch makes sense. I'd add a comment above, something like "For new content types, we don't know the bundle name yet, default to no translatability". Also needs tests.
Also the same problem probably happens with new vocabularies, new custom block types, etc.
Comment #7
vijaycs85Was wondering, if it is OK to do something like this:
but it might be API change, so going to update other places as per #4 and testcase.
Comment #8
vijaycs85Here is the updated patch with test for content type page. Manually tested other bundle pages(comment, custom block type, shortcut set, taxonomy) and the fix in #4 fixed all bundles as the fix is in language element.
Not sure, if we need to add test cases for other pages as the fix in central. If it is necessary, feel free to add test. otherwise, I will check later this week.
Comment #10
Gábor HojtsyThe code and test looks great. Only cosmetic stuff to clean things up for commit :)
I'd still add a one line comment as explained above in my previous comments.
Contains \Drupal...
More specific comment would be great. Eg. "Tests bundle translatability defaults on content types".
setUp is not required to have an inheritdoc I believe, also should have space after the modules property
Comment #11
vijaycs85Thanks @Gábor Hojtsy. fixed all in #10.
Comment #12
vijaycs85Comment #13
Gábor Hojtsy"For adding a new bundle, we don't ..." instead of content type. This applies to all entity bundles.
Also you could have used more space on the line, "default" could have fit on the first line AFAIS.
\Drupal
Comment #14
vijaycs85updated...
Comment #15
Gábor HojtsyLooks good to me :)
Comment #16
alexpottLooking at
content_translation_enabled()
I think we can make the code a bit less brittle by not usingempty
- see attached patch.Comment #17
vijaycs85Doesn't work for the 9 calls which assumes that no arg2 will check all bundles. and it is an API change. I was trying to do like
function content_translation_enabled($entity_type, $bundle = NULL, $check_all_bundle = TRUE) {
orfunction content_translation_enabled($entity_type, $bundle = 'all') {
but again, it is a change that we need to make all places where we have this call.
Comment #18
Gábor HojtsyYeah this first bundle picking was designed for no-bundle AKA single bundle entity types like user to make it easy to get their translation setting. A possibility is to make it intelligent using the entity type manager and figure out from there if the entity can have bundles and if no bundle was provided, always return FALSE from this function. If we really want to make it more intelligent. Not sure the magic factor is worth it though?
Comment #20
Gábor Hojtsy@alexpott: seems like fails in ContentTranslationSettingsTest where the article content type is saved and then made translatable is failing. Not sure what exactly are you doing here, is an empty string passed on here? How does this fix it?
Comment #21
Gábor HojtsyWhile I suggested in #2 to remove this element from the content type and instead only have 1 place, the content language settings page also uses this element, so it would not help in not needing to fix this bug.
Comment #22
k4v CreditAttribution: k4v commentedComment #23
k4v CreditAttribution: k4v commentedComment #24
k4v CreditAttribution: k4v commentedWe (schrammos and k4v) reviewed the two patches. We think #14 is fine, it fixes the issue and does not change the api.
Reworking content_translation_enabled() could be an new issue, we should check the semantics are right here.
The current documentation of content_translation_enabled() is not clear ("Determines whether the given entity type is translatable"). It should be something like "Determines if a specific bundle is translatable. If no bundle is given the function returns if at least one of the entity types bundles is translatable." But we are not sure if this is what the author intended.
Comment #25
k4v CreditAttribution: k4v commentedComment #27
Gábor HojtsyIf you want #14 to be the "latest patch", needs to hide the diversion...
Comment #28
webchickCommitted and pushed to 8.x. Thanks!
Comment #31
Gábor HojtsyYay, superb.