Problem/Motivation
See #2946333-42: Allow synced Layout override Translations: translating labels and inline blocks
If you delete a translation with inline blocks, the blocks will not be deleted until the whole entity is deleted.
Proposed resolution
- Add a langcode column to the table
- Make sure langcode is correctly set when adding a new usage
Remaining tasks
- Validate approach.
- Fix @todos in current patch.
- Upgrade test
User interface changes
N/A
API changes
N/A
Data model changes
- A new column on the inline_block_usage database table
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3013340-17.patch | 153.02 KB | tedbow |
| #17 | 3013340-17-no-fixture-do-not-test.patch | 13.73 KB | tedbow |
| #17 | interdiff-15-17-no-fixture.txt | 2.5 KB | tedbow |
| #15 | 3013340-15.patch | 11.23 KB | tedbow |
| #15 | interdiff-13-15.txt | 5.18 KB | tedbow |
Comments
Comment #2
johnwebdev commentedComment #3
johnwebdev commented... working on this!
Comment #4
johnwebdev commented... And here is a patch that makes #2946333-42: Allow synced Layout override Translations: translating labels and inline blocks green (locally).
Comment #5
johnwebdev commentedstill working on this
Comment #6
johnwebdev commentedComment #7
johnwebdev commentedForgot to change the @group on the test back. :P
Comment #8
johnwebdev commentedComment #9
tedbowLooking good. Thanks for breaking this out.
Need a description here. Also probably default looking at other langcode fields.
Description and default
Need to fully namespace @param
Is this @todo done?
We should probably confirm the correct block_content_id is returned.
We could also test
and both calls to
before the translation is removed.
Needs a description
removeByLayoutEntity(). it wasn't changed here but it will be removing more rows now.Comment #10
tedbowComment #11
johnwebdev commented#9
1. Added description.
2. Fixed.
3. Fixed.
4. Properly passed the language manager with dependency injection and removed @todo.
5. Fixed... however :(
$this->assertSame(['2'], $this->inlineBlockUsage->getUnused());It looks like
::getUnused()returns an array of IDs as strings, and not integers.6. To assert the values are not NULL? I could do that, but we could rather expand test coverage on those methods instead.
7. Fixed.
6-8: We have #2992844: Add test coverage for InlineBlockUsage class Not entirely sure what you mean with
removeByLayoutEntity()removing more rows though.Comment #13
tedbowI realize now that we can't just set the initial value to the site default language.
Even though the layouts could not be translated before this patch you could still have entities that where the default language was not the sites default language. So inline blocks used in those entities should have the langcode of the entities.
But as it is now we have to have an initial value here because langcode column can't be null.
Maybe langcode should be allowed to be null.
If the entity isn't transable we assign the site's default language here. But maybe we shouldn't.
The entity is not translatable maybe should have null for langcode.
Comment #14
johnwebdev commented#13.3 I'd prefer not using NULL to stay consistent, with that being said the current approach for the update is wrong either way so setting this back to NW.
Currently not working on this.
Comment #15
tedbowThis patch sets the initial value to
LanguageInterface::LANGCODE_NOT_SPECIFIEDAnd then attempts to update all the records
Since there could be thousands of records I didn't want to have to load all the entities.
Also would loading the entities even work because it would give us the latest revision and this might not be the revision that where the inline block was used which could have a different language value(I think).
This also has to consider config entities like entity view displays which do have a language returned.
I think regardless of whether entity is translatable or not
$data['langcode'] = $entity->language()->getId();will give use the correct value since
language()is onEntityInterfaceand it should always return a language object.Comment #16
johnwebdev commented#15.1
I decided to try it out:
With that being said, I'm not entirely sure what the expected behaviour of Drupal is when doing the steps above. Is this a bug?
2 Yep. Good change.
Comment #17
tedbow\Drupal\Core\Entity\ContentEntityBase::onChange()I could find an existing issue. It seems like bug just because of the fatal error but it is always a pretty edge case series of steps. But not related layout builder but maybe tells as far as what might not be possible.
I think the problem would be
layout_builder_update_8701runsThis series of step leaves an orphaned non-reusable block_content entity that isn't referenced anywhere which is suppose to happen
it is not horrible because:
I am trying to think of situation where you could delete a translation and the inline block is deleted when is shouldn't be(as opposed to not deleted when it should be) but I can't think of one.
I made a patch without the fixture for review
Comment #18
tim.plunkettNW for more tests
Comment #20
tim.plunkettIf this issue is still needed, I think it's postponed on #2946333: Allow synced Layout override Translations: translating labels and inline blocks