When cloning the blocks it does not assign the correct language to the block.

Created on 11 August 2022, over 2 years ago
Updated 18 September 2024, 2 months ago

Problem/Motivation

The cloned blocks from a library section aren't in the correct language. They are in the language that you created the library section item in.

This can cause all sorts of issues down the line with access checks on language. (as we have for a certain project)

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium nielsaers

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Merge request !14Update src/DeepCloningTrait.php β†’ (Open) created by nielsaers
  • πŸ‡§πŸ‡ͺBelgium weseze

    2 remarks on this approach:

    Templates that are stored in the library should have the language from the host entity from which they were cloned.
    With the changes you are proposing this could differ. Assume you are editing a page in a certain language (Chinese), while keeping the admin interface in another language (English). The current language would be English, but the template you are storing in the library should remain in the Chinese language, because it was cloned from a Chinese language page.

    Templates cloned into a page from the library should take on the language of the entity on which they are cloned.
    This is basically the same as the above, but in reverse.
    It also applies when you are simply translating your website and using templates created in another language.

    I suggest passing the host entity to the clone functions and getting the language from there.
    But I don't see anyway of doing that with the current code as it does not contain the host entity anywhere...

  • πŸ‡§πŸ‡ͺBelgium Thomas Cys

    Thomas Cys β†’ made their first commit to this issue’s fork.

  • Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    Waiting for branch to pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update 12 months ago
    2 fail
  • πŸ‡§πŸ‡ͺBelgium kriboogh

    "But I don't see anyway of doing that with the current code as it does not contain the host entity anywhere..."

    I was looking at the code for this a bit. From the submitForm methods you could pass the section_storage context 'entity' which is assigned to $layout_entity (this is the node being edited) and pass that to the deepClone methods. There you can then use the $layout_entity->getLanguage()->getId() to set the langcode.

    Also then set the langcode on the section being create or updated before the $section->save in the submitForm code after the cloning has been done.
    $section->set('langcode', $layout_entity->language()->getId());

    I will try to cook up some patch.

Production build 0.71.5 2024