Problem/Motivation

This is a file-for-the-future issue for when #2946333: Allow synced Layout override Translations: translating labels and inline blocks is committed. It might not even be an issue with this module, but rather with the approach in that core issue.

When a block is translated, say to Spanish, the original (say in English) layout retains the unstranslated revision ID for that inline block. When the english version is cloned, the translated blocks don't come over because the cloning loads the exact revision ID (which again, is probably correct), but that revision has no translations.

This hack resolves the issue such that translated blocks come over:

  protected function cloneBlockContent($revision) {
    $block = $this->entityTypeManager->getStorage('block_content')->loadRevision($revision);
    // We load the latest here to ensure that all available languages are
    // copied over.
    // @todo Figure out a better way, or push this upstream.
    $latest = $this->entityTypeManager->getStorage('block_content')->load($block->id());
    $cloned_block = $latest->createDuplicate();
    return $cloned_block;
  }

Comments

jhedstrom created an issue.

jhedstrom’s picture

After digging into the core patch a bit, I think the thing to do here if/when that's committed is something like this:

        $entity = $this->entityTypeManager->getStorage('block_content')->loadRevision($translated_configuration['block_revision_id']);
        $entity = $this->entityRepository->getActive('block_content', $entity->id());

The getActive method appears to be for exactly this sort of issue.